Skip to content

Commit b18697e

Browse files
committed
Add to mangle
1 parent 8101042 commit b18697e

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

mangle.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
"props": {
2929
"cname": 6,
3030
"props": {
31+
"$__persistentState": "__$p",
32+
"$_list": "__",
33+
"$_pendingSetup": "__h",
34+
"$_cleanup": "__c",
35+
"$_stateValue": "__",
36+
"$_args": "__H",
37+
"$_stored": "__s",
38+
"$_renderCallbacks": "__h",
39+
"$_skipEffects": "__s",
3140
"core: Node": "",
3241
"$_watched": "W",
3342
"$_unwatched": "Z",

packages/preact/src/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ hook(OptionsTypes.DIFFED, (old, vnode) => {
270270
component.__persistentState &&
271271
component.__persistentState._pendingSetup.length
272272
) {
273+
console.log("f", component.__persistentState._pendingSetup);
273274
queueSetupTasks(setupTasks.push(component));
274275
}
275276
}
@@ -467,7 +468,8 @@ function queueSetupTasks(newQueueLength: number) {
467468
function flushSetup() {
468469
let component;
469470
while ((component = setupTasks.shift())) {
470-
if (!component.__persistentState) continue;
471+
console.log("flushSetup", component.__P, component.__persistentState);
472+
if (!component.__persistentState || !component.__P) continue;
471473
try {
472474
component.__persistentState._pendingSetup.forEach(invokeCleanup);
473475
component.__persistentState._pendingSetup.forEach(invokeEffect);
@@ -527,11 +529,11 @@ function getState(index: number): HookState {
527529

528530
export function useStoreValueOnce<T>(factory: () => T): T {
529531
const state = getState(currentHookIndex++);
530-
if (!state._stored) {
532+
if (!state._stored || (options as any)._skipEffects) {
531533
state._stored = true;
532-
state._value = factory();
534+
state._stateValue = factory();
533535
}
534-
return state._value;
536+
return state._stateValue;
535537
}
536538

537539
export function useRef<T>(initialValue: T): { current: T } {
@@ -542,14 +544,15 @@ function useOnce(callback: () => void | (() => void)): void {
542544
const state = getState(currentHookIndex++);
543545
if (!state._executed) {
544546
state._executed = true;
545-
state._value = callback;
547+
state._stateValue = callback;
546548
currentComponent!.__persistentState._pendingSetup.push(state);
547549
}
548550
}
549551

550552
function invokeEffect(hook: HookState): void {
551-
if (hook._value) {
552-
hook._cleanup = hook._value() || undefined;
553+
console.log("invokeEffect", hook);
554+
if (hook._stateValue) {
555+
hook._cleanup = hook._stateValue() || undefined;
553556
}
554557
}
555558

packages/preact/src/internal.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ export interface AugmentedComponent extends Component<any, any> {
2828
_updater?: Effect;
2929
_updateFlags: number;
3030
__persistentState: SignalState;
31+
__P?: Element | Text | null;
3132
}
3233

3334
export interface HookState {
3435
_executed?: boolean;
3536
_stored?: boolean;
36-
_value?: any;
37+
_stateValue?: any;
3738
_cleanup?: () => void;
3839
}
3940

0 commit comments

Comments
 (0)