Repository navigation
fix(ui): put the typeset styles first, so a streamed document stops restyling - #470
Conversation
…estyling The typeset plugin appended its node last, and renderers match a document's top-level nodes by index, so every block a stream added replaced the <style> and restyled the whole document. Streaming SIMD through comark-chat's React MessageParts spent 4.3 s in style recalculation; it now spends 0.3 s. The streaming caret, which went into the last node, now ends the text instead of sitting after the typeset node on a line of its own. The first-child rule skips a leading <style>.
… base commit packages/chat/bench/stream.mjs builds a page with comark-chat's React MessageParts and comark-ui's preset with Shiki twice, from --base and from the working tree, and replays the SIMD fixture in Chromium. It reports commit time and Chromium's main-thread, style, and layout time over paired runs, checks the DOM matches, and checks a stateful component and a code group keep their state while prose streams after them.
Codex Review Summary: ❌ FailedThis 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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Important
Keep the stylesheet stable, but fix the duplicate streaming caret before merging. A React host re-render can add a second caret without receiving any new text.
Approach: Putting the scoped stylesheet at a stable index addresses the style churn; putting prose last also exposes a caret mutation in the pinned Comark renderer.
Reviewed changes — I checked the shared preset, the first-block spacing rule, and the Chromium replay.
- Typeset placement and spacing: The workspace build, 57 focused tests, and the new Chromium spacing test passed.
- Chat replay: All 16 sampled SIMD snapshots matched after normalization, with all 38 fences highlighted on both sides. The mixed replay retained the counter and selected tab.
gpt-6.2-sol(high) | 𝕏
comark-annotate
comark-badge
comark-bundle
comark-cards
comark-carousel
comark-cast
comark-charts
comark-chat
comark-chips
comark-cjk
comark-code
comark-code-notes
comark-colors
comark-comments
comark-critic
comark-deflist
comark-details
comark-diagrams
comark-diff
comark-embed
comark-fields
comark-figure
comark-file-tree
comark-footnotes
comark-git-graph
comark-github
comark-icon
comark-include
comark-keys
comark-links
comark-linter
comark-magic-move
comark-mark
markdown-it-to-comark
marked-to-comark
comark-mathml
comark-media
comark-metrics
migrate-to-comark
comark-outline
comark-properties
comark-qr
comark-quiz
comark-reading-time
remark-to-comark
comark-sources
comark-steps
comark-table
comark-tabs
comark-tests
comark-time
comark-ui
comark-xref
comark-zoom
commit: |
Latest result Pull request merged. Final answersSession Pull request merged. Session Pull request evidence changed. Session Pull request evidence changed. Session Pull request evidence changed. Session Pull request evidence changed. |
There was a problem hiding this comment.
ℹ️ No P0 or P1 findings remain; one benchmark portability issue is noted inline.
Reviewed changes — I reviewed 06a3c71 since the prior Pullfrog review.
- Kept the caret out of the parsed tree: React and Vue now use the sibling caret. Tests confirm that rendering the same document twice does not duplicate it and that turning streaming off removes it.
- Made the replay checks fail on bad inputs or lost state: Verified that an invalid baseline ref exits nonzero and that the Chromium chat replay retains the counter and selected tab. All 16 sampled SIMD snapshots matched, with 38 highlighted fences on each side.
The workspace build, typecheck, 458 UI and chat tests, and Chromium spacing test passed.
gpt-6.2-sol(high) | 𝕏

Streaming a long reply through comark-chat's React
MessagePartswith the preset restyles the whole document on almost every update. In the SIMD replay (38 Python fences, 256 characters every 40 ms), Chromium spends 4.3 s on style recalculation alone. The caret also sits on a line of its own under the text, not after the last word.The typeset plugin appended its node last, and
@comark/reactmatches a document's top-level nodes by index. So each update that added a block put that block where the<style>had been. React replaced the stylesheet, and the new one restyled every element, up to 32 ms per update by the end of SIMD. comark-code's frame callback then measured every code block under the new styles. The caret goes into the last top-level node, which was the empty typeset node.This PR puts the typeset node first, and keeps exactly one when a streaming parse reuses the previous tree's first nodes. The rule that removes the space above the first block now skips a leading
<style>(:nth-child(1 of :not(style, script))), so a finished document renders as before. The HTML output now opens with the<style>rather than ending with it.mainHeadless Chromium (Playwright 1.64.1), React 19.3.1,
@comark/react0.9.0 and Shiki 4.5.0 from the lockfile, Linux. The machine was busy with other jobs, so absolute times run high; the runs pairmainand the branch and alternate which goes first.The second commit adds the benchmark that produced these numbers,
packages/chat/bench/stream.mjs. It builds the chat page from source twice, at--base(defaultorigin/main) and from the working tree.--mode checkconfirms the DOM after every tenth update matchesmain, apart from where the<style>and the caret sit, with all 38 fences highlighted.--mode chatstreams a short reply and confirms a stateful component and a code group's selected tab keep their state.I also tried the block reuse from the plan: keep the React output of completed blocks through
render.markdown. It was slower (5.6 s to 7.3 s with updates back to back) and its DOM didn't matchmain. Comark reparses the whole document whenever the unparsed tail holds a#, which every Python comment does, so few blocks keep their identity. A Shiki token cache saved about 9%. Neither is in this PR.I haven't measured Firefox, Safari, or the Vue and Svelte chat entries.
Before/after and numbers: https://drop.vitehub.dev/d/b6mpbfesf6sd/before-after