Skip to content

Commit c3f56ec

Browse files
authored
Return null if block not handled (#2527)
1 parent fe9e6c1 commit c3f56ec

File tree

1 file changed

+9
-2
lines changed
  • packages/gitbook/src/components/DocumentView

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export interface BlockProps<Block extends DocumentBlock> extends DocumentContext
4242
style?: ClassValue;
4343
}
4444

45+
/**
46+
* Alternative to `assertNever` that returns `null` instead of throwing an error.
47+
*/
48+
function nullIfNever(value: never): null {
49+
return null;
50+
}
51+
4552
export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
4653
const { block, style, ...contextProps } = props;
4754

@@ -98,7 +105,7 @@ export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
98105
case 'synced-block':
99106
return <BlockSyncedBlock {...props} {...contextProps} block={block} />;
100107
default:
101-
assertNever(block);
108+
return nullIfNever(block);
102109
}
103110
})();
104111

@@ -148,6 +155,6 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
148155
case 'tabs-item':
149156
throw new Error('Blocks should be directly rendered by parent');
150157
default:
151-
assertNever(block);
158+
return nullIfNever(block);
152159
}
153160
}

0 commit comments

Comments
 (0)