File tree Expand file tree Collapse file tree
packages/emcn/src/components/code Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1015,12 +1015,21 @@ const VirtualizedViewerInner = memo(function VirtualizedViewerInner({
10151015 } )
10161016
10171017 /**
1018- * Re-measure rows when wrap mode or content changes so dynamic (wrapped) row
1019- * heights stay accurate. Fixed-height (`nowrap`) rows do not need re-measuring.
1018+ * Drop cached row measurements when leaving wrap mode: the measureElement
1019+ * refs detach with their wrapped heights still cached, and falling back to
1020+ * the fixed estimate is exactly correct for nowrap rows. Entering wrap needs
1021+ * no reset — refs re-attach and re-measure as rows render.
1022+ *
1023+ * Deliberately NOT keyed on content (`visibleLines`): `measure()` wipes the
1024+ * cache without re-measuring mounted rows (ResizeObserver only fires on size
1025+ * changes; React never re-invokes an unchanged ref), so a content change that
1026+ * keeps row heights — Prism resolving its lazy load, search `<mark>`
1027+ * highlighting — would permanently collapse wrapped rows onto the rows below.
1028+ * Genuine height changes are caught by the per-row ResizeObserver.
10201029 */
10211030 useEffect ( ( ) => {
1022- virtualizer . measure ( )
1023- } , [ wrapText , visibleLines , virtualizer ] )
1031+ if ( ! wrapText ) virtualizer . measure ( )
1032+ } , [ wrapText , virtualizer ] )
10241033
10251034 useEffect ( ( ) => {
10261035 if ( ! searchQuery ?. trim ( ) || matchCount === 0 || ! scrollRef . current ) return
You can’t perform that action at this time.
0 commit comments