feat(virtual-core): skip sync DOM read in measureElement when cached size exists#1183
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Virtualizer exposes its element size cache publicly and updates measureElement to return cached sizes during synchronous measurement calls instead of immediately performing offsetWidth/offsetHeight reads. ChangesMeasurement Cache Optimization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit 3c51175
☁️ Nx Cloud last updated this comment at |
b1f6f19 to
3c51175
Compare
This PR skip synchronous DOM reads (
offsetWidth/offsetHeight) in the defaultmeasureElementwhen a cached size already exists.Reading
offsetWidth/offsetHeightforces browser layout reflow. On re-renders, this is redundant, theResizeObserveris already watching the element and will fire if the size changes.🎯 Changes
This PR skips the sync DOM read when the item already has a measured size in
itemSizeCache, returning the cached value instead. TheResizeObserveris already observing the element and will deliver an accurate size asynchronously if it changed. First mount still does the sync read since no cache exists yet.itemSizeCacheis made public so the standalonemeasureElementfunction can access it (same pattern as the existing publicelementsCache). Users who need sync DOM reads on every render can pass a custommeasureElement.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit