fix(query-core): ignore a retained thenable callback invoked after settling - #11128
Open
sobol-sudo wants to merge 3 commits into
Open
fix(query-core): ignore a retained thenable callback invoked after settling#11128sobol-sudo wants to merge 3 commits into
sobol-sudo wants to merge 3 commits into
Conversation
Contributor
📝 WalkthroughWalkthroughUpdates ChangesThenable settlement protection and validation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/query-core/src/__tests__/thenable.test.tsx`:
- Around line 39-46: Update the test around pendingThenable to retain the reject
callback before calling resolve, invoke that stale callback afterward, and
assert the thenable still resolves with the original value. Then update the
settlement/finalization logic in pendingThenable so callbacks captured before
finalization cannot mutate status or reason, and repeated finalization remains
idempotent.
🪄 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 Plus
Run ID: 3f538398-6e28-4e86-b535-72a8fb454acd
📒 Files selected for processing (1)
packages/query-core/src/__tests__/thenable.test.tsx
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.
thenable.tsis used byhydration,retryerandqueryObserver, but it has no test file of its own, so its behaviour is only covered indirectly. This adds a unit suite for both exports, and fixes a defect the suite surfaced.Fix
pendingThenabledeletesresolve/rejecton settle, with the comment that this avoids calling them twice. A caller that kept a reference to one of them beforehand bypasses that guard, andfinalizethen applies to an already settled promise:The underlying promise correctly ignores the late call, so only the advertised state was wrong. That matters because React reads
.status/.value/.reasonto unwrap promises optimistically, so a thenable claimingrejectedwhile actually fulfilled can surface an error that never happened.finalizenow returns early once the thenable is no longer pending.Tests
pendingThenable— starts outpendingwithresolve/rejectattached; exposesvalue/reasonand drops the pending props once settled; ignores a retained callback invoked after settling; does not surface an unhandled rejection when nobody awaits it.tryResolveSync— returnsundefinedfor a native promise, including an already resolved one, sincethenalways defers to a microtask; returns the data for a thenable that calls back synchronously; supports a synchronous thenable whosethen()returns something without acatchmethod, which is the case the?.catchguard exists for; returnsundefinedwhen a synchronous thenable resolves withundefined; returnsundefinedfor a rejected promise without leaving the rejection unhandled.The retained-callback test fails on
mainwithexpected 'rejected' to be 'fulfilled'and passes with the change. Locallyquery-coreis 565 passed / 25 files, no type errors, ESLint clean.Patch changeset included since this changes published behaviour.
Summary by CodeRabbit