From 6a3e1cf6914c3d2c16e7875f2381a8cb7fe4c71d Mon Sep 17 00:00:00 2001 From: Claire Chabas Date: Fri, 18 Jul 2025 12:08:36 +0200 Subject: [PATCH 1/2] Fix code block crashing published page in Safari --- .../components/DocumentView/CodeBlock/highlight.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts b/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts index c9f596034a..092f20672e 100644 --- a/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts +++ b/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts @@ -34,6 +34,9 @@ export type RenderedInline = { body: React.ReactNode; }; +const isSafari = + typeof navigator !== 'undefined' && /^((?!chrome|android).)*safari/i.test(navigator.userAgent); + const theme = createCssVariablesTheme(); const { getSingletonHighlighter } = createSingletonShorthands( @@ -65,8 +68,12 @@ export async function highlight( inlines: RenderedInline[] ): Promise { const langName = getBlockLang(block); - if (!langName) { - // Language not found, fallback to plain highlighting + if (!langName || (isSafari && langName === 'powershell')) { + // Fallback to plain highlighting if + // - language is not found + // - language is `powershell` and browser is Safari: + // PowerShell commands can trigger complex regex that Safari + // JS engine doesn't support, causing the highlighter to crash. return plainHighlight(block, inlines); } From ad4f27cbed363949c6ce06a6689c48250cb23293 Mon Sep 17 00:00:00 2001 From: Claire Chabas Date: Fri, 18 Jul 2025 12:16:45 +0200 Subject: [PATCH 2/2] add changeset --- .changeset/wet-wolves-provide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wet-wolves-provide.md diff --git a/.changeset/wet-wolves-provide.md b/.changeset/wet-wolves-provide.md new file mode 100644 index 0000000000..d0185384c0 --- /dev/null +++ b/.changeset/wet-wolves-provide.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix code block with PowerShell crashing page in Safari