fix(web): swallow non-UpdateNotification BroadcastUpdates payloads#143
Open
wojciechlas wants to merge 1 commit into
Open
fix(web): swallow non-UpdateNotification BroadcastUpdates payloads#143wojciechlas wants to merge 1 commit into
wojciechlas wants to merge 1 commit into
Conversation
`BroadcastUpdates.get updates` chains `.map(...) → .where(...) → .cast()`. After `.where()` removes nulls, the source element type is still `UpdateNotification?`, and a bare `.cast()` lets DDC infer the cast target from the source rather than the declared `Stream<UpdateNotification>` return type. A peer message that survives `.where()` but isn't an `UpdateNotification` (legacy storage mode, SharedWorker fallback, non-conforming `BroadcastChannel` payload) then throws. Because the downstream `.listen()` in `async_web_database.dart` has no `onError` handler, the cast failure escalates to an uncaught error on the root zone. On Flutter web this surfaces as a `DartError` popup. Two surgical changes: - `broadcast_updates.dart`: make the cast type argument explicit (`.cast<UpdateNotification>()`) so type inference matches the declared return type. - `async_web_database.dart`: attach an `onError` handler on the broadcast subscription so any malformed peer payload degrades silently instead of crashing the host application. No API surface change. Bumped to `0.14.2-wip` per DEVELOPING.md.
There was a problem hiding this comment.
Pull request overview
Fixes an uncaught Flutter web (DDC) error when cross-tab BroadcastChannel traffic contains payloads that don’t deserialize into UpdateNotification, ensuring malformed peer messages don’t crash the host app.
Changes:
- Make the stream cast in
BroadcastUpdates.updatesexplicit (cast<UpdateNotification>()) to align type inference with the declaredStream<UpdateNotification>. - Add an
onErrorhandler to the broadcast-updates subscription inAsyncWebDatabaseImplto prevent uncaught root-zone errors from malformed messages. - Bump package version to
0.14.2-wipand add a changelog entry describing the web fix.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/sqlite_async/lib/src/web/database/broadcast_updates.dart | Makes the post-where() cast explicit to avoid incorrect inference and runtime cast failures surfacing uncaught. |
| packages/sqlite_async/lib/src/web/database/async_web_database.dart | Adds an onError handler on cross-tab update listening to avoid uncaught errors on malformed payloads. |
| packages/sqlite_async/pubspec.yaml | Bumps package version to 0.14.2-wip. |
| packages/sqlite_async/CHANGELOG.md | Documents the web broadcast update error-handling fix under 0.14.2-wip. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+76
to
+78
| // malformed peer messages, SharedWorker fallback). Drop them | ||
| // rather than crashing the host application via an uncaught | ||
| // error on the root zone. |
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
On Flutter web, a cross-tab
BroadcastChannelmessage that does not deserialise into anUpdateNotificationsurfaces as an uncaughtDartError:Two surgical changes fix it:
lib/src/web/database/broadcast_updates.dart— make the cast type argument explicit (.cast<UpdateNotification>()) so type inference matches the declaredStream<UpdateNotification>return type rather than inferring the nullable source-stream element type.lib/src/web/database/async_web_database.dart— attach anonErrorhandler on the broadcast subscription so any residual malformed peer payload degrades silently instead of escalating to an uncaught error on the root zone.Root cause
BroadcastUpdates.get updateschains.map(...) → .where(...) → .cast(). After.where()removes nulls, the source element type is stillUpdateNotification?. A bare.cast()lets DDC infer the cast target from the source element type (UpdateNotification?) rather than from the declaredStream<UpdateNotification>return type. When a peer publishes a payload that survives.where()but isn't anUpdateNotification(legacy storage mode, SharedWorker fallback, or otherwise non-conformingBroadcastChanneldata), the cast throws.Because the downstream
.listen()inasync_web_database.darthas noonErrorhandler, the cast failure escalates to an uncaught error on the root zone. On Flutter web this surfaces as aDartErrorpopup; a host app usingPlatformDispatcher.onErroralso sees it.dart2js production builds may mask the symptom thanks to stricter type inference at compile time, but DDC users hit it on every reproducer.
Reproducer
Open two tabs of any Flutter web app using sqlite_async with shared-tab broadcast updates. Trigger a write in one tab that fires
broadcastUpdates.send(...). The second tab logs the cast error and (on DDC) raises an uncaught DartError popup.Changes
lib/src/web/database/broadcast_updates.dart:.cast()→.cast<UpdateNotification>()lib/src/web/database/async_web_database.dart: addonErrorhandler onbroadcastUpdates.updates.listenpubspec.yaml: bump to0.14.2-wipCHANGELOG.md: entry under0.14.2-wipTest plan
Happy to add a regression test if you can point me at the right web test fixture layout.
Notes for maintainers
onError); no API surface change.🤖 Generated with Claude Code