Uh oh!
There was an error while loading. Please reload this page.
feat(react-virtual): add directDomUpdates for re-render-free scroll positioning - #1180
Conversation
…ositioning Adds opt-in `directDomUpdates` to `useVirtualizer` / `useWindowVirtualizer`. When enabled, item positions (top/left or transform) and container size (height/width) are written directly to the DOM on every onChange, and React only re-renders on range or isScrolling changes. - New `directDomUpdatesMode: 'position' | 'transform'` to pick strategy - New `virtualizer.containerRef` for the inner sized element
Caution Review failedPull request was closed or merged during review 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 (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds opt-in directDomUpdates to apply virtualized container sizing and per-item positioning directly to the DOM, minimizing React re-renders. Exposes containerRef, updates hooks/types, updates an example, and adds an E2E app plus Playwright tests for "position" and "transform" modes. ChangesDirect DOM Updates
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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 0a6f4b0
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/react-virtual/e2e/app/direct-dom-updates/main.tsx`:
- Around line 11-13: The page currently sets mode via const params = new
URLSearchParams(window.location.search) and const mode = (params.get('mode') ??
'position') as 'position' | 'transform'; but the hook default is now
'transform', so change the fallback from 'position' to 'transform' (i.e., use
(params.get('mode') ?? 'transform')), ensuring the unparameterized route matches
the hook's directDomUpdatesMode default.
In `@packages/react-virtual/e2e/app/test/direct-dom-updates.spec.ts`:
- Around line 50-51: Replace the fixed sleep call page.waitForTimeout(50) with a
web-first Playwright assertion that waits for the DOM style on the locator
'[data-testid="item-1"]' to reflect the expected move; use
page.locator('[data-testid="item-1"]') and an
expect(...).toHaveAttribute('style', ...) that checks for the correct style
depending on the test's mode variable (match /top:\s*40px/ when mode ===
'position' else match /translate3d\(0px,\s*40px,\s*0px\)/) so Playwright
auto-retries instead of using a hard timeout.
In `@packages/react-virtual/src/index.tsx`:
- Around line 42-65: Update the JSDoc for the new direct DOM updates API to
match the implementation: change the default mode in the docs to 'transform'
(not 'position') and explicitly state that even in 'transform' mode items must
still be anchored with position: absolute and top: 0 / left: 0 (the virtualizer
then applies translate3d), and also clarify that 'position' mode writes
top/left; update the comment block around the directDomUpdates and
directDomUpdatesMode references so consumers of directDomUpdates and
directDomUpdatesMode configure items correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7ccd0d7a-edf7-4e4e-87b9-4f1b21f0b592
📒 Files selected for processing (6)
examples/react/dynamic/src/main.tsxpackages/react-virtual/e2e/app/direct-dom-updates/index.htmlpackages/react-virtual/e2e/app/direct-dom-updates/main.tsxpackages/react-virtual/e2e/app/test/direct-dom-updates.spec.tspackages/react-virtual/e2e/app/vite.config.tspackages/react-virtual/src/index.tsx
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Adds opt-in
directDomUpdatestouseVirtualizer/useWindowVirtualizer. When enabled, item positions (top/left or transform) and container size (height/width) are written directly to the DOM on every onChange, and React only re-renders on range or isScrolling changes.directDomUpdatesMode: 'position' | 'transform'to pick strategyvirtualizer.containerReffor the inner sized element🎯 Changes
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
Tests
Chores