-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
WebSocket is closed before the connection is established
warning
- Loading branch information
Showing
3 changed files
with
14 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
18 changes: 7 additions & 11 deletions
18
packages/sanity/src/core/store/_legacy/presence/useDocumentPresence.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import {useEffect, useState} from 'react' | ||
import {useMemo} from 'react' | ||
import {useObservable} from 'react-rx' | ||
|
||
import {usePresenceStore} from '../datastores' | ||
import {type DocumentPresence} from './types' | ||
|
||
/** @internal */ | ||
export function useDocumentPresence(documentId: string): DocumentPresence[] { | ||
const presenceStore = usePresenceStore() | ||
const [presence, setPresence] = useState<DocumentPresence[]>([]) | ||
|
||
useEffect(() => { | ||
const subscription = presenceStore.documentPresence(documentId).subscribe(setPresence) | ||
return () => { | ||
subscription.unsubscribe() | ||
} | ||
}, [documentId, presenceStore]) | ||
|
||
return presence | ||
const observable = useMemo( | ||
() => presenceStore.documentPresence(documentId), | ||
[documentId, presenceStore], | ||
) | ||
return useObservable(observable, []) | ||
} |
16 changes: 4 additions & 12 deletions
16
packages/sanity/src/core/store/_legacy/presence/useGlobalPresence.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
import {useEffect, useState} from 'react' | ||
import {useMemo} from 'react' | ||
import {useObservable} from 'react-rx' | ||
|
||
import {usePresenceStore} from '../datastores' | ||
import {type GlobalPresence} from './types' | ||
|
||
/** @internal */ | ||
export function useGlobalPresence(): GlobalPresence[] { | ||
const [presence, setPresence] = useState<GlobalPresence[]>([]) | ||
const presenceStore = usePresenceStore() | ||
|
||
useEffect(() => { | ||
const subscription = presenceStore.globalPresence$.subscribe(setPresence) | ||
|
||
return () => { | ||
subscription.unsubscribe() | ||
} | ||
}, [presenceStore]) | ||
|
||
return presence | ||
const observable = useMemo(() => presenceStore.globalPresence$, [presenceStore]) | ||
return useObservable(observable, []) | ||
} |