-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Remove HAS_HOOKS_STATE
bit
#630
Conversation
🦋 Changeset detectedLatest commit: 17ea2e4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for preact-signals-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
HAS_HOOKS_STATE
bitHAS_HOOKS_STATE
bit
Size Change: +124 B (+0.15%) Total Size: 83.2 kB
ℹ️ View Unchanged
|
Update, we should remove the base rerender when there are no signals to also account for hooks-state as seen in 2c97a21 else state settling in hooks would never be respected. I've added a heuristic for whether or not we are dealing with state settling, you can see the relevant property here - I would backport this to 1.3.x as well to have safety in both major versions |
// @ts-ignore | ||
for (let i in state) return true; | ||
|
||
if (this.__f || (typeof this.u == "boolean" && this.u === true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to have opinions on this retroactive fix, with adding this.u
here we don't necessarily do anything wrong, when hooks would settle into a falsey update they would never call this function before so as of 10.25.x it fixes an issue and in pre 10.24.x it doesn't really do anything
17c20c9
to
2392a0a
Compare
Resolves preactjs/preact#4628
This is a thought exercise as a result of a fix in the Preact respository, strap in as this might become a doozy, open up a Stackblitz and follow along. In 10.25.0 we fixed an issue where the hooks-state settling logic would prevent a component having both signals as well as state from re-rendering, The relevant PR.
The issue was that when a component has a signal that updates and hooks that end up at the same value the component would not rerender.
This was solved by calling the previous
shouldComponentUpdate
(in this case the global sCU set by@preact/signals
) when the state settling logic decides to bail out. From a plugin perspective this is the right course of action as we want all plugins to have their lifecycles respected.Now this does however bring us to the... interesting part, when a state hook now decides in 10.25.x that it needs to bail we'll rerender it anyway because we see
HAS_HOOK_STATE
.Let's look at this in action
Now what I want to achieve is a middle ground where we can respect hooks state settling as well as rerender correctly.
Another variable to consider with signals is
hookState._component.props !== props;
, this line is meant to respect the top-down rerender flow. When the parent initiates a render and passes through an updated prop we want to rerender deeply as this is the classic state based Virtual DOM way. In signals we do shallow equality, this however means that any component having both signals and state-based VDOM will respect the top-down render which I guess is a "one up" for removing thisHAS_HOOKS_STATE
.Now the question becomes how will this behave?
10.0-10.12
HAS_HOOKS_STATE
to rerender the componentHAS_PENDING_UPDATE
to rerender the component10.12-10.24
I think it's safe to not cater to this case as it was a bug in Preact.
10.25.x and onwards
HAS_PENDING_UPDATE
to rerender the componentI don't want to imply that removing
HAS_HOOKS_STATE
is the right solution but this is more a way to discuss the tradeoffs and show the impact it has on different versions of Preact.Note
The consequences of the above also become clear when upgrading the Preact package in signals, the currently failing test passes (with the current changes) when we upgrade to anything beyond 10.12.x. This implies that this bit is only needed for 10.0-10.12