refactor(fuselage-hooks): useSafeRefCallback reimplemented callback/cleanup order
#1741
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