Skip to content
Source
Sign inSign up
TanStack/virtual

fix(angular-virtual): wrap onChange signal write in untracked to prevent NG0600 #1295

Openokxint(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1295/headopened

Fixes #1096.

onChange calls reactiveVirtualizer.set(instance) to update a linkedSignal. When a template reads virtualizer.getVirtualItems() inside a computed or effect, Angular evaluates the computed eagerly on change detection. The set() inside onChange then fires within that evaluation context, triggering NG0600: Writing to signals is not allowed in a computed or an effect.

untracked is already imported at line 11. Wrapping the set() call in untracked() escapes the reactive context and silences the error without changing behavior — the signal still updates and downstream computeds re-evaluate on the next tick.

// before
onChange: (instance, sync) => {
  reactiveVirtualizer.set(instance)
  ...
}

// after
onChange: (instance, sync) => {
  untracked(() => reactiveVirtualizer.set(instance))
  ...
}

Summary by CodeRabbit

  • Bug Fixes
    • Virtualizer change notifications no longer track surrounding reactive reads when updating reactive state, helping prevent unintended reactive updates. DOM-flush scheduling and user-provided change callbacks continue to work as before.
    1. Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Advanced

      Run ID: d800bb71-d4d2-4a0b-b37c-748206bad494

      📥 Commits

      Reviewing files that changed from the base of the PR and between 78371e851e90fd74e984deeb0c3fd8098e2cd4f3 and 562621f812d5c0692fc2be83a9b3e5eb4b5a345b.

      📒 Files selected for processing (1)
      • packages/angular-virtual/src/index.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.


      📝 Walkthrough

      Walkthrough

      The Angular virtualizer now updates reactiveVirtualizer inside untracked when its onChange callback runs. Optional DOM-flush scheduling and the user callback remain unchanged.

      Changes

      Angular signal update

      Layer / File(s)Summary
      Untracked virtualizer signal update
      packages/angular-virtual/src/index.ts
      The onChange callback wraps the reactiveVirtualizer.set(instance) update in untracked. The remaining callback behavior is unchanged.

      Priority: ➖ Normal

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

      Change: Bug fix · Severity of issue fixed: Medium

      Merge Risk: ⚪ Minimal · up to 56262

      The update avoids the reported Angular error while continuing to notify signal consumers. No actionable merge risk remains.

      Architecture Summary

      Architecture risk: 🔵 Low · up to 56262

      The change affects 1 system.

      Changed systems: packages/angular-virtual

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — packages/angular-virtual (library) was modified; 1 changed file maps to changed impact.

      Before / after behavior

      • observed — Modified behavior in packages/angular-virtual/src/index.ts: The reactiveVirtualizer.set(instance) update is now wrapped in untracked; the remaining onChange behavior is unchanged.
      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly identifies the Angular virtualizer fix, the affected callback, and the purpose of preventing NG0600. It is concise and directly related to the main change.
      Description check✅ PassedThe description clearly explains the change, motivation, affected signal behavior, and expected outcome. It omits the template’s Checklist and Release Impact sections, but it provides the core informa…
      Linked Issues check✅ PassedIssue #1096 requires Angular code to prevent NG0600 when getVirtualItems() evaluation triggers onChange. In packages/angular-virtual/src/index.ts, onChange now calls `untracked(() => reactiveV…
      Out of Scope Changes check✅ PassedThe reviewed change is limited to the reactiveVirtualizer.set(instance) call in Angular virtualizer onChange. The change directly addresses issue #1096 and does not show unrelated behavior or file…
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Autopilot is currently an internal CodeRabbit preview.


      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. piecyk reviewed

      Thanks for the PR!

      #1096 was reported against 4.0.1, where getVirtualItems() → getMeasurements → notify wrote to the signal from inside a computed. Since then #1158 reworked the adapter, and on current main reading getVirtualItems() / getTotalSize() no longer triggers notify. The remaining notify paths (maybeNotify from the scroll/rect observers, resizeItem/measureElement, measure()) run from afterRenderEffect or event callbacks. @tanstack/angular-virtual requires @angular/core >=20, and signal writes inside effects have been allowed since Angular 19, so those are legal.

      Could you share a minimal repro (StackBlitz or a failing test in packages/angular-virtual/tests) showing NG0600 on the current version?

      If one exists, I'd rather fix the write-during-read at its source than mask it with untracked. Writing to reactiveVirtualizer while a computed that depends on it is evaluating only settles today because the memo hits on the second pass, and it can cause extra change-detection passes (NG0100/NG0103) instead of a clear error.

      A changeset would also be needed, since this touches published code.

Sign in to join this conversation.