Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/recoil/core/Recoil_RecoilRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type InternalProps = {
initializeState?: MutableSnapshot => void,
store_INTERNAL?: Store,
children: React.Node,
skipCircularDependencyDetection_DANGEROUS?: boolean,
};

function notInAContext() {
Expand Down Expand Up @@ -365,6 +366,7 @@ function RecoilRoot_INTERNAL({
initializeState,
store_INTERNAL: storeProp, // For use with React "context bridging"
children,
skipCircularDependencyDetection_DANGEROUS,
}: InternalProps): React.Node {
// prettier-ignore
// @fb-only: useEffect(() => {
Expand Down Expand Up @@ -486,6 +488,7 @@ function RecoilRoot_INTERNAL({
getGraph,
subscribeToTransactions,
addTransactionMetadata,
skipCircularDependencyDetection_DANGEROUS,
},
);
if (storeProp != null) {
Expand Down Expand Up @@ -550,6 +553,7 @@ type Props =
store_INTERNAL?: Store,
override?: true,
children: React.Node,
skipCircularDependencyDetection_DANGEROUS?: boolean,
}
| {
store_INTERNAL?: Store,
Expand All @@ -562,6 +566,7 @@ type Props =
*/
override: false,
children: React.Node,
skipCircularDependencyDetection_DANGEROUS?: boolean,
};

function RecoilRoot(props: Props): React.Node {
Expand Down
1 change: 1 addition & 0 deletions packages/recoil/core/Recoil_State.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type Store = $ReadOnly<{
getGraph: StateID => Graph,
subscribeToTransactions: ((Store) => void, ?NodeKey) => {release: () => void},
addTransactionMetadata: ({...}) => void,
skipCircularDependencyDetection_DANGEROUS?: boolean,
}>;

export type StoreRef = {
Expand Down
3 changes: 3 additions & 0 deletions packages/recoil/recoil_values/Recoil_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ function selector<T>(
}

function selectorGet(store: Store, state: TreeState): Loadable<T> {
if (store.skipCircularDependencyDetection_DANGEROUS === true) {
return getSelectorLoadableAndUpdateDeps(store, state);
}
return detectCircularDependencies(() =>
getSelectorLoadableAndUpdateDeps(store, state),
);
Expand Down