Skip to content

fix(angular): ensure table options updates are not missed during first mount window - #6534

Open
riccardoperra wants to merge 5 commits into
mainfrom
codex/6530-fix
Open

fix(angular): ensure table options updates are not missed during first mount window#6534
riccardoperra wants to merge 5 commits into
mainfrom
codex/6530-fix

Conversation

@riccardoperra

@riccardoperra riccardoperra commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

This pull request addresses a key issue in the @tanstack/angular-table package where options updates could be missed during the initial mount of a table. The changes ensure that option updates are reliably captured from the very first render, and also refactor the lazy initialization logic to provide more robust state tracking and improved test coverage.

Core improvements to options reactivity and initialization:

  • The injectTable function now uses a computed signal for options and ensures updates are not missed during the initial mount, fixing a bug where the first update could be dropped. This involves tracking previous options and applying updates only when they change.
  • The lazyInit utility is refactored to return an object with value, rawValue, and initialized properties, allowing for more precise control and introspection of the lazy initialization state. [1] [2] [3]

Testing and reliability improvements:

  • Additional and updated tests ensure that options updates are not dropped before the effect first runs, and that the new lazy initialization logic behaves correctly and is testable. [1] [2] [3] [4] [5]
  • Minor test and type fixes, such as correcting feature spreading and updating test assertions to match the new initialization API.

Documentation:

  • A changeset is added to document the patch release and the fix for missed options updates on first mount.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Angular Table options updates during initial rendering so the latest data and configuration are preserved.
    • Improved reactive updates to apply only when table options change.
    • Ensured table cleanup is safe when initialization has not completed.
  • Behavior Updates

    • Lazy table initialization now reports its status and provides access to the initialized value.
    • Required signal inputs can trigger initialization during rendering.
  • Release

    • Prepared a patch release for @tanstack/angular-table.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 195d3212-6fdb-4ed1-bac4-7e7fd1736f5b

📥 Commits

Reviewing files that changed from the base of the PR and between d9b772a and 4d5fd8a.

📒 Files selected for processing (1)
  • packages/angular-table/src/injectTable.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/angular-table/src/injectTable.ts

📝 Walkthrough

Walkthrough

lazyInit now uses Angular effects and exposes initialization state. injectTable now tracks computed option identity and preserves updates made before the first reactive effect. Tests cover the updated lazy and option synchronization behavior.

Changes

Angular options synchronization

Layer / File(s) Summary
Angular lazy initialization
packages/angular-table/src/lazySignalInitializer.ts, packages/angular-table/tests/lazy-init.test.ts
lazyInit now requires an Angular injection context, schedules initialization with an Angular effect, and returns value, rawValue, and initialized. Tests use TestBed.tick() and verify eager and lazy initialization behavior.
Computed option tracking
packages/angular-table/src/injectTable.ts
injectTable wraps the options factory in a computed signal. Reactive updates compare option object identity and update the table only when the object changes. Destruction unmounts only initialized tables.
Regression validation
packages/angular-table/tests/injectTable.test.ts, packages/angular-table/tests/angularReactivityFeature.test.ts, .changeset/early-tips-matter.md
The regression test verifies that pre-effect signal updates reach table.options.data. The test helper uses the shared feature object, and a patch changeset records the fix.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Mergeability Score: ⚪ Minimal · up to 4d5fd

This change improves table option updates during initial mounting and refines lazy initialization with targeted tests; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant AngularEffect
  participant injectTable
  participant Table
  AngularEffect->>injectTable: evaluate computed options
  injectTable->>Table: initialize with current options
  AngularEffect->>injectTable: detect changed option object
  injectTable->>Table: apply changed options
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary fix for missed Angular table option updates during the first mount.
Description check ✅ Passed The description explains the changes, motivation, tests, lazy initialization refactor, and changeset, but it does not use the repository template headings or checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/6530-fix

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.

@nx-cloud

nx-cloud Bot commented Aug 9, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 0844a9f

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 7m 8s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 34s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-13 10:47:16 UTC

@riccardoperra riccardoperra changed the title fix(angular): fix stale options during the effect first run fix(angular): ensure table options updates are not missed during first mount window Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

1 package(s) bumped directly, 0 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/angular-table 9.1.2 → 9.1.3 Changeset

@pkg-pr-new

pkg-pr-new Bot commented Aug 9, 2026

Copy link
Copy Markdown
More templates

@tanstack/alpine-table

npm i https://pkg.pr.new/@tanstack/alpine-table@6534

@tanstack/angular-table

npm i https://pkg.pr.new/@tanstack/angular-table@6534

@tanstack/angular-table-devtools

npm i https://pkg.pr.new/@tanstack/angular-table-devtools@6534

@tanstack/ember-table

npm i https://pkg.pr.new/@tanstack/ember-table@6534

@tanstack/lit-table

npm i https://pkg.pr.new/@tanstack/lit-table@6534

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/@tanstack/match-sorter-utils@6534

@tanstack/octane-table

npm i https://pkg.pr.new/@tanstack/octane-table@6534

@tanstack/preact-table

npm i https://pkg.pr.new/@tanstack/preact-table@6534

@tanstack/preact-table-devtools

npm i https://pkg.pr.new/@tanstack/preact-table-devtools@6534

@tanstack/react-table

npm i https://pkg.pr.new/@tanstack/react-table@6534

@tanstack/react-table-devtools

npm i https://pkg.pr.new/@tanstack/react-table-devtools@6534

@tanstack/solid-table

npm i https://pkg.pr.new/@tanstack/solid-table@6534

@tanstack/solid-table-devtools

npm i https://pkg.pr.new/@tanstack/solid-table-devtools@6534

@tanstack/svelte-table

npm i https://pkg.pr.new/@tanstack/svelte-table@6534

@tanstack/table-core

npm i https://pkg.pr.new/@tanstack/table-core@6534

@tanstack/table-devtools

npm i https://pkg.pr.new/@tanstack/table-devtools@6534

@tanstack/vue-table

npm i https://pkg.pr.new/@tanstack/vue-table@6534

@tanstack/vue-table-devtools

npm i https://pkg.pr.new/@tanstack/vue-table-devtools@6534

commit: 4d5fd8a

@riccardoperra
riccardoperra marked this pull request as ready for review August 9, 2026 09:26

@MILLERMARRU MILLERMARRU left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The mechanism here is solid. Wrapping _options in computed() is what makes the previousOptions === currentOptions reference check meaningful in the first place, calling the raw factory twice always returns two different object literals, so without the memoization the comparison would never be equal and every effect run would apply. With computed(), a real signal change is what produces a new reference, so the effect's very first run can now tell "options actually changed since I captured the initial snapshot" from "nothing changed, this is just the effect settling," instead of unconditionally skipping the first run like isMount did. Traced the timeline in #6530 and this correctly handles the specific race described there, an update that lands in the gap between construction and the effect's first flush is no longer silently dropped.

Worth being precise about scope though, since the changeset and the linked issue don't quite line up. #6530 describes two problems: the primary one is lazySignalInitializer.ts's queueMicrotask eager-init firing before Angular's input bindings are applied, throwing an uncaught NG0950 in test environments with an async beforeEach. The isMount swallow is called out as a secondary issue, one that only surfaces once you work around the first one. This PR only touches injectTable.ts, lazySignalInitializer.ts isn't part of the diff, so it fixes proposal (3) from the issue but not proposal (1). The reported symptom, the uncaught NG0950 in TestBed suites, is still there after this merges. Worth linking as "part of #6530" rather than "closes #6530", or the eager-init half is going to look resolved when it isn't.

@riccardoperra
riccardoperra marked this pull request as draft August 9, 2026 15:55
@MILLERMARRU

Copy link
Copy Markdown

Just went through the new commit, this closes the gap I mentioned earlier. queueMicrotask is gone from lazySignalInitializer.ts, so initialization now only happens through the Proxy traps, there's no more scheduled work that could race ahead of Angular applying the input bindings. Between that and the previousOptions comparison from the first commit, this now covers both halves of #6530, not just the swallowed-update part.

Traced through a few sequences by hand (options changing before the table is ever constructed, options changing right after) and the effect's if (!table) return guard combined with the reference comparison handles them correctly in all of them.

@riccardoperra
riccardoperra marked this pull request as ready for review August 13, 2026 08:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔇 Additional comments (2)
packages/angular-table/src/lazySignalInitializer.ts (1)

6-8: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

⚠️ Unverified finding
Sandbox verification was unavailable.

Declare rawValue as nullable before initialization.

The test asserts that rawValue is null before TestBed.tick(), but this API declares rawValue as T. This hides a reachable null value from consumers. injectTable currently dereferences lazyTable.rawValue, so it relies on Angular effect ordering to avoid a null dereference.

Change rawValue to T | null. Update consumers to access value only after their update guard decides that initialization is required.

Proposed fix
 ): {
-  readonly rawValue: T
+  readonly rawValue: T | null
   readonly value: T
   readonly initialized: boolean
 } {
@@
   return {
     value: proxy,
     get rawValue() {
-      return object as T
+      return object
     },
-      const tableInstance = lazyTable.rawValue
       if (previousOptions === currentOptions) return
       untracked(() =>
-        tableInstance.setOptions((previous) => ({
+        lazyTable.value.setOptions((previous) => ({
           ...previous,
           ...currentOptions,
         })),

Also applies to: 55-59

packages/angular-table/tests/lazy-init.test.ts (1)

16-36: LGTM!

Also applies to: 50-50, 70-77, 104-114


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a4f11a9a-b4eb-47dc-bbc3-adb1abeaea47

📥 Commits

Reviewing files that changed from the base of the PR and between c4bb4a5 and 8c28d35.

📒 Files selected for processing (3)
  • packages/angular-table/src/injectTable.ts
  • packages/angular-table/src/lazySignalInitializer.ts
  • packages/angular-table/tests/lazy-init.test.ts

@riccardoperra riccardoperra self-assigned this Aug 13, 2026
@riccardoperra

Copy link
Copy Markdown
Collaborator Author

@KevinVandy pr ready

Comment thread packages/angular-table/src/injectTable.ts Outdated
Comment thread packages/angular-table/src/injectTable.ts
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