Skip to content

Commit 31bcd1a

Browse files
authored
Improve detection of code path not supported in v2, add visual tests (#2884)
1 parent 270e5ef commit 31bcd1a

File tree

17 files changed

+157
-111
lines changed

17 files changed

+157
-111
lines changed

.github/workflows/ci.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,31 @@ jobs:
255255
name: playwright-test-results
256256
path: packages/gitbook/test-results/
257257
retention-days: 3
258+
visual-testing-v2:
259+
runs-on: ubuntu-latest
260+
name: Visual Testing v2
261+
needs: deploy-v2-vercel
262+
steps:
263+
- name: Checkout
264+
uses: actions/checkout@v4
265+
- name: Setup Bun
266+
uses: ./.github/composite/setup-bun
267+
- name: Install dependencies
268+
run: bun install --frozen-lockfile
269+
- name: Setup Playwright
270+
uses: ./.github/actions/setup-playwright
271+
- name: Run Playwright tests
272+
run: bun e2e
273+
env:
274+
BASE_URL: ${{needs.deploy-v2-vercel.outputs.deployment-url }}/url/
275+
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
276+
ARGOS_BUILD_NAME: 'v2'
277+
- uses: actions/upload-artifact@v4
278+
if: ${{ !cancelled() }}
279+
with:
280+
name: playwright-test-results
281+
path: packages/gitbook/test-results/
282+
retention-days: 3
258283
visual-testing-customers:
259284
runs-on: ubuntu-latest
260285
name: Visual Testing Customers
@@ -280,6 +305,31 @@ jobs:
280305
name: playwright-test-results-customers
281306
path: packages/gitbook/test-results/
282307
retention-days: 3
308+
visual-testing-customers-v2:
309+
runs-on: ubuntu-latest
310+
name: Visual Testing Customers v2
311+
needs: deploy-v2-vercel
312+
steps:
313+
- name: Checkout
314+
uses: actions/checkout@v4
315+
- name: Setup Bun
316+
uses: ./.github/composite/setup-bun
317+
- name: Install dependencies
318+
run: bun install --frozen-lockfile
319+
- name: Setup Playwright
320+
uses: ./.github/actions/setup-playwright
321+
- name: Run Playwright tests
322+
run: bun e2e-customers
323+
env:
324+
BASE_URL: ${{needs.deploy-v2-vercel.outputs.deployment-url }}/url/
325+
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
326+
ARGOS_BUILD_NAME: 'customers-v2'
327+
- uses: actions/upload-artifact@v4
328+
if: ${{ !cancelled() }}
329+
with:
330+
name: playwright-test-results-customers
331+
path: packages/gitbook/test-results/
332+
retention-days: 3
283333
pagespeed-testing:
284334
runs-on: ubuntu-latest
285335
name: PageSpeed Testing

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"noUnusedImports": "error",
5959
"noVoidElementsWithChildren": "warn",
6060
"useJsxKeyInIterable": "warn",
61-
"useExhaustiveDependencies": "warn"
61+
"useExhaustiveDependencies": "warn",
62+
"noUnknownFunction": "warn"
6263
},
6364
"style": {
6465
"noNonNullAssertion": "warn",

packages/gitbook-v2/next.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const nextConfig = {
1515
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
1616
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
1717
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
18+
19+
// Used to detect if the app is running in V2 mode
20+
GITBOOK_V2: 'true',
1821
},
1922

2023
assetPrefix: process.env.GITBOOK_ASSETS_PREFIX,

packages/gitbook-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"scripts": {
2020
"generate": "rm -rf ./public && cp -r ../gitbook/public ./public",
21-
"dev:v2": "env-cmd --silent -f ../../.env.local next",
21+
"dev:v2": "env-cmd --silent -f ../../.env.local next --turbopack",
2222
"build": "next build",
2323
"build:v2": "next build",
2424
"start": "next start",

packages/gitbook/src/app/middleware/(site)/(core)/robots.txt/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { NextRequest } from 'next/server';
22

3-
import { getSite } from '@/lib/api';
4-
import { getAbsoluteHref } from '@/lib/links';
53
import { getSiteContentPointer } from '@/lib/pointer';
64
import { isSiteIndexable } from '@/lib/seo';
5+
import { fetchV1ContextForSitePointer } from '@/lib/v1';
76

87
export const runtime = 'edge';
98

@@ -12,13 +11,14 @@ export const runtime = 'edge';
1211
*/
1312
export async function GET(_req: NextRequest) {
1413
const pointer = await getSiteContentPointer();
15-
const site = await getSite(pointer.organizationId, pointer.siteId);
14+
const context = await fetchV1ContextForSitePointer(pointer);
15+
const { linker } = context;
1616

1717
const lines = [
1818
'User-agent: *',
1919
'Disallow: /~gitbook/',
20-
...((await isSiteIndexable(site))
21-
? ['Allow: /', `Sitemap: ${await getAbsoluteHref('/sitemap.xml', true)}`]
20+
...((await isSiteIndexable(context))
21+
? ['Allow: /', `Sitemap: ${linker.toAbsoluteURL(linker.toPathInSpace('/sitemap.xml'))}`]
2222
: ['Disallow: /']),
2323
];
2424
const content = lines.join('\n');

packages/gitbook/src/components/DocumentView/CodeBlock/theme.css

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
:root {
2-
--shiki-color-text: var(--color-tint-11);
2+
--shiki-color-text: theme("colors.tint.11");
33
--shiki-token-constant: #0a6355;
44
--shiki-token-string: #8b6d32;
5-
--shiki-token-comment: var(--color-teal-700 / 0.64);
6-
--shiki-token-keyword: var(--color-pomegranate-600);
5+
--shiki-token-comment: theme("colors.teal.700/.64");
6+
--shiki-token-keyword: theme("colors.pomegranate.600");
77
--shiki-token-parameter: #0a3069;
88
--shiki-token-function: #8250df;
99
--shiki-token-string-expression: #6a4906;
10-
--shiki-token-punctuation: var(--color-pomegranate-700 / 0.92);
11-
--shiki-token-link: var(--color-tint-12);
10+
--shiki-token-punctuation: theme("colors.pomegranate.700/.92");
11+
--shiki-token-link: theme("colors.tint.12");
1212
--shiki-token-inserted: #22863a;
1313
--shiki-token-deleted: #b31d28;
1414
--shiki-token-changed: #8250df;
1515
}
1616

1717
html.dark {
18-
--shiki-color-text: var(--color-tint-11);
18+
--shiki-color-text: theme("colors.tint.11");
1919
--shiki-token-constant: #d19a66;
20-
--shiki-token-string: var(--color-pomegranate-300);
21-
--shiki-token-comment: var(--color-teal-300 / 0.64);
22-
--shiki-token-keyword: var(--color-pomegranate-400);
23-
--shiki-token-parameter: var(--color-yellow-500);
20+
--shiki-token-string: theme("colors.pomegranate.300");
21+
--shiki-token-comment: theme("colors.teal.300/.64");
22+
--shiki-token-keyword: theme("colors.pomegranate.400");
23+
--shiki-token-parameter: theme("colors.yellow.500");
2424
--shiki-token-function: #56b6c2;
25-
--shiki-token-string-expression: var(--color-tint-11);
25+
--shiki-token-string-expression: theme("colors.tint.11");
2626
--shiki-token-punctuation: #acc6ee;
27-
--shiki-token-link: var(--color-pomegranate-400);
27+
--shiki-token-link: theme("colors.pomegranate.400");
2828
--shiki-token-inserted: #85e89d;
2929
--shiki-token-deleted: #fdaeb7;
3030
--shiki-token-changed: #56b6c2;

packages/gitbook/src/components/PageAside/PageAside.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import urlJoin from 'url-join';
1212

1313
import { getSpaceLanguage, t } from '@/intl/server';
1414
import { getDocumentSections } from '@/lib/document-sections';
15-
import { getAbsoluteHref } from '@/lib/links';
1615
import { tcls } from '@/lib/tailwind';
1716
import { getPDFUrlSearchParams } from '@/lib/urls';
1817

@@ -24,7 +23,7 @@ import { ScrollSectionsList } from './ScrollSectionsList';
2423
/**
2524
* Aside listing the headings in the document.
2625
*/
27-
export async function PageAside(props: {
26+
export function PageAside(props: {
2827
page: RevisionPageDocument;
2928
document: JSONDocument | null;
3029
context: GitBookSiteContext;
@@ -36,7 +35,7 @@ export async function PageAside(props: {
3635
const { customization, site, space } = context;
3736
const language = getSpaceLanguage(customization);
3837

39-
const pdfHref = await getAbsoluteHref(
38+
const pdfHref = context.linker.toPathInSpace(
4039
`~gitbook/pdf?${getPDFUrlSearchParams({
4140
page: page.id,
4241
only: true,

packages/gitbook/src/components/PageBody/PageBody.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function PageBody(props: {
2626
withPageFeedback: boolean;
2727
}) {
2828
const { page, context, ancestors, document, withPageFeedback } = props;
29-
const { space, customization } = context;
29+
const { customization } = context;
3030

3131
const asFullWidth = document ? hasFullWidthBlock(document) : false;
3232
const language = getSpaceLanguage(customization);
@@ -60,7 +60,7 @@ export function PageBody(props: {
6060
<PageCover as="hero" page={page} cover={page.cover} context={context} />
6161
) : null}
6262

63-
<PageHeader page={page} ancestors={ancestors} pages={context.pages} />
63+
<PageHeader context={context} page={page} ancestors={ancestors} />
6464
{document && !isNodeEmpty(document) ? (
6565
<React.Suspense
6666
fallback={
@@ -85,12 +85,7 @@ export function PageBody(props: {
8585
)}
8686

8787
{page.layout.pagination && customization.pagination.enabled ? (
88-
<PageFooterNavigation
89-
space={space}
90-
customization={customization}
91-
pages={context.pages}
92-
page={page}
93-
/>
88+
<PageFooterNavigation context={context} page={page} />
9489
) : null}
9590

9691
<div

packages/gitbook/src/components/PageBody/PageFooterNavigation.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
import {
2-
type CustomizationSettings,
3-
type Revision,
4-
type RevisionPageDocument,
5-
type SiteCustomizationSettings,
6-
SiteInsightsLinkPosition,
7-
type Space,
8-
} from '@gitbook/api';
1+
import { type RevisionPageDocument, SiteInsightsLinkPosition } from '@gitbook/api';
92
import { Icon, type IconName } from '@gitbook/icons';
103
import type React from 'react';
114

125
import { getSpaceLanguage, t } from '@/intl/server';
13-
import { getPageHref } from '@/lib/links';
146
import { resolvePrevNextPages } from '@/lib/pages';
157
import { tcls } from '@/lib/tailwind';
168

9+
import type { GitBookSiteContext } from '@v2/lib/context';
1710
import { Link, type LinkInsightsProps } from '../primitives';
1811

1912
/**
2013
* Show cards to go to previous/next pages at the bottom.
2114
*/
2215
export async function PageFooterNavigation(props: {
23-
space: Space;
24-
customization: CustomizationSettings | SiteCustomizationSettings;
25-
pages: Revision['pages'];
16+
context: GitBookSiteContext;
2617
page: RevisionPageDocument;
2718
}) {
28-
const { customization, pages, page } = props;
19+
const { context, page } = props;
20+
const { customization, pages, linker } = context;
2921
const { previous, next } = resolvePrevNextPages(pages, page);
3022
const language = getSpaceLanguage(customization);
31-
const previousHref = previous ? await getPageHref(pages, previous) : '';
32-
const nextHref = next ? await getPageHref(pages, next) : '';
23+
const previousHref = previous ? linker.toPathForPage({ pages, page: previous }) : '';
24+
const nextHref = next ? linker.toPathForPage({ pages, page: next }) : '';
3325

3426
return (
3527
<div

packages/gitbook/src/components/PageBody/PageHeader.tsx

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
import type { RevisionPage, RevisionPageDocument } from '@gitbook/api';
1+
import type { RevisionPageDocument } from '@gitbook/api';
22
import { Icon } from '@gitbook/icons';
33
import { Fragment } from 'react';
44

5-
import { getPageHref } from '@/lib/links';
65
import type { AncestorRevisionPage } from '@/lib/pages';
76
import { tcls } from '@/lib/tailwind';
7+
import type { GitBookSiteContext } from '@v2/lib/context';
88

99
import { PageIcon } from '../PageIcon';
1010
import { StyledLink } from '../primitives';
1111

1212
export async function PageHeader(props: {
13+
context: GitBookSiteContext;
1314
page: RevisionPageDocument;
1415
ancestors: AncestorRevisionPage[];
15-
pages: RevisionPage[];
1616
}) {
17-
const { page, ancestors, pages } = props;
17+
const { context, page, ancestors } = props;
18+
const { pages, linker } = context;
1819

1920
if (!page.layout.title && !page.layout.description) {
2021
return null;
2122
}
2223

23-
const ancestorElements = await Promise.all(
24-
ancestors.map(async (breadcrumb, index) => {
25-
const href = await getPageHref(pages, breadcrumb);
26-
return (
27-
<Fragment key={breadcrumb.id}>
28-
<li key={breadcrumb.id}>
29-
<StyledLink
30-
href={href}
31-
style={tcls(
32-
'no-underline',
33-
'hover:underline',
34-
'text-xs',
35-
'tracking-wide',
36-
'font-semibold',
37-
'uppercase',
38-
'flex',
39-
'items-center',
40-
'gap-1.5',
41-
'contrast-more:underline',
42-
'contrast-more:decoration-current'
43-
)}
44-
>
45-
<PageIcon
46-
page={breadcrumb}
47-
style="flex size-4 items-center justify-center text-base leading-none"
48-
/>
49-
{breadcrumb.title}
50-
</StyledLink>
51-
</li>
52-
{index !== ancestors.length - 1 && (
53-
<Icon icon="chevron-right" className={tcls('size-3', 'text-tint-subtle')} />
54-
)}
55-
</Fragment>
56-
);
57-
})
58-
);
59-
6024
return (
6125
<header
6226
className={tcls('max-w-3xl', 'mx-auto', 'mb-6', 'space-y-3', 'page-api-block:ml-0')}
6327
>
6428
{ancestors.length > 0 && (
6529
<nav>
6630
<ol className={tcls('flex', 'flex-wrap', 'items-center', 'gap-2')}>
67-
{ancestorElements}
31+
{ancestors.map((breadcrumb, index) => {
32+
const href = linker.toPathForPage({ pages, page: breadcrumb });
33+
return (
34+
<Fragment key={breadcrumb.id}>
35+
<li key={breadcrumb.id}>
36+
<StyledLink
37+
href={href}
38+
style={tcls(
39+
'no-underline',
40+
'hover:underline',
41+
'text-xs',
42+
'tracking-wide',
43+
'font-semibold',
44+
'uppercase',
45+
'flex',
46+
'items-center',
47+
'gap-1.5',
48+
'contrast-more:underline',
49+
'contrast-more:decoration-current'
50+
)}
51+
>
52+
<PageIcon
53+
page={breadcrumb}
54+
style="flex size-4 items-center justify-center text-base leading-none"
55+
/>
56+
{breadcrumb.title}
57+
</StyledLink>
58+
</li>
59+
{index !== ancestors.length - 1 && (
60+
<Icon
61+
icon="chevron-right"
62+
className={tcls('size-3', 'text-tint-subtle')}
63+
/>
64+
)}
65+
</Fragment>
66+
);
67+
})}
6868
</ol>
6969
</nav>
7070
)}

0 commit comments

Comments
 (0)