Skip to content

Commit 58d7f3c

Browse files
conico974Nicolas Dorseuil
andauthored
Fix revision ID handling for computed content (#3386)
Co-authored-by: Nicolas Dorseuil <[email protected]>
1 parent 07eab98 commit 58d7f3c

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

.changeset/dry-pandas-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook-v2": patch
3+
---
4+
5+
Fix revision id for computed content

packages/gitbook-v2/src/lib/context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export type GitBookSpaceContext = GitBookBaseContext & {
8787
/** Revision of the space. */
8888
revision: Revision;
8989

90+
/** Identifier of the revision. Could be different than `revision.id` when using computed. */
91+
revisionId: string;
92+
9093
/** Share key of the space. */
9194
shareKey: string | undefined;
9295
};
@@ -367,6 +370,7 @@ export async function fetchSpaceContextByIds(
367370
organizationId: space.organization,
368371
space,
369372
revision,
373+
revisionId,
370374
changeRequest,
371375
shareKey: ids.shareKey,
372376
};

packages/gitbook/e2e/internal.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ const testCases: TestsCase[] = [
910910
).toBeVisible();
911911
const url = page.url();
912912
expect(url.includes('shared-space-uno')).toBeTruthy(); // same uno site
913-
expect(url.endsWith('/shared')).toBeTruthy(); // correct page
913+
expect(url.endsWith('/shared/')).toBeTruthy(); // correct page
914914
},
915915
screenshot: false,
916916
},
@@ -930,7 +930,7 @@ const testCases: TestsCase[] = [
930930
).toBeVisible();
931931
const url = page.url();
932932
expect(url.includes('shared-space-dos')).toBeTruthy(); // same dos site
933-
expect(url.endsWith('/shared')).toBeTruthy(); // correct page
933+
expect(url.endsWith('/shared/')).toBeTruthy(); // correct page
934934
},
935935
screenshot: false,
936936
},

packages/gitbook/src/components/AdminToolbar/AdminToolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function AdminToolbar(props: AdminToolbarProps) {
5858
return <ChangeRequestToolbar context={context} />;
5959
}
6060

61-
if (context.revision.id !== context.space.revision) {
61+
if (context.revisionId !== context.space.revision) {
6262
return <RevisionToolbar context={context} />;
6363
}
6464

packages/gitbook/src/components/SitePage/fetch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function fetchPageData(context: GitBookSiteContext, params: PagePar
3636
* If the path can't be found, we try to resolve it from the API to handle redirects.
3737
*/
3838
async function resolvePage(context: GitBookSiteContext, params: PagePathParams | PageIdParams) {
39-
const { organizationId, site, space, revision, shareKey, linker } = context;
39+
const { organizationId, site, space, revision, shareKey, linker, revisionId } = context;
4040

4141
if ('pageId' in params) {
4242
return resolvePageId(revision.pages, params.pageId);
@@ -59,7 +59,7 @@ async function resolvePage(context: GitBookSiteContext, params: PagePathParams |
5959
const resolved = await getDataOrNull(
6060
context.dataFetcher.getRevisionPageByPath({
6161
spaceId: space.id,
62-
revisionId: revision.id,
62+
revisionId: revisionId,
6363
path: rawPathname,
6464
})
6565
);

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function SpaceLayout(props: {
5959
siteSectionId={context.sections?.current?.id ?? null}
6060
siteSpaceId={context.siteSpace.id}
6161
siteShareKey={context.shareKey ?? null}
62-
revisionId={context.revision.id}
62+
revisionId={context.revisionId}
6363
spaceId={context.space.id}
6464
visitorAuthClaims={visitorAuthClaims}
6565
visitorCookieTrackingEnabled={context.customization.insights?.trackingCookie}

packages/gitbook/src/lib/seo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function isSiteIndexable(context: GitBookSiteContext) {
3535
}
3636

3737
// Prevent indexation of preview of revisions / change-requests
38-
if (context.changeRequest || context.revision.id !== context.space.revision) {
38+
if (context.changeRequest || context.revisionId !== context.space.revision) {
3939
return false;
4040
}
4141

0 commit comments

Comments
 (0)