8000 fix(review): render large code files without highlighting by simon-inkie · Pull Request #42 · simon-inkie/inkie-deck · GitHub
[go: up one dir, main page]

Skip to content

fix(review): render large code files without highlighting - #42

Merged
simon-inkie merged 1 commit into
mainfrom
fix/large-file-highlight
Oct 3, 2026
Merged

simon-inkie merged 1 commit into
mainfrom
fix/large-file-highlight

Conversation

@simon-inkie
Copy link
Copy Markdown
Owner

What

A large review file was syntax-highlighted in full and given a DOM node per line. Both scale with file size, so opening a big file stalled the panel.

Above 128 KiB of content, or more than 4,000 lines, CodeView now renders the file as plain preformatted text with no line-number gutter, and says in the panel that highlighting is off. Below either threshold nothing changes.

Two details worth a reviewer's attention:

  • The plain path renders content as React text (<code>{content}</code>) rather than through dangerouslySetInnerHTML, so a large file containing markup is escaped rather than injected. The test asserts <script> survives as text.
  • shouldRenderPlainCode counts newlines with a loop rather than split("\n"), so the size check does not itself allocate a large array.

Review legs

  • Remote CodeRabbit unavailable (subscription, 2 Oct). Not treated as a clean review.
  • Peer reviewer: pending, cross-lane.
  • Independent model-diverse check: pending.
  • Suites: deck 2085 passed / 11 skipped (96 files), typecheck clean, check:leaks clean (386 files, 30 rules), check:dashes clean, lib-version-gate clean. The new suite is 4/4.

Not tested

  • No live browser measurement of the stall threshold; the 128 KiB and 4,000-line budgets are carried over unchanged from the internal upstream, where they were chosen against a real stall.
  • No e2e run.

OSS-clean

Public repo. No personal or customer names, no internal agent names, no /home paths, no keys, no commercial or pricing content.

A large review file was syntax-highlighted in full and given a DOM node per
line, which stalled the panel. The server's 2 MB read cap is a security bound,
not a client-side highlighting budget.

Above 128 KiB of content, or more than 4,000 lines, render the file as plain
preformatted text with no gutter and say why in the panel. Below either
threshold nothing changes.

The plain path renders content as React text rather than innerHTML, so a large
file containing markup is escaped, not injected
8000
.
@simon-inkie
simon-inkie merged commit c32e578 into main Oct 3, 2026
4 checks passed
@simon-inkie
Copy link
Copy Markdown
Owner Author

Review, Sol 6.1, 2026-10-02

No findings.

Reviewed SHA fc11ff7. Read both changed files in full and checked surrounding rendering, CSS and server limits. No introduced security issues, public-repo leaks or scope creep found.

Executed all four added test cases and exact 4,000/4,001-line boundary checks using an in-memory harness with real React server rendering; all passed.

Did not run Vitest itself, the full suite, typechecking or browser performance/layout tests. No files or Git state changed.

@simon-inkie
Copy link
Copy Markdown
Owner Author

Review, Sonnet, 2026-10-03

PR 42, fix(review): render large code files without highlighting
Head SHA reviewed: fc11ff7
Verdict: PASS with notes (0 Major)

Summary

CodeView falls back to a plain <pre><code>{content}</code></pre> above 128 KiB or 4,000 lines. Hooks are all called before the early return, the plain path renders content as a React text node (escaped, no dangerouslySetInnerHTML), the line counter loop avoids allocating, and the tests assert escaping. Small and correct.

Critical

None.

Major

None.

Minor

  1. packages/deck/app/components/CodeView.tsx:37-51: content.length counts UTF-16 code units, not bytes, so the "128 KiB" label overstates strictness for non-ASCII content (128K CJK characters is roughly 384 KB). Rename to MAX_HIGHLIGHT_CHARS in the comment ("128K characters") or leave a comment saying it is a perf budget, not a byte cap. No behavioural fix needed.
  2. shouldRenderPlainCode counts a trailing newline as a line: a file of exactly 4,000 lines ending in \n counts 4,001 and goes plain. Harmless, but the boundary is untested. Add exact-boundary tests: "x\n".repeat(3999) + "x" (4,000 lines, false) and the same plus "\n" (true, as written), so the intended semantics are pinned.
  3. Test at test/code-view-large-file.test.tsx (4,001 lines): "line\n".repeat(4001) is 4,002 lines by this counter, so it does not sit on the boundary it implies.
  4. Plain-path notice uses text-muted-foreground on a hardcoded #1f1f1f background. In the light theme that token is a mid-grey tuned for a light surface and may be low contrast. Use an explicit colour (for example #9da1a6) as the rest of the dark body does.
  5. Files just under the threshold still go through hljs in full (minified JS of 120 KB on a single line can still be slow). Acceptable given the carried-over budget; a follow-up could add a per-line length guard.

Nit

  • The file header comment (lines 1-23) still says output is always injected as innerHTML with a gutter; add one line describing the plain path.
  • The plain wrapper duplicates the dark-theme inline styles; extract a small constant.
  • lineCount useMemo returns 0 in plain mode; fine, but the early return could sit above both useMemos for readability (hooks rule satisfied either way since the hooks are not conditional).

Test would fail without the change

Yes: the new suite imports shouldRenderPlainCode, which does not exist on main, and the 1 MB case would otherwise render the hljs class. The <script> assertion is meaningful (checks both the escaped and raw form).

Public-repo hygiene

Clean in the diff: no names, /home paths, secrets or plan mentions.

Did not check

  • No browser measurement; I did not validate that 128 KiB / 4,000 lines are the right stall thresholds.
  • Did not check ReviewPanel for any feature that depends on the gutter or on hljs spans (the only importer is ReviewPanel.tsx:362 and it passes content and lang only, so nothing obvious).
  • Did not run the suite or typecheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0