Skip to content

Commit

Permalink
Skip syntax highlighting files with long lines
Browse files Browse the repository at this point in the history
We have frozen some browsers with the status quo :).
  • Loading branch information
isker committed Jan 19, 2024
1 parent c3afe81 commit 2cdf4d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-wolves-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"neogrok": patch
---

Skip syntax highlighting files with long lines
16 changes: 13 additions & 3 deletions src/routes/(search-page)/line-group.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@
$: {
if (visible) {
// Shikiji only accepts a single string even though it goes
// right ahead and splits it :(.
highlight(lines.map(({ line: { text } }) => text).join("\n"));
// Skip highlighting anything with long lines, as it's an excellent way to
// freeze the browser. Such files are probably minified web assets, or
// otherwise low-signal.
if (!lines.some(({ line }) => line.text.length >= 1000)) {
// Shikiji only accepts a single string even though it goes
// right ahead and splits it :(.
highlight(lines.map(({ line: { text } }) => text).join("\n"));
} else {
// We can have defined `highlights` here if our LineGroup was cut in two
// by a now-removed "hidden" threshold. Having highlights for part of
// the group but not the rest is strange in the UI, so remove it all.
highlights = undefined;
}
}
}
Expand Down

0 comments on commit 2cdf4d7

Please sign in to comment.