-
Notifications
You must be signed in to change notification settings - Fork 1
fix(react): ensure useDocumentProjection reuses state source for all strings #669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cngonzalez
merged 2 commits into
main
from
fix/sdk-660/ensure-doc-projections-reuse-state-source
Nov 21, 2025
Merged
fix(react): ensure useDocumentProjection reuses state source for all strings #669
cngonzalez
merged 2 commits into
main
from
fix/sdk-660/ensure-doc-projections-reuse-state-source
Nov 21, 2025
+242
−40
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ryanbonial
previously approved these changes
Nov 14, 2025
Member
ryanbonial
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix works well. Thanks!
aeff275 to
e1310c2
Compare
f9dba71 to
95755bf
Compare
e1310c2 to
6f60f63
Compare
95755bf to
cd12fbe
Compare
6f60f63 to
9fbbb0e
Compare
cd12fbe to
71274df
Compare
9fbbb0e to
74d86d1
Compare
74d86d1 to
9baabcc
Compare
2df6371 to
6667598
Compare
6667598 to
b4dda08
Compare
9baabcc to
176e4ef
Compare
The base branch was changed.
176e4ef to
6c199ee
Compare
ryanbonial
approved these changes
Nov 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Description
useDocumentProjectionwas actually a bit finicky about theprojectionbeing passed to it. We had a ticket about it looping forever.My best guess about what was happening was this:
useDocumentProjectionuseDocumentProjectionwould then callgetProjectionState. It always returns a newStateSource, which returns a newsubscribefunctionuseSyncExternalStorereceives the newsubscribefunction, triggering a re-renderThis PR adds some memoization to maintain consistency in projection strings and state sources.
We didn't catch this in casual clicking around because
defineProjectionwas doing some of the memoization work for us, I think. To address this, I added some common ways people would useuseDocumentProjectionand also some e2e tests against it.What to review
Any risks of over memoization or staleness?
Testing
e2e tests (I think this is hard to capture in React tests and we still have 100% coverage).
To see the OLD behavior,
git fetchgit checkout maingit checkout origin/fix/sdk-660/ensure-doc-projections-reuse-state-source apps/kitchensink-react/src/DocumentCollection/DocumentProjectionRoute.tsxpnpm devThis PR fixes that.