Skip to content

Commit

Permalink
Thought exercise on sCU
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Dec 20, 2024
1 parent 9022d4a commit 548142a
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions packages/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export {
};

const HAS_PENDING_UPDATE = 1 << 0;
const HAS_HOOK_STATE = 1 << 1;
const HAS_COMPUTEDS = 1 << 2;

// Install a Preact options hook
Expand Down Expand Up @@ -300,13 +299,6 @@ hook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {
old(vnode);
});

/** Mark components that use hook state so we can skip sCU optimization. */
hook(OptionsTypes.HOOK, (old, component, index, type) => {
if (type < 3 || type === 9)
(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;
old(component, index, type);
});

/**
* Auto-memoize components that use Signals/Computeds.
* Note: Does _not_ optimize components that use hook/class state.
Expand All @@ -320,34 +312,12 @@ Component.prototype.shouldComponentUpdate = function (
const updater = this._updater;
const hasSignals = updater && updater._sources !== undefined;

// let reason;
// if (!hasSignals && !hasComputeds.has(this)) {
// reason = "no signals or computeds";
// } else if (hasPendingUpdate.has(this)) {
// reason = "has pending update";
// } else if (hasHookState.has(this)) {
// reason = "has hook state";
// }
// if (reason) {
// if (!this) reason += " (`this` bug)";
// console.log("not optimizing", this?.constructor?.name, ": ", reason, {
// details: {
// hasSignals,
// hasComputeds: hasComputeds.has(this),
// hasPendingUpdate: hasPendingUpdate.has(this),
// hasHookState: hasHookState.has(this),
// deps: Array.from(updater._deps),
// updater,
// },
// });
// }

// if this component used no signals or computeds, update:
if (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;

// if there is a pending re-render triggered from Signals,
// or if there is hook or class state, update:
if (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;
if (this._updateFlags & HAS_PENDING_UPDATE) return true;

// @ts-ignore
for (let i in state) return true;
Expand Down

0 comments on commit 548142a

Please sign in to comment.