Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 129 additions & 39 deletions bun.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"bidc": "^0.0.2",
"bun-types": "^1.1.20",
"classnames": "^2.5.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react": "^19.0.1",
"react-dom": "^19.0.1",
"tsdown": "^0.15.6",
"typescript": "^5.5.3",
"usehooks-ts": "^3.1.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/gitbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@gitbook/react-openapi": "workspace:*",
"@modelcontextprotocol/sdk": "1.17.5",
"@opennextjs/aws": "^3.8.5",
"@opennextjs/cloudflare": "^1.11.0",
"@opennextjs/cloudflare": "^1.14.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.1.12",
"@radix-ui/react-hover-card": "^1.1.15",
Expand Down Expand Up @@ -50,7 +50,7 @@
"micromark-extension-frontmatter": "^2.0.0",
"micromark-extension-gfm": "^3.0.0",
"motion": "^12.23.24",
"next": "15.4.0",
"next": "15.4.8",
"next-themes": "^0.4.6",
"nuqs": "^2.2.3",
"object-hash": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function Page(props: PageProps) {
const { context } = await getDynamicSiteContext(params);
const pathname = getPagePathFromParams(params);

return <SitePage context={context} pageParams={{ pathname }} />;
return <SitePage context={context} pageParams={{ pathname }} staticRoute={false} />;
}

export async function generateViewport(props: PageProps): Promise<Viewport> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function Page(props: PageProps) {
const { context } = await getEmbeddableDynamicContext(params);
const pathname = getPagePathFromParams(params);

return <EmbeddableDocsPage context={context} pageParams={{ pathname }} />;
return <EmbeddableDocsPage context={context} pageParams={{ pathname }} staticRoute={false} />;
}

export async function generateMetadata(props: PageProps): Promise<Metadata> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function Page(props: PageProps) {
const { context } = await getStaticSiteContext(params);
const pathname = getPagePathFromParams(params);

return <SitePage context={context} pageParams={{ pathname }} />;
return <SitePage context={context} pageParams={{ pathname }} staticRoute />;
}

export async function generateViewport(props: PageProps): Promise<Viewport> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function Page(props: PageProps) {
const { context } = await getEmbeddableStaticContext(params);
const pathname = getPagePathFromParams(params);

return <EmbeddableDocsPage context={context} pageParams={{ pathname }} />;
return <EmbeddableDocsPage context={context} pageParams={{ pathname }} staticRoute />;
}

export async function generateMetadata(props: PageProps): Promise<Metadata> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type EmbeddableDocsPageProps = {
/**
* Page component for the embed docs page.
*/
export async function EmbeddableDocsPage(props: EmbeddableDocsPageProps) {
export async function EmbeddableDocsPage(
props: EmbeddableDocsPageProps & { staticRoute: boolean }
) {
const { context, pageParams } = props;
const { page, document, ancestors, withPageFeedback } = await getSitePageData({
context,
Expand Down Expand Up @@ -87,6 +89,7 @@ export async function EmbeddableDocsPage(props: EmbeddableDocsPageProps) {
document={document}
withPageFeedback={withPageFeedback}
insightsDisplayContext={SiteInsightsDisplayContext.Embed}
staticRoute={props.staticRoute}
/>
</ScrollContainer>
</EmbeddableFrameBody>
Expand Down
20 changes: 20 additions & 0 deletions packages/gitbook/src/components/PageBody/OptionalSuspense.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

/**
* Conditionally wrap children in a Suspense component based on SSR status.
* We need to do that because otherwise ISR pages will trigger the suspense boundary on every request,
* causing flickering and bad UX.
*/
export default function OptionalSuspense(props: {
staticRoute: boolean;
fallback: React.ReactNode;
children: React.ReactNode;
}) {
const { staticRoute, fallback, children } = props;

if (staticRoute) {
return <>{children}</>;
}

return <React.Suspense fallback={fallback}>{children}</React.Suspense>;
}
18 changes: 14 additions & 4 deletions packages/gitbook/src/components/PageBody/PageBody.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { GitBookSiteContext } from '@/lib/context';
import type { JSONDocument, RevisionPageDocument, SiteInsightsDisplayContext } from '@gitbook/api';
import React from 'react';

import { getSpaceLanguage } from '@/intl/server';
import { t } from '@/intl/translate';
Expand All @@ -12,6 +11,7 @@ import { TrackPageViewEvent } from '../Insights';
import { PageFeedbackForm } from '../PageFeedback';
import { CurrentPageProvider } from '../hooks/useCurrentPage';
import { DateRelative, SuspenseLoadedHint } from '../primitives';
import OptionalSuspense from './OptionalSuspense';
import { PageBodyBlankslate } from './PageBodyBlankslate';
import { PageCover } from './PageCover';
import { PageFooterNavigation } from './PageFooterNavigation';
Expand All @@ -27,8 +27,17 @@ export function PageBody(props: {
document: JSONDocument | null;
withPageFeedback: boolean;
insightsDisplayContext: SiteInsightsDisplayContext;
staticRoute: boolean;
}) {
const { page, context, ancestors, document, withPageFeedback, insightsDisplayContext } = props;
const {
page,
context,
ancestors,
document,
withPageFeedback,
insightsDisplayContext,
staticRoute,
} = props;
const { customization } = context;

const contentFullWidth = document ? hasFullWidthBlock(document) : false;
Expand Down Expand Up @@ -84,7 +93,8 @@ export function PageBody(props: {
withRSSFeed={contentHasUpdates}
/>
{document && !isNodeEmpty(document) ? (
<React.Suspense
<OptionalSuspense
staticRoute={staticRoute}
fallback={
<DocumentViewSkeleton
document={document}
Expand All @@ -106,7 +116,7 @@ export function PageBody(props: {
withLinkPreviews,
}}
/>
</React.Suspense>
</OptionalSuspense>
) : (
<PageBodyBlankslate page={page} context={context} />
)}
Expand Down
3 changes: 2 additions & 1 deletion packages/gitbook/src/components/SitePage/SitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type PageMetaLinks = {
/**
* Fetch and render a page.
*/
export async function SitePage(props: SitePageProps) {
export async function SitePage(props: SitePageProps & { staticRoute: boolean }) {
const {
context,
page,
Expand Down Expand Up @@ -99,6 +99,7 @@ export async function SitePage(props: SitePageProps) {
document={document}
withPageFeedback={withPageFeedback}
insightsDisplayContext={SiteInsightsDisplayContext.Site}
staticRoute={props.staticRoute}
/>
</div>
<PageClientLayout pageMetaLinks={pageMetaLinks} />
Expand Down