Skip to content

Commit 168f118

Browse files
committed
FAILING Fork mount impl as well
1 parent 68da82a commit 168f118

File tree

2 files changed

+70
-32
lines changed

2 files changed

+70
-32
lines changed

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,13 +1501,13 @@ function updateMutableSource<Source, Snapshot>(
15011501
return useMutableSource(hook, source, getSnapshot, subscribe);
15021502
}
15031503

1504-
function mountSyncExternalStore<T>(
1504+
function mountSyncExternalStoreImpl<T>(
1505+
hook: Hook,
15051506
subscribe: (() => void) => () => void,
15061507
getSnapshot: () => T,
15071508
getServerSnapshot?: () => T,
15081509
): T {
15091510
const fiber = currentlyRenderingFiber;
1510-
const hook = mountWorkInProgressHook();
15111511

15121512
let nextSnapshot;
15131513
const isHydrating = getIsHydrating();
@@ -1593,6 +1593,20 @@ function mountSyncExternalStore<T>(
15931593
return nextSnapshot;
15941594
}
15951595

1596+
function mountSyncExternalStore<T>(
1597+
subscribe: (() => void) => () => void,
1598+
getSnapshot: () => T,
1599+
getServerSnapshot?: () => T,
1600+
): T {
1601+
const hook = mountWorkInProgressHook();
1602+
return mountSyncExternalStoreImpl(
1603+
hook,
1604+
subscribe,
1605+
getSnapshot,
1606+
getServerSnapshot,
1607+
);
1608+
}
1609+
15961610
function updateSyncExternalStoreImpl<T>(
15971611
hook: Hook,
15981612
prevSnapshot: T,
@@ -1688,20 +1702,25 @@ function rerenderSyncExternalStore<T>(
16881702
getServerSnapshot?: () => T,
16891703
): T {
16901704
const hook = updateWorkInProgressHook();
1691-
const prevSnapshot =
1692-
currentHook === null
1693-
? // This is a rerender during a mount.
1694-
hook.memoizedState
1695-
: // This is a rerender during an update.
1696-
currentHook.memoizedState;
1697-
1698-
return updateSyncExternalStoreImpl(
1699-
hook,
1700-
prevSnapshot,
1701-
subscribe,
1702-
getSnapshot,
1703-
getServerSnapshot,
1704-
);
1705+
if (currentHook === null) {
1706+
// This is a rerender during a mount.
1707+
return mountSyncExternalStoreImpl(
1708+
hook,
1709+
subscribe,
1710+
getSnapshot,
1711+
getServerSnapshot,
1712+
);
1713+
} else {
1714+
// This is a rerender during an update.
1715+
const prevSnapshot: T = currentHook.memoizedState;
1716+
return updateSyncExternalStoreImpl(
1717+
hook,
1718+
prevSnapshot,
1719+
subscribe,
1720+
getSnapshot,
1721+
getServerSnapshot,
1722+
);
1723+
}
17051724
}
17061725

17071726
function pushStoreConsistencyCheck<T>(

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,13 +1501,13 @@ function updateMutableSource<Source, Snapshot>(
15011501
return useMutableSource(hook, source, getSnapshot, subscribe);
15021502
}
15031503

1504-
function mountSyncExternalStore<T>(
1504+
function mountSyncExternalStoreImpl<T>(
1505+
hook: Hook,
15051506
subscribe: (() => void) => () => void,
15061507
getSnapshot: () => T,
15071508
getServerSnapshot?: () => T,
15081509
): T {
15091510
const fiber = currentlyRenderingFiber;
1510-
const hook = mountWorkInProgressHook();
15111511

15121512
let nextSnapshot;
15131513
const isHydrating = getIsHydrating();
@@ -1593,6 +1593,20 @@ function mountSyncExternalStore<T>(
15931593
return nextSnapshot;
15941594
}
15951595

1596+
function mountSyncExternalStore<T>(
1597+
subscribe: (() => void) => () => void,
1598+
getSnapshot: () => T,
1599+
getServerSnapshot?: () => T,
1600+
): T {
1601+
const hook = mountWorkInProgressHook();
1602+
return mountSyncExternalStoreImpl(
1603+
hook,
1604+
subscribe,
1605+
getSnapshot,
1606+
getServerSnapshot,
1607+
);
1608+
}
1609+
15961610
function updateSyncExternalStoreImpl<T>(
15971611
hook: Hook,
15981612
prevSnapshot: T,
@@ -1688,20 +1702,25 @@ function rerenderSyncExternalStore<T>(
16881702
getServerSnapshot?: () => T,
16891703
): T {
16901704
const hook = updateWorkInProgressHook();
1691-
const prevSnapshot =
1692-
currentHook === null
1693-
? // This is a rerender during a mount.
1694-
hook.memoizedState
1695-
: // This is a rerender during an update.
1696-
currentHook.memoizedState;
1697-
1698-
return updateSyncExternalStoreImpl(
1699-
hook,
1700-
prevSnapshot,
1701-
subscribe,
1702-
getSnapshot,
1703-
getServerSnapshot,
1704-
);
1705+
if (currentHook === null) {
1706+
// This is a rerender during a mount.
1707+
return mountSyncExternalStoreImpl(
1708+
hook,
1709+
subscribe,
1710+
getSnapshot,
1711+
getServerSnapshot,
1712+
);
1713+
} else {
1714+
// This is a rerender during an update.
1715+
const prevSnapshot: T = currentHook.memoizedState;
1716+
return updateSyncExternalStoreImpl(
1717+
hook,
1718+
prevSnapshot,
1719+
subscribe,
1720+
getSnapshot,
1721+
getServerSnapshot,
1722+
);
1723+
}
17051724
}
17061725

17071726
function pushStoreConsistencyCheck<T>(

0 commit comments

Comments
 (0)