Repository navigation
perf(ui): defer syntax highlighting until code renders - #175105
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96c2504720
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| function markdownRenderKey(options: MarkdownRenderEnv): string { | ||
| return `${i18n.getLocale()}\0${options.assistantTranscriptRoleHeaders}\0${options.codeBlockChrome}\0${options.codeBlockInteraction}\0${options.fileLinks}\0${JSON.stringify(options.githubRepo ? [options.githubRepo.owner, options.githubRepo.repo] : null)}\0${markdownGitHubAliasSignature(options.githubRepositories, options.githubRepo)}\0${options.interactiveImages}\0${options.linkFavicons}\0${options.progressBars}\0${options.mode}\0${options.remoteImages}\0${options.sessionLinks}\0${options.tableInteractions}\0${JSON.stringify(options.humanMentionTokens ?? [])}`; | ||
| return `${markdownHighlightingReady()}\0${i18n.getLocale()}\0${options.assistantTranscriptRoleHeaders}\0${options.codeBlockChrome}\0${options.codeBlockInteraction}\0${options.fileLinks}\0${JSON.stringify(options.githubRepo ? [options.githubRepo.owner, options.githubRepo.repo] : null)}\0${markdownGitHubAliasSignature(options.githubRepositories, options.githubRepo)}\0${options.interactiveImages}\0${options.linkFavicons}\0${options.progressBars}\0${options.mode}\0${options.remoteImages}\0${options.sessionLinks}\0${options.tableInteractions}\0${JSON.stringify(options.humanMentionTokens ?? [])}`; |
There was a problem hiding this comment.
Subscribe only code-bearing renders to highlighter readiness
When the first code block finishes loading the highlighter, this unconditional signal read invalidates every mounted Markdown computation, including prose-only transcript messages. Because readiness is also part of the cache key, those messages miss their existing false entries and are reparsed, sanitized, and reconciled together; a long chat can therefore incur a large main-thread spike exactly when the first code block appears. Gate this dependency on content that can actually invoke highlighting, so prose retains its cached rendering.
AGENTS.md reference: ui/AGENTS.md:L38-L42
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesThis PR loads syntax highlighting on demand and replaces the reader’s emoji plugin runtime with shared shortcode replacement. Example: Open a prose-only chat, then receive a TypeScript code block containing const answer = 42.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it delivers a useful, maintainer-directed loading improvement that current main does not provide. The prior rendering findings are repaired, with no new actionable defect found; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherControl UI Markdown consumers turn transcript and document text into sanitized HTML, with shared code rendering and incremental DOM reconciliation preserving reader controls. flowchart TD
A[Transcript and document text] --> B[Markdown parser]
B --> C[Shared code renderer]
C --> D[Lazy highlighter]
D --> C
B --> E[HTML sanitizer]
E --> F[Reactive views and DOM reconciler]
Technical reviewBest possible solution: Retain the shared lazy highlighter and existing sanitizer/reconciler owners, then land through the normal exact-head CI gates. Do we have a high-confidence way to reproduce the issue? Current-main source directly imports the highlighter and fourteen grammars through the shared code renderer, establishing the eager-loading path without executing target code. Is this the best way to solve the issue? The change cuts loading at the existing shared renderer, preserves its grammar and sanitization contracts, and uses the existing incremental DOM owner to retain controls. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d739d3592ba4. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +199, Tests +212, Docs +4, Other 0. Total +415 across 25 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 17, 2026, 2:17 AM ET / 06:17 UTC (Revision 4). |
Keep pending highlighted HTML in the existing mutable DOM tail across streaming completion, loaded history, and JSON. Preserve attachment and sidebar controls with incremental reconciliation, and cover the real transcript entry points with a delayed-load regression.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Keep prose caches and literal block art independent of the optional highlighter. Preserve the synchronous streaming workload test after loading highlighting, and cover pending block art and prose work counts.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Keep the browser clipboard proof independent of incremental markdown comment boundaries while selecting the same visible words.
Keep the live-event selection retention proof while allowing the optional highlighter to load before selecting its output.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* perf(ui): defer markdown highlighting until code renders * fix(ui): retain markdown controls while highlighting loads Keep pending highlighted HTML in the existing mutable DOM tail across streaming completion, loaded history, and JSON. Preserve attachment and sidebar controls with incremental reconciliation, and cover the real transcript entry points with a delayed-load regression. * fix(ui): scope lazy highlighting invalidation to code Keep prose caches and literal block art independent of the optional highlighter. Preserve the synchronous streaming workload test after loading highlighting, and cover pending block art and prose work counts. * test(ui): select transcript text across DOM markers Keep the browser clipboard proof independent of incremental markdown comment boundaries while selecting the same visible words. * test(ui): wait for lazy Debug payload highlighting Keep the live-event selection retention proof while allowing the optional highlighter to load before selecting its output.
What Problem This Solves
Chat loads the syntax highlighter and fourteen language grammars even when the conversation contains only prose. Reader documents also load a general emoji plugin to perform named-shortcode replacement.
User Impact
Plain chat boots with 23,232 fewer gzip bytes. The first code block loads highlighting on demand; code remains escaped, readable, and copyable while loading or if the optional chunk fails. Completed rendering preserves the previous HTML, including code controls, links, tables, and sanitization.
Why This Change Was Made
Split highlighting from the parser/sanitizer chunk, refresh cached and streamed markup when it becomes available, and keep the reader and plugin-readme consumers reactive. Reader emoji expansion now uses the existing catalog and token-replacement owner, without the general plugin runtime. Chat shortcode behavior and composer completion are unchanged.
The apparent second renderer is actually a separate source-ownership parser: MarkdownIt already owns transcript, reasoning, and document HTML; mdast/micromark owns exact code/reasoning offsets, container boundaries, and incremental retention. These contracts are not interchangeable, so the canonical source parser and all sanitizer boundaries remain. The full emoji catalog also remains necessary for completion and picker coverage. No dependency was added or upgraded.
Evidence
Final production builds use matching comparison metadata on the same machine and toolchain, checked with the strict
--base-distperformance tool; baseafc42329297a5134f023a2d51c5b61290b299aa6:Startup is 337,449 B gzip / 7 JS requests / 1 CSS request. Chat's hard cap drops from 1,580,000 to 1,550,000 B; other byte/request caps stay unchanged. The generated boot manifest excludes all highlight.js modules.
60e418eb57d3b3fb4f20987a1a4895c49699dc57; hosted build-artifacts and workflow-sanity gates also passedTouched production TypeScript: 4,320 → 4,462 LOC (+142). Tests/fixtures: 2,356 → 2,641 LOC (+285). Solid checklist counts are unchanged: controllers 0, effects 4, render effects 0, untrack 0, native listeners 1, DOM queries 3, class-string patterns 0, flush 0, ownership capture 2.
CI run 39003243581 caught a missing NodeNext JSON import attribute and two control-retention regressions. The repair keeps provisional code in the incremental streaming tail until the first highlighting request settles, then lets the existing reconciler promote it normally. Markdown attachments opt into the same incremental reconciliation within their existing keyed source lifetime. A shared partition helper also covers loaded history, JSON, and finalizing a stream while highlighting is pending. The sidebar and attachment readers use incremental refs. The delayed-load regression exercises actual transcript preparation and JSON rendering, retaining code wrappers, expanded/wrapped state, and JSON raw mode; the DOM reconciler is unchanged. These failures are treated as attributable and repaired, not inherited.
Review also caught broad prose invalidation when highlighting loaded. Cache readiness now tracks only highlightable code. The next full-CI run (39006808932) exposed pending highlighting withholding literal block art and a synchronous sanitizer-work test that never yielded for the lazy import. The block-art path now stays independent of highlighting; the workload suite explicitly awaits the highlighter, while the controlled delayed-load test verifies prose does not rerender and block art stays literal before loading completes. Both failures reproduce on the repair head and pass on the original base; all 31 final focused cases pass. The copy E2E also assumed a paragraph’s first child was text; incremental rendering legitimately inserts comment markers. It now locates the same visible words with a text-node walker and still exercises the real browser selection and clipboard command. Its typecheck, lint, and independent review pass; its browser proof passed in full PR CI. The Debug event-log browser test also waits for its initial highlighted span before selecting it; Chromium then passes all node-identity and selected-text retention assertions across live prepend/eviction. This test-only adjustment passes lint, types, and independent review.
The added production code is the shared lazy-load/readiness boundary and the small reader emoji rule; the highlighter implementation and grammar set move intact. No rendering controllers, effects, listeners, DOM queries, or ownership-capture calls were added.
Screenshots below use only synthetic content.
The completed run 39007690123 has only the copy-test text-node assumption and initial Debug highlighting wait repaired in the final two test commits. Its skill-preview, remaining UI, browser-extension, and real-Gateway shards passed. The final full-CI run 39008949041 passed with both test repairs, including every UI, browser-extension, and real-Gateway shard.