Skip to content

Commit

Permalink
FAILING Fork mount impl as well
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Nov 9, 2022
1 parent 68da82a commit 168f118
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 32 deletions.
51 changes: 35 additions & 16 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,13 +1501,13 @@ function updateMutableSource<Source, Snapshot>(
return useMutableSource(hook, source, getSnapshot, subscribe);
}

function mountSyncExternalStore<T>(
function mountSyncExternalStoreImpl<T>(
hook: Hook,
subscribe: (() => void) => () => void,
getSnapshot: () => T,
getServerSnapshot?: () => T,
): T {
const fiber = currentlyRenderingFiber;
const hook = mountWorkInProgressHook();

let nextSnapshot;
const isHydrating = getIsHydrating();
Expand Down Expand Up @@ -1593,6 +1593,20 @@ function mountSyncExternalStore<T>(
return nextSnapshot;
}

function mountSyncExternalStore<T>(
subscribe: (() => void) => () => void,
getSnapshot: () => T,
getServerSnapshot?: () => T,
): T {
const hook = mountWorkInProgressHook();
return mountSyncExternalStoreImpl(
hook,
subscribe,
getSnapshot,
getServerSnapshot,
);
}

function updateSyncExternalStoreImpl<T>(
hook: Hook,
prevSnapshot: T,
Expand Down Expand Up @@ -1688,20 +1702,25 @@ function rerenderSyncExternalStore<T>(
getServerSnapshot?: () => T,
): T {
const hook = updateWorkInProgressHook();
const prevSnapshot =
currentHook === null
? // This is a rerender during a mount.
hook.memoizedState
: // This is a rerender during an update.
currentHook.memoizedState;

return updateSyncExternalStoreImpl(
hook,
prevSnapshot,
subscribe,
getSnapshot,
getServerSnapshot,
);
if (currentHook === null) {
// This is a rerender during a mount.
return mountSyncExternalStoreImpl(
hook,
subscribe,
getSnapshot,
getServerSnapshot,
);
} else {
// This is a rerender during an update.
const prevSnapshot: T = currentHook.memoizedState;
return updateSyncExternalStoreImpl(
hook,
prevSnapshot,
subscribe,
getSnapshot,
getServerSnapshot,
);
}
}

function pushStoreConsistencyCheck<T>(
Expand Down
51 changes: 35 additions & 16 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,13 +1501,13 @@ function updateMutableSource<Source, Snapshot>(
return useMutableSource(hook, source, getSnapshot, subscribe);
}

function mountSyncExternalStore<T>(
function mountSyncExternalStoreImpl<T>(
hook: Hook,
subscribe: (() => void) => () => void,
getSnapshot: () => T,
getServerSnapshot?: () => T,
): T {
const fiber = currentlyRenderingFiber;
const hook = mountWorkInProgressHook();

let nextSnapshot;
const isHydrating = getIsHydrating();
Expand Down Expand Up @@ -1593,6 +1593,20 @@ function mountSyncExternalStore<T>(
return nextSnapshot;
}

function mountSyncExternalStore<T>(
subscribe: (() => void) => () => void,
getSnapshot: () => T,
getServerSnapshot?: () => T,
): T {
const hook = mountWorkInProgressHook();
return mountSyncExternalStoreImpl(
hook,
subscribe,
getSnapshot,
getServerSnapshot,
);
}

function updateSyncExternalStoreImpl<T>(
hook: Hook,
prevSnapshot: T,
Expand Down Expand Up @@ -1688,20 +1702,25 @@ function rerenderSyncExternalStore<T>(
getServerSnapshot?: () => T,
): T {
const hook = updateWorkInProgressHook();
const prevSnapshot =
currentHook === null
? // This is a rerender during a mount.
hook.memoizedState
: // This is a rerender during an update.
currentHook.memoizedState;

return updateSyncExternalStoreImpl(
hook,
prevSnapshot,
subscribe,
getSnapshot,
getServerSnapshot,
);
if (currentHook === null) {
// This is a rerender during a mount.
return mountSyncExternalStoreImpl(
hook,
subscribe,
getSnapshot,
getServerSnapshot,
);
} else {
// This is a rerender during an update.
const prevSnapshot: T = currentHook.memoizedState;
return updateSyncExternalStoreImpl(
hook,
prevSnapshot,
subscribe,
getSnapshot,
getServerSnapshot,
);
}
}

function pushStoreConsistencyCheck<T>(
Expand Down

0 comments on commit 168f118

Please sign in to comment.