Skip to content

Commit fa3d2aa

Browse files
authored
Fix inline expression crashing pages (#3297)
1 parent e7a591d commit fa3d2aa

File tree

10 files changed

+31
-45
lines changed

10 files changed

+31
-45
lines changed

.github/workflows/deploy-preview.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
runs-on: ubuntu-latest
160160
name: Visual Testing v1
161161
needs: deploy-v1-cloudflare
162-
timeout-minutes: 8
162+
timeout-minutes: 10
163163
steps:
164164
- name: Checkout
165165
uses: actions/checkout@v4
@@ -220,7 +220,7 @@ jobs:
220220
runs-on: ubuntu-latest
221221
name: Visual Testing Customers v1
222222
needs: deploy-v1-cloudflare
223-
timeout-minutes: 8
223+
timeout-minutes: 10
224224
steps:
225225
- name: Checkout
226226
uses: actions/checkout@v4
@@ -240,7 +240,7 @@ jobs:
240240
runs-on: ubuntu-latest
241241
name: Visual Testing Customers v2
242242
needs: deploy-v2-vercel
243-
timeout-minutes: 8
243+
timeout-minutes: 10
244244
steps:
245245
- name: Checkout
246246
uses: actions/checkout@v4
@@ -261,7 +261,7 @@ jobs:
261261
runs-on: ubuntu-latest
262262
name: Visual Testing Customers v2 (Cloudflare)
263263
needs: deploy-v2-cloudflare
264-
timeout-minutes: 8
264+
timeout-minutes: 10
265265
steps:
266266
- name: Checkout
267267
uses: actions/checkout@v4

bun.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"name": "@gitbook/cache-tags",
2727
"version": "0.3.1",
2828
"dependencies": {
29-
"@gitbook/api": "^0.119.0",
29+
"@gitbook/api": "^0.120.0",
3030
"assert-never": "^1.2.1",
3131
},
3232
"devDependencies": {
@@ -51,7 +51,7 @@
5151
"name": "gitbook",
5252
"version": "0.12.0",
5353
"dependencies": {
54-
"@gitbook/api": "^0.119.0",
54+
"@gitbook/api": "^0.120.0",
5555
"@gitbook/cache-do": "workspace:*",
5656
"@gitbook/cache-tags": "workspace:*",
5757
"@gitbook/colors": "workspace:*",
@@ -150,7 +150,7 @@
150150
"name": "gitbook-v2",
151151
"version": "0.3.0",
152152
"dependencies": {
153-
"@gitbook/api": "^0.119.0",
153+
"@gitbook/api": "^0.120.0",
154154
"@gitbook/cache-tags": "workspace:*",
155155
"@opennextjs/cloudflare": "1.2.1",
156156
"@sindresorhus/fnv1a": "^3.1.0",
@@ -209,7 +209,7 @@
209209
"name": "@gitbook/react-contentkit",
210210
"version": "0.7.0",
211211
"dependencies": {
212-
"@gitbook/api": "^0.119.0",
212+
"@gitbook/api": "^0.120.0",
213213
"@gitbook/icons": "workspace:*",
214214
"classnames": "^2.5.1",
215215
},
@@ -267,7 +267,7 @@
267267
},
268268
"overrides": {
269269
"@codemirror/state": "6.4.1",
270-
"@gitbook/api": "^0.119.0",
270+
"@gitbook/api": "^0.120.0",
271271
"react": "^19.0.0",
272272
"react-dom": "^19.0.0",
273273
},
@@ -632,7 +632,7 @@
632632

633633
"@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@6.6.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
634634

635-
"@gitbook/api": ["@gitbook/api@0.119.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-l2gfJ5+1HT3Sj1OQCh72lUOGU9LV9WbDjgKPjxIFz+NgOhSest1bJ3JhmHP66Xd4ETpmm0YQqnq4y18wKRMjBQ=="],
635+
"@gitbook/api": ["@gitbook/api@0.120.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-FiRmPiSBwobMxmNjd14QkkOdM95BAPLDDRShgpS9Vsd8lHjNMyZfrJKVJTsJUuFcgYoi4cqNw9yu/TiUBUgv3g=="],
636636

637637
"@gitbook/cache-do": ["@gitbook/cache-do@workspace:packages/cache-do"],
638638

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"packageManager": "bun@1.2.11",
1111
"overrides": {
1212
"@codemirror/state": "6.4.1",
13-
"@gitbook/api": "^0.119.0",
13+
"@gitbook/api": "^0.120.0",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0"
1616
},

packages/cache-tags/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"version": "0.3.1",
1212
"dependencies": {
13-
"@gitbook/api": "^0.119.0",
13+
"@gitbook/api": "^0.120.0",
1414
"assert-never": "^1.2.1"
1515
},
1616
"devDependencies": {

packages/gitbook-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.3.0",
44
"private": true,
55
"dependencies": {
6-
"@gitbook/api": "^0.119.0",
6+
"@gitbook/api": "^0.120.0",
77
"@gitbook/cache-tags": "workspace:*",
88
"@opennextjs/cloudflare": "1.2.1",
99
"@sindresorhus/fnv1a": "^3.1.0",

packages/gitbook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static/icons && rm -rf ./public/~gitbook/static/math"
1717
},
1818
"dependencies": {
19-
"@gitbook/api": "^0.119.0",
19+
"@gitbook/api": "^0.120.0",
2020
"@gitbook/cache-do": "workspace:*",
2121
"@gitbook/cache-tags": "workspace:*",
2222
"@gitbook/colors": "workspace:*",

packages/gitbook/src/components/DocumentView/Block.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@/components/primitives';
1111
import type { ClassValue } from '@/lib/tailwind';
1212

13+
import { nullIfNever } from '@/lib/typescript';
1314
import { BlockContentRef } from './BlockContentRef';
1415
import { CodeBlock } from './CodeBlock';
1516
import { Columns } from './Columns';
@@ -45,13 +46,6 @@ export interface BlockProps<Block extends DocumentBlock> extends DocumentContext
4546
style?: ClassValue;
4647
}
4748

48-
/**
49-
* Alternative to `assertNever` that returns `null` instead of throwing an error.
50-
*/
51-
function nullIfNever(_value: never): null {
52-
return null;
53-
}
54-
5549
export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
5650
const { block, style, isEstimatedOffscreen, context } = props;
5751

packages/gitbook/src/components/DocumentView/Inline.tsx

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
import type {
2-
DocumentInline,
3-
DocumentInlineAnnotation,
4-
DocumentInlineButton,
5-
DocumentInlineEmoji,
6-
DocumentInlineImage,
7-
DocumentInlineLink,
8-
DocumentInlineMath,
9-
DocumentInlineMention,
10-
JSONDocument,
11-
} from '@gitbook/api';
12-
import assertNever from 'assert-never';
1+
import type { DocumentInline, JSONDocument } from '@gitbook/api';
132

3+
import { nullIfNever } from '@/lib/typescript';
144
import { Annotation } from './Annotation/Annotation';
155
import type { DocumentContextProps } from './DocumentView';
166
import { Emoji } from './Emoji';
@@ -39,16 +29,7 @@ export interface InlineProps<T extends DocumentInline> extends DocumentContextPr
3929
children?: React.ReactNode;
4030
}
4131

42-
export function Inline<
43-
T extends
44-
| DocumentInlineImage
45-
| DocumentInlineAnnotation
46-
| DocumentInlineEmoji
47-
| DocumentInlineLink
48-
| DocumentInlineMath
49-
| DocumentInlineMention
50-
| DocumentInlineButton,
51-
>(props: InlineProps<T>) {
32+
export function Inline<T extends DocumentInline>(props: InlineProps<T>) {
5233
const { inline, ...contextProps } = props;
5334

5435
switch (inline.type) {
@@ -66,7 +47,11 @@ export function Inline<
6647
return <InlineImage {...contextProps} inline={inline} />;
6748
case 'button':
6849
return <InlineButton {...contextProps} inline={inline} />;
50+
case 'expression':
51+
// The GitBook API should take care of evaluating expressions.
52+
// We should never need to render them.
53+
return null;
6954
default:
70-
assertNever(inline);
55+
return nullIfNever(inline);
7156
}
7257
}

packages/gitbook/src/lib/typescript.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@
44
export function filterOutNullable<T>(value: T): value is NonNullable<T> {
55
return !!value;
66
}
7+
8+
/**
9+
* Alternative to `assertNever` that returns `null` instead of throwing an error.
10+
*/
11+
export function nullIfNever(_value: never): null {
12+
return null;
13+
}

packages/react-contentkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"classnames": "^2.5.1",
13-
"@gitbook/api": "^0.119.0",
13+
"@gitbook/api": "^0.120.0",
1414
"@gitbook/icons": "workspace:*"
1515
},
1616
"peerDependencies": {

0 commit comments

Comments
 (0)