MCPcopy Create free account
hub / github.com/plotly/dash / updateSyncExternalStore

Function updateSyncExternalStore

dash/deps/react-dom@18.3.1.js:16045–16099  ·  view source on GitHub ↗
(subscribe, getSnapshot, getServerSnapshot)

Source from the content-addressed store, hash-verified

16043 }
16044
16045 function updateSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
16046 var fiber = currentlyRenderingFiber$1;
16047 var hook = updateWorkInProgressHook(); // Read the current snapshot from the store on every render. This breaks the
16048 // normal rules of React, and only works because store updates are
16049 // always synchronous.
16050
16051 var nextSnapshot = getSnapshot();
16052
16053 {
16054 if (!didWarnUncachedGetSnapshot) {
16055 var cachedSnapshot = getSnapshot();
16056
16057 if (!objectIs(nextSnapshot, cachedSnapshot)) {
16058 error('The result of getSnapshot should be cached to avoid an infinite loop');
16059
16060 didWarnUncachedGetSnapshot = true;
16061 }
16062 }
16063 }
16064
16065 var prevSnapshot = hook.memoizedState;
16066 var snapshotChanged = !objectIs(prevSnapshot, nextSnapshot);
16067
16068 if (snapshotChanged) {
16069 hook.memoizedState = nextSnapshot;
16070 markWorkInProgressReceivedUpdate();
16071 }
16072
16073 var inst = hook.queue;
16074 updateEffect(subscribeToStore.bind(null, fiber, inst, subscribe), [subscribe]); // Whenever getSnapshot or subscribe changes, we need to check in the
16075 // commit phase if there was an interleaved mutation. In concurrent mode
16076 // this can happen all the time, but even in synchronous mode, an earlier
16077 // effect may have mutated the store.
16078
16079 if (inst.getSnapshot !== getSnapshot || snapshotChanged || // Check if the susbcribe function changed. We can save some memory by
16080 // checking whether we scheduled a subscription effect above.
16081 workInProgressHook !== null && workInProgressHook.memoizedState.tag & HasEffect) {
16082 fiber.flags |= Passive;
16083 pushEffect(HasEffect | Passive$1, updateStoreInstance.bind(null, fiber, inst, nextSnapshot, getSnapshot), undefined, null); // Unless we're rendering a blocking lane, schedule a consistency check.
16084 // Right before committing, we will walk the tree and check if any of the
16085 // stores were mutated.
16086
16087 var root = getWorkInProgressRoot();
16088
16089 if (root === null) {
16090 throw new Error('Expected a work-in-progress root. This is a bug in React. Please file an issue.');
16091 }
16092
16093 if (!includesBlockingLane(root, renderLanes)) {
16094 pushStoreConsistencyCheck(fiber, getSnapshot, nextSnapshot);
16095 }
16096 }
16097
16098 return nextSnapshot;
16099 }
16100
16101 function pushStoreConsistencyCheck(fiber, getSnapshot, renderedSnapshot) {
16102 fiber.flags |= StoreConsistency;

Callers 1

Calls 8

updateWorkInProgressHookFunction · 0.70
errorFunction · 0.70
updateEffectFunction · 0.70
pushEffectFunction · 0.70
getWorkInProgressRootFunction · 0.70
includesBlockingLaneFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…