Skip to content

Conversation

@oliverlaz
Copy link
Member

@oliverlaz oliverlaz commented Nov 19, 2025

💡 Overview

Fixes #2006. Cold-derived Observable instances (remoteParticipants$ and similar) get read twice in strict mode, and as such, the derivative runs multiple times, creating multiple shallow-equal arrays.
Although this isn't exactly an issue, as we had this behavior before #1953, the emitter warning could be confusing.

Docs: https://github.com/GetStream/docs-content/pull/778

@oliverlaz oliverlaz changed the title fix: getSnapshot caching fix(react-bindings): getSnapshot caching Nov 19, 2025
Copilot finished reviewing on behalf of oliverlaz November 19, 2025 17:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue where cold-derived Observable instances (like remoteParticipants$) are read multiple times in React strict mode, causing redundant derivations and emitter warnings. The fix introduces a ref-based caching mechanism for getSnapshot to ensure the initial value is only read once.

Key changes:

  • Introduced valueRef and initialRenderRef to cache observable values and prevent multiple reads during strict mode
  • Moved value retrieval logic from getSnapshot into initialization and subscription callbacks
  • Simplified the getSnapshot function to return cached values from refs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@oliverlaz oliverlaz merged commit ed0983c into main Nov 20, 2025
17 of 19 checks passed
@oliverlaz oliverlaz deleted the getsnapshot-caching branch November 20, 2025 14:07
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.

The result of getSnapshot should be cached to avoid an infinite loop

4 participants