fix: handle unknown union variants without dropping the whole update#41
Merged
jimmy-phantom merged 2 commits intoJun 15, 2026
Merged
Conversation
When a union payload's __typename matches no known variant (e.g. a server that added a variant the client schema does not list yet), parsing threw and applyMutationEvent swallowed it with a warn, discarding the entire entity update including unrelated sibling fields. Now an optional union field degrades to undefined and the rest of the entity applies; a non-optional one rethrows as UnknownUnionVariantError, which applyMutationEvent surfaces as an error (visible, not a silent warn) without applying partial state. Initial load and live updates behave identically. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pzuraq
approved these changes
Jun 15, 2026
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
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.
Problem
When a discriminated-union payload carries a
__typenamematching no known variant (commonly a server that added a variant the client schema doesn't list yet), union parsing throws.applyMutationEventcaught that throw, logged awarn, and discarded the entire entity update, including unrelated sibling fields, with nothing surfaced. The entity would silently stop updating until a known-variant payload arrived.Change
UnknownUnionVariantErrorat the union-discrimination site.parseData, an unknown variant on an optional field degrades toundefinedand the rest of the entity applies; on a non-optional field it rethrows.applyMutationEventsurfacesUnknownUnionVariantErrorvialog.error(visible) instead of the silentwarn, and still applies no partial state.applyData) and live updates (applyMutationEvent) behave identically, since the decision lives in the shared parse path.undefined, rest appliesundefined, rest applieslog.errorTests
unknown-union-variant.test.tscovers all four cells. Full unit suite green;tsc --noEmitclean.🤖 Generated with Claude Code