refactor(fuselage-hooks): useSafeRefCallback reimplemented callback/cleanup order#1741
Merged
refactor(fuselage-hooks): useSafeRefCallback reimplemented callback/cleanup order#1741
useSafeRefCallback reimplemented callback/cleanup order#1741Conversation
🦋 Changeset detectedLatest commit: f11ac4e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Member
Author
|
I incorrectly assumed there was an issue, due to something else in another project. This implementation is better though, but I'll change it a lil' bit so it looks better. |
tassoevan
approved these changes
Aug 25, 2025
This was referenced Aug 22, 2025
Merged
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.
Proposed changes (including videos or screenshots)
This fixes an issue where if the passed callback reference were to change, the cleanup function would be lost.There was no such issue.
The callback calling order was refactored. Now when the component unmounts/rerender, the main callback won't be called - instead, the cleanup function will be called in it's place.
Previously, the cleanup function would be called everytime before the callbackRef was called, even if
nodewas null. This is the default behaviour for refCallbacks, and serves the purpose of communicating that that node stopped existing. Since we now have a cleanup function, this "extra call" with anullnode doesn't need to happen anymore, since the cleanup function will be called at this time.Another consideration that was taken is that, when using callbackRefs, it's very common to see the following pattern:
Every current use of this hook does this. Since most of the times that's how it's supposed to go, that behavior was abstracted inside the hook by not calling the refCallback when
node === null.Issue(s)
ARCH-1784
Further comments