From 5c4923557fcd4dcfe8e4fbdc34374cde7d50573c Mon Sep 17 00:00:00 2001 From: Claire Chabas Date: Tue, 29 Jul 2025 20:39:26 +0200 Subject: [PATCH] Temporarily remove highlighting for PowerShell and C++ in Safari to avoid page crash (#3508) --- .changeset/sixty-toes-attack.md | 5 +++++ .../components/DocumentView/CodeBlock/highlight.ts | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/sixty-toes-attack.md diff --git a/.changeset/sixty-toes-attack.md b/.changeset/sixty-toes-attack.md new file mode 100644 index 000000000..2a15d032f --- /dev/null +++ b/.changeset/sixty-toes-attack.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Remove highlighting in Safari for PowerShell and C++ to avoid page crash until next version with bug fix is released diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts b/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts index c9f596034..80432f916 100644 --- a/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts +++ b/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts @@ -34,6 +34,8 @@ 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 +67,13 @@ export async function highlight( inlines: RenderedInline[] ): Promise { const langName = getBlockLang(block); - if (!langName) { - // Language not found, fallback to plain highlighting + + if (!langName || (isSafari && ['powershell', 'cpp'].includes(langName))) { + // Fallback to plain highlighting if + // - language is not found + // - TEMP : language is PowerShell or C++ and browser is Safari: + // RegExp#[Symbol.search] throws TypeError when `lastIndex` isn’t writable + // Fixed in upcoming Safari 18.6, remove when it'll be released - RND-7772 return plainHighlight(block, inlines); }