fix(ui): disconnect hot reload sockets on unmount#3658
Merged
gabrielmfern merged 2 commits intoJul 14, 2026
Conversation
Contributor
|
@hducati is attempting to deploy a commit to the resend Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 07ebc5c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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 |
gabrielmfern
approved these changes
Jul 14, 2026
gabrielmfern
left a comment
Member
There was a problem hiding this comment.
this is very nice, thank you!
commit: |
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.
The previous implementation mixed two lifecycle concerns:
-> callback changes during a re-render: socket should remain connected and use the latest callback
-> component unmounts: socket should be closed
The original socket.off() likely avoided reconnecting whenever an inline callback changed. However, after a real unmount, the socketRef is discarded, so that connection can never be reused.
I ran a runtime measurement on my end, and it confirmed the leak:
Before: 3 → 5 → 7 → 9 → 11 active sockets
After: 3 → 3 → 3 → 3 → 3 active sockets
The additional sockets belonging to unmounted components have no purpose at all
Summary by cubic
Fixes a hot reload socket leak by disconnecting the socket when preview components unmount. Keeps the latest reload callback without reconnecting on re-renders.
reloadlistener and calldisconnect().onShouldReloadstays up to date without re-subscribing.@react-email/ui.Written for commit 07ebc5c. Summary will update on new commits.