Skip to content

Commit 246b62b

Browse files
committed
Remove seeing useContext as HOOKS_STATE
1 parent f6437f7 commit 246b62b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

.changeset/lucky-pears-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@preact/signals": patch
3+
---
4+
5+
Stop treating `useContext` as hook state in the auto-memoization heuristic. Context updates force-update their subscribers in Preact, bypassing `shouldComponentUpdate` entirely, so context consumers can safely keep the props-based render skipping.

packages/preact/src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,14 @@ hook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {
387387
old(vnode);
388388
});
389389

390-
/** Mark components that use hook state so we can skip sCU optimization. */
390+
/**
391+
* Mark components that use hook state so we can skip sCU optimization.
392+
* Note: useContext (type 9) is deliberately not included — context updates
393+
* force-update their subscribers, bypassing shouldComponentUpdate entirely:
394+
* https://github.com/preactjs/preact/blob/main/src/create-context.js#L24
395+
*/
391396
hook(OptionsTypes.HOOK, (old, component, index, type) => {
392-
if (type < 3 || type === 9)
397+
if (type < 3)
393398
(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;
394399
old(component, index, type);
395400
});

0 commit comments

Comments
 (0)