Skip to content

Commit 5c49235

Browse files
authored
Temporarily remove highlighting for PowerShell and C++ in Safari to avoid page crash (#3508)
1 parent b1f608b commit 5c49235

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changeset/sixty-toes-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Remove highlighting in Safari for PowerShell and C++ to avoid page crash until next version with bug fix is released

packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export type RenderedInline = {
3434
body: React.ReactNode;
3535
};
3636

37+
const isSafari =
38+
typeof navigator !== 'undefined' && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
3739
const theme = createCssVariablesTheme();
3840

3941
const { getSingletonHighlighter } = createSingletonShorthands(
@@ -65,8 +67,13 @@ export async function highlight(
6567
inlines: RenderedInline[]
6668
): Promise<HighlightLine[]> {
6769
const langName = getBlockLang(block);
68-
if (!langName) {
69-
// Language not found, fallback to plain highlighting
70+
71+
if (!langName || (isSafari && ['powershell', 'cpp'].includes(langName))) {
72+
// Fallback to plain highlighting if
73+
// - language is not found
74+
// - TEMP : language is PowerShell or C++ and browser is Safari:
75+
// RegExp#[Symbol.search] throws TypeError when `lastIndex` isn’t writable
76+
// Fixed in upcoming Safari 18.6, remove when it'll be released - RND-7772
7077
return plainHighlight(block, inlines);
7178
}
7279

0 commit comments

Comments
 (0)