fix(droid): resolve DataCloneError in ws-worker Comlink callback#9893
Merged
fix(droid): resolve DataCloneError in ws-worker Comlink callback#9893
Conversation
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
storeWsMessage stored FlexBuffers-decoded objects directly into Dexie. toReference().toObject() returns objects containing Uint8Array typed array views referencing the original ArrayBuffer. Dexie's multi-tab sync broadcasts changes via BroadcastChannel.postMessage(), which throws DataCloneError on these typed array views. JSON round-trip the decoded object before storing to produce a plain cloneable value.
c56bd84 to
e808324
Compare
storeWsMessage assumed all WebSocket data was FlexBuffers-encoded and called toReference().toObject(), which returns objects with typed array views. Dexie's BroadcastChannel multi-tab sync then threw DataCloneError when trying to postMessage those views. The ws-worker is protocol-agnostic (IRC text, FlatBuffers, Protobuf) so the storage layer should be too. Now stores raw bytes as Uint8Array (natively supported by IndexedDB and BroadcastChannel) and removes the FlexBuffers decode from the write path. Consumers decode on read using the appropriate deserializer for their protocol.
Replaced the main-thread bridgeWsToDb pattern with direct worker-to-
worker communication via BroadcastChannel ('kbve_ws_data').
Before: ws-worker → Comlink → main thread → Comlink → db-worker → IDB
After: ws-worker → BroadcastChannel → db-worker → IDB
- ws-worker broadcasts classified messages (text/binary + timestamp)
directly to db-worker, main thread never touches raw data
- db-worker stores raw bytes as Uint8Array (format-agnostic, no
FlexBuffers assumption — supports IRC text, FlatBuffers, Protobuf)
- Removed bridgeWsToDb and unused proxy import from main.ts
- Removed FlexBuffers toReference import from db-worker (was
causing DataCloneError via Dexie BroadcastChannel sync)
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
Replaced the main-thread
bridgeWsToDbpattern with direct worker-to-worker communication via BroadcastChannel.Before (main thread in the data path):
After (main thread only handles UI events):
Changes
text/binary+ timestamp) tokbve_ws_dataBroadcastChannel — main thread callback still fires for UI renderingkbve_ws_datachannel, stores raw bytes asUint8Array(format-agnostic — IRC text, FlatBuffers, Protobuf all stored the same way, consumers decode on read)bridgeWsToDbfunction and unusedproxyimport — main thread no longer participates in the storage pipelinetoReferencedecode from db-worker write path — was producing objects with typed array views that Dexie's BroadcastChannel sync couldn't cloneTest plan