Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@rwzdk is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
c556b1a to
60c358d
Compare
|
Caution Review failedThe pull request is closed. Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
1678739 to
a637287
Compare
|
Superseded by #7729 for the |
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Problem
Shared observables iterate their live subscriber list while delivering an event, but a subscriber tears itself down synchronously as soon as it receives one:
observable()runs the teardown aftererror/complete, and a subscriber may also unsubscribe insidenext(that is exactly whatobservableToPromisedoes). The teardown splices the subscriber out of the list, thefor...ofloop moves on to the element that shifted into the slot it already visited, and the next subscriber is skipped.share()https://github.com/trpc/trpc/blob/main/packages/server/src/observable/operators.ts#L52-L64
complete, so e.g.observableToPromisenever settles,next: every following subscriber silently misses that value.share()backsTRPCUntypedClient.$requestanddedupeLink, and it is public API via@trpc/server/observable.behaviorSubjecthttps://github.com/trpc/trpc/blob/main/packages/server/src/observable/behaviorSubject.ts#L44-L48
Same root cause in
next(): an observer that unsubscribes insidenextcauses its neighbour to miss the value.behaviorSubjectcarries the connection state inhttpSubscriptionLinkand thewsClient.Fix
Iterate over a snapshot of the subscriber list in both places, so a synchronous teardown cannot shift the remaining subscribers out of the loop.
Tests
operators.test.ts: two subscribers on completion, two on error, and a subscriber that unsubscribes insidenext.behaviorSubject.test.ts: two observers, the first unsubscribes insidenext.Red (main sources + new tests):
packages/server/src/observable/βTests 4 failed | 11 passed (15)β e.g.expected "vi.fn()" to be called 1 times, but got 0 timesandexpected [ 0 ] to deeply equal [ 0, 1 ].Green (patched):
packages/server/src/observable/+dedupeLink+clientInternals+linksβTests 47 passed (47)across 6 files.Prepared with an AI coding agent.