From 2cdf4d7bbfc004f03dbc7872cbb8c64a0003e16b Mon Sep 17 00:00:00 2001 From: Ian Kerins Date: Thu, 18 Jan 2024 19:50:12 -0500 Subject: [PATCH] Skip syntax highlighting files with long lines We have frozen some browsers with the status quo :). --- .changeset/shaggy-wolves-roll.md | 5 +++++ src/routes/(search-page)/line-group.svelte | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .changeset/shaggy-wolves-roll.md diff --git a/.changeset/shaggy-wolves-roll.md b/.changeset/shaggy-wolves-roll.md new file mode 100644 index 0000000..0f7707f --- /dev/null +++ b/.changeset/shaggy-wolves-roll.md @@ -0,0 +1,5 @@ +--- +"neogrok": patch +--- + +Skip syntax highlighting files with long lines diff --git a/src/routes/(search-page)/line-group.svelte b/src/routes/(search-page)/line-group.svelte index fe98b4f..ef52b91 100644 --- a/src/routes/(search-page)/line-group.svelte +++ b/src/routes/(search-page)/line-group.svelte @@ -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; + } } }