React useThreads
incorrect usage of useSyncExternalStoreWithSelector
triggers infinite re-renders
#1442
Labels
bug
Something isn't working
Describe the bug
The
useThreads
component passes a new selector touseSyncExternalStoreWithSelector
on each render. This function is used herepackages/liveblocks-react/src/comments/CommentsRoom.tsx
line 488.This makes it so that every time
useThreads
is called, the referencedthreads
binding will be a new object.To Reproduce
The re-render triggered by the
setVisibleThreads
will trigger an infinite re-render sincethreads
will always have a new reference.Workaround
Use deep equals for any state depending on
threads
.Fix
To fix this the following needs to be updated to use memoized functions:
Environment (please complete the following information):
1.9.3
by this PR - Add support for rendering comment in multiple room #1385The text was updated successfully, but these errors were encountered: