Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks 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 c330408
☁️ Nx Cloud last updated this comment at |
@tanstack/angular-store
@tanstack/lit-store
@tanstack/octane-store
@tanstack/preact-store
@tanstack/react-store
@tanstack/solid-store
@tanstack/store
@tanstack/svelte-store
@tanstack/vue-store
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
this is fully ai authored, and it adds +250 gzip bytes
🎯 Changes
Reading a computed atom with
.get()currently leaves references from its sources, keeping the computed alive even when it has no subscribers. This change detaches those subscriber links while retaining the computed's dependency links for cache validation and reuse. Subscribing reconnects the retained links, preserving unchanged cached snapshots.Adds regression coverage for dependency chains, conditional dependencies, custom comparisons, subscription transitions, getter failures, reentrant writes, and async completion, plus a patch changeset.
Fixes #372.
Further performance optimization is deferred until benchmark coverage is available; this PR contains no benchmark infrastructure or reactive-engine rewrite.
How dependency tracking changes
Both directions of tracking already exist on
main. Forderived = createAtom(() => source.get() + 1), evaluating the getter creates a singleLinkobject that belongs to two lists:source.subslists the computations that depend onsource, so writes can notify them.derived.depslists the sources thatderiveddepends on, so its dependencies can be tracked and cleaned up.These are two views of the same link, not two different kinds of link introduced by this PR:
Today, a bare
derived.get()leaves that link in both lists. As long assourceis reachable,source.subskeeps the link—and thereforederived—reachable too. Dropping the application's reference toderivedis not enough to collect it.The subscription/unsubscription workaround removes the link from both lists when the last subscriber leaves. That releases
derived, but also discards its dependency information and marks it dirty.This PR separates removing the reverse reference from discarding the dependency information:
mainget()derived.depsderived.depsThe computed can still reach its sources, but its sources no longer keep it alive. If application code retains
derived, later reads can validate its cached dependencies. If application code drops it, the garbage collector can collect it and its retained links. NoFinalizationRegistryis needed: detachment happens when there are no subscribers, rather than waiting to detect that the computed has become unreachable.Validation
pnpm test:pr: 299 runtime tests passed, one skipped. Type checks, lint, dependency checks, library builds, and package validation passed.git diff --check.✅ Checklist
pnpm test:pr(results and limitations above).🚀 Release Impact