Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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