Skip to content

Conversation

judofyr
Copy link
Contributor

@judofyr judofyr commented Sep 25, 2025

Description

This fixes a quite subtle bug: Any state changes happening in onSubscribe would be not be part of the source.observable. The reason for this is that the implementation would do:

  1. First emit the current value by looking at state.get()
  2. Invoke the onSubscribe hook.
  3. Listen to the observable of state, but skip the first value because we expect it to emit the current state first.

However, this means that if (2) actually changes the state synchronously then that's the value that is skipped in (3) happens to be the new state.

We're using this pattern in getDocumentSyncStatus.

This changes the implementation to be based around an observable which contains the actual values. This is both shorter in code and also happens to avoid calling getCurrent multiple times. Previously getCurrent would be invoked twice: Once for detecting that a value had changed and once again when producing the value.

What to review

  • Try to determine if there's some edge cases scenarios where this new (more correct IMO) behavior could happen.
  • Also wondering if there's a better pattern for withSubscribeHook.

Testing

  • I've added new unit tests for this behavior.

Fun gif

Sorry, I couldn't find any fun gifs about RxJS.

…eStateSourceAction

This fixes a quite subtle bug: Any state changes happening in `onSubscribe`
would be not be part of the source.observable. The reason for this is
that the implementation would do:

1. First emit the current value by looking at state.get()
2. Invoke the onSubscribe hook.
3. Listen to the observable of state, but skip the first value
   because we expect it to emit the current state first.

However, this means that if (2) actually _changes_ the state synchronously
then that's the value that is skipped in (3) happens to be the new state.

This changes the implementation to be based around an observable
which contains the actual values. This is both shorter in code
and also happens to avoid calling `getCurrent` multiple times.
Previously `getCurrent` would be invoked twice: Once for detecting
that a value had changed and once again when producing the value.
@judofyr judofyr self-assigned this Sep 25, 2025
@judofyr judofyr requested a review from a team as a code owner September 25, 2025 14:31
@judofyr judofyr requested a review from colepeters September 25, 2025 14:31
Copy link

vercel bot commented Sep 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
sdk-kitchensink-react Ready Ready Preview Sep 25, 2025 2:31pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant