Skip to content

Fix inline expression crashing pages #3297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/deploy-preview.yaml
Original file line number Diff line number Diff line change
@@ -159,7 +159,7 @@ jobs:
runs-on: ubuntu-latest
name: Visual Testing v1
needs: deploy-v1-cloudflare
timeout-minutes: 8
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -220,7 +220,7 @@ jobs:
runs-on: ubuntu-latest
name: Visual Testing Customers v1
needs: deploy-v1-cloudflare
timeout-minutes: 8
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -240,7 +240,7 @@ jobs:
runs-on: ubuntu-latest
name: Visual Testing Customers v2
needs: deploy-v2-vercel
timeout-minutes: 8
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -261,7 +261,7 @@ jobs:
runs-on: ubuntu-latest
name: Visual Testing Customers v2 (Cloudflare)
needs: deploy-v2-cloudflare
timeout-minutes: 8
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
12 changes: 6 additions & 6 deletions bun.lock
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
"name": "@gitbook/cache-tags",
"version": "0.3.1",
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"assert-never": "^1.2.1",
},
"devDependencies": {
@@ -51,7 +51,7 @@
"name": "gitbook",
"version": "0.12.0",
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"@gitbook/cache-do": "workspace:*",
"@gitbook/cache-tags": "workspace:*",
"@gitbook/colors": "workspace:*",
@@ -150,7 +150,7 @@
"name": "gitbook-v2",
"version": "0.3.0",
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"@gitbook/cache-tags": "workspace:*",
"@opennextjs/cloudflare": "1.2.1",
"@sindresorhus/fnv1a": "^3.1.0",
@@ -209,7 +209,7 @@
"name": "@gitbook/react-contentkit",
"version": "0.7.0",
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"@gitbook/icons": "workspace:*",
"classnames": "^2.5.1",
},
@@ -267,7 +267,7 @@
},
"overrides": {
"@codemirror/state": "6.4.1",
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
},
@@ -632,7 +632,7 @@

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

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

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
"packageManager": "bun@1.2.11",
"overrides": {
"@codemirror/state": "6.4.1",
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
2 changes: 1 addition & 1 deletion packages/cache-tags/package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
},
"version": "0.3.1",
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"assert-never": "^1.2.1"
},
"devDependencies": {
2 changes: 1 addition & 1 deletion packages/gitbook-v2/package.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"version": "0.3.0",
"private": true,
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"@gitbook/cache-tags": "workspace:*",
"@opennextjs/cloudflare": "1.2.1",
"@sindresorhus/fnv1a": "^3.1.0",
2 changes: 1 addition & 1 deletion packages/gitbook/package.json
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static/icons && rm -rf ./public/~gitbook/static/math"
},
"dependencies": {
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"@gitbook/cache-do": "workspace:*",
"@gitbook/cache-tags": "workspace:*",
"@gitbook/colors": "workspace:*",
8 changes: 1 addition & 7 deletions packages/gitbook/src/components/DocumentView/Block.tsx
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {
} from '@/components/primitives';
import type { ClassValue } from '@/lib/tailwind';

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

/**
* Alternative to `assertNever` that returns `null` instead of throwing an error.
*/
function nullIfNever(_value: never): null {
return null;
}

export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
const { block, style, isEstimatedOffscreen, context } = props;

31 changes: 8 additions & 23 deletions packages/gitbook/src/components/DocumentView/Inline.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import type {
DocumentInline,
DocumentInlineAnnotation,
DocumentInlineButton,
DocumentInlineEmoji,
DocumentInlineImage,
DocumentInlineLink,
DocumentInlineMath,
DocumentInlineMention,
JSONDocument,
} from '@gitbook/api';
import assertNever from 'assert-never';
import type { DocumentInline, JSONDocument } from '@gitbook/api';

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

export function Inline<
T extends
| DocumentInlineImage
| DocumentInlineAnnotation
| DocumentInlineEmoji
| DocumentInlineLink
| DocumentInlineMath
| DocumentInlineMention
| DocumentInlineButton,
>(props: InlineProps<T>) {
export function Inline<T extends DocumentInline>(props: InlineProps<T>) {
const { inline, ...contextProps } = props;

switch (inline.type) {
@@ -66,7 +47,11 @@ export function Inline<
return <InlineImage {...contextProps} inline={inline} />;
case 'button':
return <InlineButton {...contextProps} inline={inline} />;
case 'expression':
// The GitBook API should take care of evaluating expressions.
// We should never need to render them.
return null;
default:
assertNever(inline);
return nullIfNever(inline);
}
}
7 changes: 7 additions & 0 deletions packages/gitbook/src/lib/typescript.ts
Original file line number Diff line number Diff line change
@@ -4,3 +4,10 @@
export function filterOutNullable<T>(value: T): value is NonNullable<T> {
return !!value;
}

/**
* Alternative to `assertNever` that returns `null` instead of throwing an error.
*/
export function nullIfNever(_value: never): null {
return null;
}
2 changes: 1 addition & 1 deletion packages/react-contentkit/package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
},
"dependencies": {
"classnames": "^2.5.1",
"@gitbook/api": "^0.119.0",
"@gitbook/api": "^0.120.0",
"@gitbook/icons": "workspace:*"
},
"peerDependencies": {