feat: add useSocketId() hook to React, Vue and Svelte adapters#499
Open
hectorgrecco wants to merge 3 commits into
Open
feat: add useSocketId() hook to React, Vue and Svelte adapters#499hectorgrecco wants to merge 3 commits into
hectorgrecco wants to merge 3 commits into
Conversation
Implements useSocketId hook that calls useConnectionStatus for reactivity and returns echo().socketId(). Also adds socketId and connector mocks to the laravel-echo vi.mock to support the new test.
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.
Summary
Adds a
useSocketId()reactive hook/composable/rune to all three framework adapters, closing the gap described in #474.The existing
echo()function is already exported from all adapters and can be used directly for interceptor setup:However, there was no reactive primitive for component usage that automatically updates when the connection reconnects and receives a new socket ID. This PR fills that gap.
New API
React
Vue
Svelte
Implementation
useSocketId()builds on the existinguseConnectionStatus()in each adapter — it subscribes toonConnectionChangefor free, so when the connection cycles (and a new socket ID is assigned), the value updates automatically. No new subscriptions or state management.Test plan
packages/react: 61 tests pass, 1 pre-existing skippackages/vue: 45 tests pass, 2 pre-existing skipspackages/svelte: 32 tests passCloses #474