Fix 404 on Markdown pages when a theme is forced (#4685)

This commit is contained in:
Peter White
2026-10-14 11:46:58 +02:00
committed by GitHub
parent 65acba0b61
commit 0b515b0970
3 changed files with 32 additions and 1 deletions
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Fix 404 on Markdown pages (View as Markdown) in site previews and when a theme is forced with `?theme=`.
+24
View File
@@ -1125,6 +1125,30 @@ const testCases: TestsCase[] = [
).toBeVisible();
},
},
{
name: 'Markdown page with theme cookie',
url: async () => {
const data = await getSiteAPIToken(
'https://gitbook.gitbook.io/test-gitbook-open/'
);
const searchParams = new URLSearchParams();
searchParams.set('token', data.apiToken);
searchParams.set('theme', 'dark');
return `url/${getGitBookPreviewURL(`${data.site}/blocks?${searchParams.toString()}`)}`;
},
screenshot: false,
run: async (page) => {
// The app opens previews with `?theme=`, which the middleware persists in a cookie.
const markdownURL = new URL(page.url());
markdownURL.pathname = `${markdownURL.pathname.replace(/\/$/, '')}.md`;
markdownURL.search = '';
const response = await page.request.get(markdownURL.toString());
expect(response.status()).toBe(200);
expect(response.headers()['content-type']).toContain('text/markdown');
},
},
{
name: 'Redirect to app for authentication when missing token',
url: async () => {
+3 -1
View File
@@ -496,7 +496,9 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
themeMode === CustomizationThemeMode.Dark
? CustomizationDefaultThemeMode.Dark
: CustomizationDefaultThemeMode.Light;
} else {
} else if (routeTypeFromPathname !== 'static') {
// Markdown, llms.txt, RSS and sitemap routes only exist under `sites/static`, so
// forcing them dynamic 404s. They don't render a theme anyway. RND-12749.
routeType = 'dynamic';
requestHeaders.set(MiddlewareHeaders.Theme, themeMode);
}