mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 11:03:39 +00:00
Use stable site URL data for route rewrite in the middleware (#3053)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Use stable site URL data for route rewrite in the middleware
|
||||||
@@ -194,18 +194,38 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
|
|||||||
);
|
);
|
||||||
routeType = routeTypeFromPathname ?? routeType;
|
routeType = routeTypeFromPathname ?? routeType;
|
||||||
|
|
||||||
|
// We pick only stable data from the siteURL data to prevent re-rendering of
|
||||||
|
// the root layout when changing pages..
|
||||||
|
const stableSiteURLData: Omit<typeof siteURLData, 'pathname'> = {
|
||||||
|
site: siteURLData.site,
|
||||||
|
siteSection: siteURLData.siteSection,
|
||||||
|
siteSpace: siteURLData.siteSpace,
|
||||||
|
siteBasePath: siteURLData.siteBasePath,
|
||||||
|
basePath: siteURLData.basePath,
|
||||||
|
space: siteURLData.space,
|
||||||
|
organization: siteURLData.organization,
|
||||||
|
changeRequest: siteURLData.changeRequest,
|
||||||
|
revision: siteURLData.revision,
|
||||||
|
shareKey: siteURLData.shareKey,
|
||||||
|
apiToken: siteURLData.apiToken,
|
||||||
|
complete: siteURLData.complete,
|
||||||
|
contextId: siteURLData.contextId,
|
||||||
|
};
|
||||||
|
|
||||||
const route = [
|
const route = [
|
||||||
'sites',
|
'sites',
|
||||||
routeType,
|
routeType,
|
||||||
mode,
|
mode,
|
||||||
encodeURIComponent(siteURLWithoutProtocol),
|
encodeURIComponent(siteURLWithoutProtocol),
|
||||||
encodeURIComponent(
|
encodeURIComponent(
|
||||||
rison.encode({
|
rison.encode(
|
||||||
...siteURLData,
|
// rison can't encode undefined values
|
||||||
// The pathname is passed as the next segment of the route and should not cause this segment to change
|
Object.fromEntries(
|
||||||
// based on the page being visited
|
Object.entries(stableSiteURLData).filter(
|
||||||
pathname: '<DO_NOT_USE>',
|
([_, v]) => typeof v !== 'undefined'
|
||||||
})
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
pathname,
|
pathname,
|
||||||
].join('/');
|
].join('/');
|
||||||
|
|||||||
Reference in New Issue
Block a user