fix(query-broadcast-client-experimental): suppress unhandled postMessage DataCloneError rejections#10697
Open
algojogacor wants to merge 1 commit into
Open
Conversation
…age DataCloneError rejections Add .catch() handlers to all three BroadcastChannel postMessage calls to prevent unhandledrejection events when query state contains non-cloneable values (ReadableStream, Response, File, functions, etc.). Fixes TanStack#10543
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.
Summary
Fixes #10543
broadcastQueryClientsilently causes unhandledDataCloneErrorrejections when a query'sstate.datacontains non-cloneable values likeReadableStream,Response,File, or framework proxies. These rejections surface in error trackers (Sentry/Datadog) with stacks pointing intonode_modules, making them impossible to trace to specific queries.Root Cause
In
packages/query-broadcast-client-experimental/src/index.ts, the threechannel.postMessage()calls (lines 40, 49, 57 — forupdated,removed,addedevents) do not have.catch()handlers. When the structured-clone algorithm encounters non-cloneable data,broadcast-channelrejects internally, producing anunhandledrejectionevent.Fix
Added
.catch(() => {})to all threepostMessage()calls. This silently swallows clone failures — the same approach used by broadcast-channel internally for its own message parsing. Cross-tab sync for that specific query update is skipped (the cloned data can't be transferred), but error trackers are no longer polluted and other queries continue syncing normally.Changes
packages/query-broadcast-client-experimental/src/index.ts: added.catch(() => {})to threepostMessage()calls (+3 -3lines)Testing
broadcastQueryClientno longer triggersunhandledrejectionwhen setting query data withReadableStreamorResponsevalues ✅