Skip to content

Commit e1e22db

Browse files
committed
fix: remove prepareConnection dependency in useEffect
This was causing prepareConnection to get run constantly since its reference depends on restOptions which changes every call. The way I see it, if a user is changing their options and wants prepareconnection to be run for something beyond the initial set (probably unusual), they can call it themselves on the returned session object.
1 parent f3ab908 commit e1e22db

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/react/src/hooks/useSession.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,17 @@ export function useSession(
486486
// room.prepareConnection(tokenSource, { tokenSourceOptions }),
487487
await room.prepareConnection(credentials.serverUrl, credentials.participantToken);
488488
}, [tokenSourceFetch, room]);
489-
React.useEffect(() => {
490-
prepareConnection().catch((err) => {
491-
// FIXME: figure out a better logging solution?
492-
console.warn('WARNING: Room.prepareConnection failed:', err);
493-
});
494-
}, [prepareConnection]);
489+
React.useEffect(
490+
() => {
491+
prepareConnection().catch((err) => {
492+
// FIXME: figure out a better logging solution?
493+
console.warn('WARNING: Room.prepareConnection failed:', err);
494+
});
495+
},
496+
[
497+
/* note: no prepareConnection here, this effect should only ever run once! */
498+
],
499+
);
495500

496501
return React.useMemo(
497502
() => ({

0 commit comments

Comments
 (0)