Skip to content

Commit

Permalink
Update src/constants.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Dec 2, 2024
1 parent 667a39b commit 3525847
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions hooks/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { options as _options } from 'preact';
import { SKIP_CHILDREN } from 'preact/src/constants';
import { SKIP_CHILDREN } from '../../src/constants';

/** @type {number} */
let currentIndex;
Expand All @@ -25,6 +25,7 @@ let oldAfterDiff = options.diffed;
let oldCommit = options._commit;
let oldBeforeUnmount = options.unmount;
let oldRoot = options._root;
let oldAfterRender = options._afterRender;

const RAF_TIMEOUT = 100;
let prevRaf;
Expand Down Expand Up @@ -213,14 +214,13 @@ export function useReducer(reducer, initialState, init) {
return hookState._value;
}

const oldAfterRender = options._afterRender;
options._afterRender = (newVNode, oldVNode) => {
if (newVNode._component && newVNode._component.__hooks) {
const hooks = newVNode._component.__hooks._list;
const stateHooksThatExecuted = hooks.filter(
/** @type {(x: import('./internal').HookState) => x is import('./internal').ReducerHookState} */
// @ts-expect-error
x => !!x._component && x._didExecute
x => x._component && x._didExecute
);

if (
Expand All @@ -232,9 +232,8 @@ options._afterRender = (newVNode, oldVNode) => {
newVNode._flags |= SKIP_CHILDREN;
}

stateHooksThatExecuted.forEach(hook => {
hook._didUpdate = undefined;
hook._didExecute = false;
stateHooksThatExecuted.some(hook => {
hook._didExecute = hook._didUpdate = false;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const INSERT_VNODE = 1 << 2;
/** Indicates a VNode has been matched with another VNode in the diff */
export const MATCHED = 1 << 1;

export const SKIP_CHILDREN = 1 << 18;
export const SKIP_CHILDREN = 1 << 3;

/** Reset all mode flags */
export const RESET_MODE = ~(MODE_HYDRATE | MODE_SUSPENDED);
Expand Down

0 comments on commit 3525847

Please sign in to comment.