Replace handler hook with element_id based approach #11
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.
Removes the handler hook API and replaces it with a more transparent and simpler (at least, from the developer API perspective) element_id-based tracking system. The intent here is to keep the optimization where event ids remain stable across updates even though event handler callback functions may be recreated and re-bound on every render cycle, preventing unnecessary id changes in patches for event handlers.
This work achieves that by adding a stable
element_id
to theReconciledElement
record and utilizing the existing reconciler diffing logic to determine if an element is the same element as the previous element or if it is a new element that needs a newelement_id
.With this new approach, it is no longer necessary for a developer to use hooks to define event handlers and event handling should be much simpler. For example, previously a component would need to be written as such:
Now with these changes, the component handlers can simply be written as normal functions:
Or with the handler callback inlined with the markup for simple cases: