Fixed useLiveState, useLivePresence, useLiveFollowMode, and useLiveEvent bugs that caused the uniqueKey field not fetching the correct default values when the new DDS is loaded. Other hooks do not appear to have this same issue.
Bug originally happened because I was trying to reduce what I saw as redundant renders, but I guess React already skips re-render if the value is unchanged. For useLivePresence it may actually cause duplicate re-renders, but it's better to do that than to miss getting the initial values.
In this image the text input is the uniqueKey field passed into the useLiveState field. Since both users have different values, the shared count displayed is different. If I switch the right to have the same value as the left, it updates to this:
And now if I increment the counter it updates for both clients:
And if I then change the id again on the left, the value updates to the correct default of 1 (but not the right, as expected):
Prior to this change, it would have kept the same value from the previous DDS instance. So if I were to have changed the key to "tests 2" in the same way as that last image, the default value would have been 4 rather than 1 (even though internally LiveState knew the initial value was 1.
The other hooks had similar solutions, but some like useLiveTimer and useLiveEvent needed special treatment. For that, I reset it to the defaults of undefined whenever the value changed. Still seems to work fine. For useLiveEvent I simply reset the locally tracked latestEvent and allEventsRef to their default values whenever the underlying DDS is swapped for a new one. This works fine due to the internal nuances of those DDS's.
Fixed
useLiveState
,useLivePresence
,useLiveFollowMode
, anduseLiveEvent
bugs that caused theuniqueKey
field not fetching the correct default values when the new DDS is loaded. Other hooks do not appear to have this same issue.Bug originally happened because I was trying to reduce what I saw as redundant renders, but I guess React already skips re-render if the value is unchanged. For
useLivePresence
it may actually cause duplicate re-renders, but it's better to do that than to miss getting the initial values.In this image the text input is the
uniqueKey
field passed into theuseLiveState
field. Since both users have different values, the shared count displayed is different. If I switch the right to have the same value as the left, it updates to this:And now if I increment the counter it updates for both clients:
And if I then change the id again on the left, the value updates to the correct default of 1 (but not the right, as expected):
Prior to this change, it would have kept the same value from the previous DDS instance. So if I were to have changed the key to "tests 2" in the same way as that last image, the default value would have been 4 rather than 1 (even though internally
LiveState
knew the initial value was 1.The other hooks had similar solutions, but some like
useLiveTimer
anduseLiveEvent
needed special treatment. For that, I reset it to the defaults of undefined whenever the value changed. Still seems to work fine. ForuseLiveEvent
I simply reset the locally trackedlatestEvent
andallEventsRef
to their default values whenever the underlying DDS is swapped for a new one. This works fine due to the internal nuances of those DDS's.