Skip to content

fix(emcn): stop wiping virtualized code viewer row measurements on content changes#5649

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/code-viewer-virtualized-wrap-overlap
Jul 13, 2026
Merged

fix(emcn): stop wiping virtualized code viewer row measurements on content changes#5649
waleedlatif1 merged 1 commit into
stagingfrom
fix/code-viewer-virtualized-wrap-overlap

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes wrapped lines overlapping in the virtualized Code.Viewer (workflow editor terminal Output/Input panel) — reported in Slack with a wrapped conversationId line drawing over the row below it
  • Root cause: the re-measure effect called virtualizer.measure() on every visibleLines identity change. TanStack Virtual's measure() wipes the size cache without re-measuring mounted rows — ResizeObserver only fires on size changes and React never re-invokes an unchanged measureElement ref — so any content change that keeps row heights (Prism finishing its lazy load right after first open, search-highlight <mark> wrapping) permanently collapsed every wrapped row to the 21px estimate
  • The wipe now runs only when leaving wrap mode, the one transition that needs it: refs detach with wrapped heights still cached, and falling back to the fixed estimate is exactly correct for nowrap. Entering wrap re-measures as refs attach, and genuine height changes are caught by the per-row ResizeObserver, so no other trigger is needed (this also removes a redundant mount-time wipe + re-measure pass)

Type of Change

  • Bug fix

Testing

Reproduced deterministically in an isolated Playwright harness rendering Code.Viewer with virtualized + wrapText: before the fix, a height-preserving content change left rows at translateY(0/21/42…) while wrapped rows measured taller (overlap); after, every row's offset equals the cumulative measured heights. Ran a 12-scenario matrix (prism lazy-load, search set/clear, JSON collapse toggle on/off, content change both directions, width narrow/restore, wrap off/on, search after wrap cycle): original code fails 8/12 with overlap, fixed code passes 12/12 including every scenario the original passed. Typecheck (emcn + sim) and biome clean.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jul 13, 2026 11:17pm

Request Review

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Single, targeted change to virtualizer measurement timing in code.tsx with no auth, data, or API impact.

Overview
Fixes wrapped line overlap in virtualized Code.Viewer (e.g. workflow terminal Output/Input) by changing when TanStack Virtual’s row size cache is cleared.

The re-measure useEffect no longer depends on visibleLines or calls virtualizer.measure() on every content update. measure() now runs only when wrapText becomes false, so cached wrapped heights are dropped when leaving wrap mode and fixed 21px estimates apply for nowrap. Entering wrap and height-preserving updates (Prism lazy load, search <mark> highlights) rely on measureElement refs and per-row ResizeObserver instead of a global cache wipe that left mounted rows stuck at the estimate.

Reviewed by Cursor Bugbot for commit d947cb9. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes when the virtualized code viewer resets row measurements.

  • Limits virtualizer.measure() to the transition out of wrap mode.
  • Removes visibleLines from the reset effect dependencies.
  • Documents why content-only changes should rely on row ResizeObserver measurement instead.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Wrapped rows keep per-row measurement active.
  • Nowrap rows still use the fixed row estimate after the cache reset.

Important Files Changed

Filename Overview
packages/emcn/src/components/code/code.tsx Narrows the virtualized code viewer measurement reset to wrap-off transitions and keeps content changes on per-row measurement.

Reviews (1): Last reviewed commit: "fix(emcn): stop wiping virtualized code ..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 3ac5e90 into staging Jul 13, 2026
13 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/code-viewer-virtualized-wrap-overlap branch July 13, 2026 23:19
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