Skip to content

Conversation

@gabriellsh
Copy link
Member

@gabriellsh gabriellsh commented Aug 21, 2025

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 node was 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 a null node 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:

if (!node) {
    return;
}

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

@changeset-bot
Copy link

changeset-bot bot commented Aug 21, 2025

🦋 Changeset detected

Latest commit: f11ac4e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@rocket.chat/fuselage-hooks Patch
@rocket.chat/logo Patch

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

@gabriellsh gabriellsh marked this pull request as draft August 21, 2025 22:27
@gabriellsh
Copy link
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.

@gabriellsh gabriellsh marked this pull request as ready for review August 22, 2025 18:27
@tassoevan tassoevan merged commit 5bbd461 into main Aug 25, 2025
8 checks passed
@tassoevan tassoevan deleted the fix/useSafeRefCallback branch August 25, 2025 17:26
This was referenced Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants