Skip to content

Commit 1c48a64

Browse files
useTextStream encounters TypeError('A text stream handler for topic...') upon browser refresh (#1118)
Co-authored-by: lukasIO <[email protected]>
1 parent 202802d commit 1c48a64

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

.changeset/itchy-rocks-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/components-react": patch
3+
---
4+
5+
fix: avoid text stream re-register on disconnect

packages/react/src/hooks/useTextStream.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ export function useTextStream(topic: string) {
1919
const room = useRoomContext();
2020

2121
const connectionState = useConnectionState(room);
22-
const isDisconnected = React.useMemo(
23-
() => connectionState === ConnectionState.Disconnected,
24-
[connectionState],
25-
);
22+
const isDisconnected = connectionState === ConnectionState.Disconnected;
2623

27-
const textStreamObservable = React.useMemo(() => {
28-
return setupTextStream(room, topic);
29-
}, [room, topic, isDisconnected]);
24+
const textStreamData = React.useMemo(() => setupTextStream(room, topic), [room, topic]);
25+
const textStreamObservable = isDisconnected ? undefined : textStreamData;
3026

3127
const textStreams = useObservableState<TextStreamData[]>(textStreamObservable, []);
3228

0 commit comments

Comments
 (0)