From 321b06d873abd987441bb5d0b340da06207dde71 Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 7 Sep 2026 12:14:36 +0200 Subject: [PATCH] fix: keep permanent redirects temporary in site previews and for draft redirects --- packages/gitbook/src/components/SitePage/fetch.ts | 2 ++ packages/gitbook/src/lib/context.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/packages/gitbook/src/components/SitePage/fetch.ts b/packages/gitbook/src/components/SitePage/fetch.ts index 484b90b2f..498f2f99c 100644 --- a/packages/gitbook/src/components/SitePage/fetch.ts +++ b/packages/gitbook/src/components/SitePage/fetch.ts @@ -93,10 +93,12 @@ async function resolvePage(context: GitBookSiteContext, params: PagePathParams | const isPublicLiveContext = !shareKey && !context.changeRequest && + !context.preview && context.revisionId === context.space.revision && !context.isLoggedInVisitor; if ( resolvedSiteRedirect.redirect && + !resolvedSiteRedirect.redirect.draft && 'permanent' in resolvedSiteRedirect.redirect && resolvedSiteRedirect.redirect.permanent === true && isPublicLiveContext diff --git a/packages/gitbook/src/lib/context.ts b/packages/gitbook/src/lib/context.ts index 20a1917db..16dec245b 100644 --- a/packages/gitbook/src/lib/context.ts +++ b/packages/gitbook/src/lib/context.ts @@ -201,6 +201,9 @@ export type GitBookSiteContext = GitBookSpaceContext & { /** Whether the request included a visitor token. */ isLoggedInVisitor: boolean; + /** Whether the site is rendered from a preview URL. */ + preview: boolean; + /** Whether to display agent instructions in the markdown output. Defaults to true when undefined. */ displayAgentInstructions?: boolean; @@ -287,6 +290,7 @@ export async function fetchSiteContextByURLLookup( isFallback: data.isFallback ?? false, noIndexSearch: data.noIndexSearch ?? false, isLoggedInVisitor: data.isLoggedInVisitor ?? false, + preview: data.preview ?? false, displayAgentInstructions: data.displayAgentInstructions, isAiAgent: data.isAiAgent, }); @@ -310,6 +314,7 @@ export async function fetchSiteContextByIds( isFallback: boolean; noIndexSearch: boolean; isLoggedInVisitor: boolean; + preview: boolean; displayAgentInstructions?: boolean; isAiAgent?: boolean; } @@ -439,6 +444,7 @@ export async function fetchSiteContextByIds( isFallback: ids.isFallback, noIndexSearch: ids.noIndexSearch, isLoggedInVisitor: ids.isLoggedInVisitor, + preview: ids.preview, displayAgentInstructions: ids.displayAgentInstructions, isAiAgent: ids.isAiAgent, };