This repository was archived by the owner on Jan 1, 2025. It is now read-only.
Add flag to skip circular dependency detection #2214
Merged
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.
Summary:
I discovered a bug in
detectCircularDependencies()
where it may erroneously detect a circular dependency whengraphQLQueryEffect()
is used. It arises from the fact that we are using a global stack to keep track of which Atom/Selectors have been visited.From the stack trace, I think I've figured out what is happening...
selectorGet()
calls to load dependencies.detectCircularDependencies()
several times and a bunch of keys get added to thedependencyStack
, as you would expect. So far, everything looks good.graphQLQueryEffect()
.graphQLQueryEffect()
subscribes to aRelayObservable
.The act of subscribing schedules a task using theRelayFBScheduler
.flushSyncCallbacks()
in ReactDOM.renderWithHooks()
in ReactDOM.useRecoilValue()
.detectCircularDependencies()
, which is where we fail because thedependencyStack
already includes the keys of all those previous Selectors and Atoms up to and including the Atom with thegraphQLQueryEffect()
.This change adds a flag prop named
skipCircularDependencyDetection_DANGEROUS
to<RecoilRoot>
, which is propagated down to theStore
. If this flag is set totrue
thendetectCircularDependencies()
is bypassed.This is obviously less than ideal. I think we can all agree that a fix for
detectCircularDependencies()
would be a much better solution. I am under the impression that, that will be a major refactor though, since it will require changingdependencyStack
to be non-global and passing it all around. This flag will at least mitigate the bug until a more proper solution can be implemented. It should be very easy to back it out once that happens.Differential Revision: D44563103