fix(react): cleanup functions are execute for lifecycle hooks - #28319
Merged
Conversation
Co-authored-by: Maria Hutt <maria@ionic.io>
sean-perkins
commented
Oct 10, 2023
sean-perkins
marked this pull request as ready for review
October 10, 2023 17:11
Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
sean-perkins
force-pushed
the
sp/FW-5340
branch
from
October 11, 2023 20:12
faa3cfe to
7eb58bd
Compare
thetaPC
reviewed
Oct 12, 2023
Comment on lines
+144
to
+145
| const destructor = cb(); | ||
| if (cb.id) { |
Contributor
There was a problem hiding this comment.
Wouldn't it be better to create the variable, destructor inside the if statement? That way there isn't an unused variable if cb.id doesn't exist.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment.
Following up on why I did this - took me a second to recall.
The callback may not have an id, but we still want to invoke the callback regardless. Otherwise the developers implementation within the lifecycle hook will never fire.
We only want to store the destructor callback if the callback has an id - which is assigned from the lifecycle hooks.
This was intentional.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue number: Resolves #28186
What is the current behavior?
Ionic lifecycle hooks do not execute a cleanup function when the underlying
useEffectis unmounted.Ionic's implementation registers the lifecycle callback to be handled at a later time, by the page managers. However, it does not keep a reference to the returned callback, so it cannot execute it when the
useEffectis unmounted.What is the new behavior?
Does this introduce a breaking change?
Other information
Dev-build:
7.4.4-dev.11696956070.1faa3cfeThis PR builds on the changes in #28316.