Skip to content

Commit baf378d

Browse files
committed
Don't show the preview toolbar when rendering within GitBook app preview env
1 parent 177afa5 commit baf378d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { GitBookSiteContext } from '@/lib/context';
22
import { Icon } from '@gitbook/icons';
3-
import { headers } from 'next/headers';
43
import React from 'react';
54

5+
import { isPreviewRequest } from '@/lib/preview';
66
import { tcls } from '@/lib/tailwind';
7-
87
import { DateRelative } from '../primitives';
98
import { RefreshChangeRequestButton } from './RefreshChangeRequestButton';
109
import { Toolbar, ToolbarBody, ToolbarButton, ToolbarButtonGroups } from './Toolbar';
@@ -47,10 +46,15 @@ function ToolbarLayout(props: { children: React.ReactNode }) {
4746
*/
4847
export async function AdminToolbar(props: AdminToolbarProps) {
4948
const { context } = props;
50-
const mode = (await headers()).get('x-gitbook-mode');
5149

52-
if (mode === 'multi-id') {
53-
// We don't show the admin toolbar in multi-id mode, as it's used for previewing in the dashboard.
50+
// Get the current URL from the linker (which accounts for both static and dynamic routes)
51+
const currentURL = new URL(context.linker.toAbsoluteURL('/'));
52+
53+
// Check if this url is opened within the GitBook app's in-editor preview tab.
54+
const isInAppPreview = isPreviewRequest(currentURL);
55+
56+
// Don't show admin toolbar for preview requests
57+
if (isInAppPreview) {
5458
return null;
5559
}
5660

0 commit comments

Comments
 (0)