fix(core): do not reject promise right away - only when `promise` gets used #9576
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: query-core
- @@ -272,3 +267,12 @@272267 get: (target, key) => {273268 this.trackProp(key as keyof QueryObserverResult)274269 onPropTracked?.(key as keyof QueryObserverResult)270+ console.log('tracking prop', key)271+ if (key === 'promise' && !this.options.experimental_prefetchInRender) {272+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition273+ ;(this.#currentThenable as PendingThenable<TData>).reject?.(274+ new Error(275+ 'experimental_prefetchInRender feature flag is not enabled',276+ ),277+ )278+ }
TkDodo reviewed
@@ -272,3 +267,4 @@272267 get: (target, key) => {273268 this.trackProp(key as keyof QueryObserverResult)274269 onPropTracked?.(key as keyof QueryObserverResult)270+ console.log('tracking prop', key)TkDodo reviewed
@@ -272,3 +267,10 @@272267 get: (target, key) => {273268 this.trackProp(key as keyof QueryObserverResult)274269 onPropTracked?.(key as keyof QueryObserverResult)270+ if (key === 'promise' && !this.options.experimental_prefetchInRender) {271+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition272+ ;(this.#currentThenable as PendingThenable<TData>).reject?.(273+ new Error(274+ 'experimental_prefetchInRender feature flag is not enabled',275+ ),276+ )TkDodo merged thisabab082
TkDodo closed this
Sign in to join this conversation.
Walkthrough#
The change defers rejection of the observer's initial thenable until the tracked result's
promiseproperty is accessed. Withexperimental_prefetchInRenderdisabled the thenable is created pending and only rejected lazily onpromiseaccess; behavior unchanged when the flag is enabled.Changes#
packages/query-core/src/queryObserver.ts#currentThenableas pending whenexperimental_prefetchInRenderis disabled; remove eager rejection in constructor; add a Proxy getter that rejects the pending thenable lazily when thepromiseproperty is accessed (uses optional chaining forreject). No public API changes.Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Assessment against linked issues#
Poem#
Tip
🔌 Remote MCP (Model Context Protocol) integration is now available!
Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between b507746b04ec93ebefddce1834bd7c2ded807cc8 and 4a51a5452d40e0340fc07dc42ac7cc2362775967.
📒 Files selected for processing (1)
packages/query-core/src/queryObserver.ts(1 hunks)⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (2)
✨ Finishing Touches
🧪 Generate unit tests
🪧 Tips
Chat#
There are 3 ways to chat with CodeRabbit:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.@coderabbitaiin a new review comment at the desired location with your query.@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.Support#
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)#
Type
@coderabbitai helpto get the list of available commands.Other keywords and placeholders#
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed.@coderabbitai summaryto generate the high-level summary at a specific location in the PR description.@coderabbitaianywhere in the PR title to generate the title automatically.CodeRabbit Configuration File (
.coderabbit.yaml)#.coderabbit.yamlfile to the root of your repository.# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.jsonStatus, Documentation and Community#