Skip to content

fix(virtual-core): drop rows that a render detaches in a scroll element delivery - #1413

Open
clean99 wants to merge 1 commit into
TanStack:mainfrom
clean99:contrib/scroll-rect-detached-rows
Open

clean99 wants to merge 1 commit into
TanStack:mainfrom
clean99:contrib/scroll-rect-detached-rows

Conversation

@clean99

@clean99 clean99 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

A Solid list that measures its rows logs "ResizeObserver loop completed with undelivered notifications." each time its scroll element gets shorter and rows leave the range. The scroll element's rect callback now drops detached rows after it notifies, as the row observer does.

  • Problem: Solid removes the rows inside the scroll element's ResizeObserver delivery and never calls a ref with null. fix(core): avoid observer loop errors when resize renders change rows #1348 drops detached rows in the row observer and fix(virtual-core): drop rows that a render detaches after their ref callback #1412 in measureElement(null), so on this path nothing unobserves them before the browser gathers observations again. Nothing visible breaks; the error reaches window.onerror on every shrink.
  • Change: the rect callback calls this.measureElement(null) after maybeNotify(). It skips the synchronous first read in _willUpdate, which is not a delivery, so a row that is cached before it is attached stays observed.
  • Verification: pnpm --filter @tanstack/virtual-core exec vitest run tests/measurement.test.ts. One new case renders inside onChange without a null ref and fails without the change; another covers the first read. In Chromium 159 the page below logs the error in 5 of 5 runs with the published packages and in 0 of 5 with @tanstack/virtual-core built from this branch.
  • Not tested: the Marko and Angular wirings in the docs also never pass null to the ref. The error was not reproduced there, and there is no Solid e2e app to add a browser case to.

Related: #1345, #1348, #1412.

Reproduction, with solid-js 1.9.9 and @tanstack/solid-virtual 3.13.57 (@tanstack/virtual-core 3.19.15). The rows set their index in the ref callback and measure after it, the forms given in #930:

  1. Open the page below.
  2. Run document.documentElement.style.setProperty('--viewport', '300px') in the console.
  3. The page logs the message above. With this change, it logs nothing.
Page
<!doctype html>
<style>
  :root {
    --viewport: 600px;
  }
  #parent {
    height: var(--viewport);
    overflow: auto;
  }
</style>
<div id="app"></div>
<script type="importmap">
  {
    "imports": {
      "solid-js": "https://esm.sh/solid-js@1.9.9",
      "solid-js/store": "https://esm.sh/solid-js@1.9.9/store",
      "solid-js/web": "https://esm.sh/solid-js@1.9.9/web",
      "@tanstack/virtual-core": "https://esm.sh/@tanstack/virtual-core@3.19.15"
    }
  }
</script>
<script type="module">
  import { For, createComponent } from 'solid-js'
  import { insert, render } from 'solid-js/web'
  import { createVirtualizer } from 'https://esm.sh/*@tanstack/solid-virtual@3.13.57'

  addEventListener('error', (event) => console.log(event.message))

  render(() => {
    const parent = document.createElement('div')
    parent.id = 'parent'
    const inner = document.createElement('div')
    inner.style.position = 'relative'
    parent.append(inner)
    const virtualizer = createVirtualizer({
      count: 200,
      getScrollElement: () => parent,
      estimateSize: () => 32,
    })
    insert(inner, () => {
      inner.style.height = `${virtualizer.getTotalSize()}px`
    })
    insert(
      inner,
      createComponent(For, {
        get each() {
          return virtualizer.getVirtualItems()
        },
        children: (row) => {
          const el = document.createElement('div')
          el.dataset.index = row.index
          el.style.cssText = `position:absolute;top:0;width:100%;height:32px;transform:translateY(${row.start}px)`
          el.textContent = `Row ${row.index}`
          queueMicrotask(() => virtualizer.measureElement(el))
          return el
        },
      }),
    )
    return parent
  }, document.getElementById('app'))
</script>

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a ResizeObserver loop error that could occur when rows were removed during observer delivery. Detached rows are now unobserved before the next browser delivery.
    • Rows that are not yet connected during the initial scroll-element read remain observed.

@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e562e14

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@tanstack/virtual-core Patch
@tanstack/angular-virtual Patch
@tanstack/lit-virtual Patch
@tanstack/marko-virtual Patch
@tanstack/react-virtual Patch
@tanstack/solid-virtual Patch
@tanstack/svelte-virtual Patch
@tanstack/vue-virtual Patch
@tanstack/virtual-benchmarks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The scroll rectangle observer now calls measureElement(null) after subsequent rectangle notifications. Tests cover detached rows after synchronous renders and rows measured before the virtualizer’s initial update. A changeset declares a patch release.

Changes: Scroll rectangle cleanup

Layer / File(s) Summary
Clean up detached rows after rectangle notifications
packages/virtual-core/src/index.ts, packages/virtual-core/tests/measurement.test.ts, .changeset/calm-scroll-rect-rows.md
Subsequent rectangle observer callbacks call measureElement(null) after updating scrollRect and notifying. Tests cover synchronous renders, detached-row observation, and retaining a row measured before the initial update. A changeset declares a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • TanStack/virtual#1412: Addresses overlapping detached-row cleanup during ResizeObserver delivery, using a microtask for row observers.

Suggested reviewers: jrandolf, piecyk

Merge Risk: Minimal · up to e562e

This patch fixes a ResizeObserver error logged when a framework removes rows during scroll-element resize delivery. The change is small, tested, and reversible. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (dropping rows that a render detaches during a scroll element ResizeObserver delivery) in the virtual-core package. The change adds a measureElement(null) call after maybeNotif…
Description check Passed The description follows the template. It has a Changes section that states the problem, the change, and how it was verified, with a reproduction page. The checklist is ticked, and the release impact s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix (dropping rows that a render detaches during a scroll element ResizeObserver delivery) in the virtual-core package. The change adds a measureElement(null) call after maybeNotify() in the scroll-element rect callback, and the tests cover this path. The title matches the main change.

Full details: Description check

Explanation

The description follows the template. It has a Changes section that states the problem, the change, and how it was verified, with a reproduction page. The checklist is ticked, and the release impact section says a changeset was generated, which matches the added .changeset file. The description does not address the template's checkbox for docs/CI-only changes, but that box is correctly left unchecked.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/virtual-core/tests/measurement.test.ts

Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): packages/virtual-core/tests/measurement.test.ts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a45ab12d-85fd-419f-ae99-b60e6d96bde5
Commits

Reviewing files that changed from the base of the PR and between 9b52543 and e562e14.

Files selected for processing: 3

  • .changeset/calm-scroll-rect-rows.md
  • packages/virtual-core/src/index.ts
  • packages/virtual-core/tests/measurement.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@piecyk piecyk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @clean99! Checked it locally at e562e14, all core tests pass. Both new tests fail when I revert their half of the fix (main's src for the sync-render case, dropping the observing guard for the first-read case), so they pin it nicely.

LGTM once CI is green 🚀

@nx-cloud

nx-cloud Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e562e14

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 46s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 22s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-30 09:28:15 UTC

This branch has not been deployed

No deployments
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.

2 participants