fix(core): prevent React Query double fetching by lazy signal access#7439
Closed
SpencerJung wants to merge 1 commit into
Closed
fix(core): prevent React Query double fetching by lazy signal access#7439SpencerJung wants to merge 1 commit into
SpencerJung wants to merge 1 commit into
Conversation
In React 18 Strict Mode, spreading prepareQueryContext(context) inside queryFn invokes the signal getter, causing React Query to treat the query as abortable and issue a second fetch after cancellation. This fix avoids spreading the object with the signal getter and instead defines the lazy getter directly on the meta object, matching v4 behavior. Affected hooks: useList, useOne, useMany, useCustom, useInfiniteList Closes refinedev#7132
|
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.
fix(core): prevent React Query double fetching by lazy signal access
Description
Refine v5's
useListand other data hooks perform two HTTP requests in React 18 + Strict Mode in development, while refine v4 performed only one.Root Cause
Spreading
prepareQueryContext(context)insidequeryFninvokes thesignalgetter, causing React Query to detect thatsignalis used. Whensignalis used, React Query treats the query as abortable, and in dev + Strict Mode it cancels the first run and issues a second fetch.Fix
Avoid spreading the object with the
signalgetter and instead define the lazy getter directly on themetaobject, matching v4 behavior.Changed
packages/core/src/hooks/data/useList.tspackages/core/src/hooks/data/useOne.tspackages/core/src/hooks/data/useMany.tspackages/core/src/hooks/data/useCustom.tspackages/core/src/hooks/data/useInfiniteList.tsVerification
Before fix: 2 network requests in Strict Mode dev
After fix: 1 network request in Strict Mode dev
Related Issue
Closes #7132