Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ gradle-wrapper.jar

# Exceptions to the above rules
!/pubspec.lock
!**/example/web/sql-wasm.js
!**/example/web/sql-wasm.wasm
!/sample_app/web/sql-wasm.js
!/sample_app/web/sql-wasm.wasm
!**/example/web/drift_worker.js
!**/example/web/sqlite3.wasm
!/sample_app/web/drift_worker.js
!/sample_app/web/sqlite3.wasm
!/sample_app/android/app/google-services.json
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linter:
- avoid_relative_lib_imports
- avoid_slow_async_io
- avoid_types_as_parameter_names
- avoid_web_libraries_in_flutter
- cancel_subscriptions
- close_sinks
- control_flow_in_finally
Expand Down
12 changes: 10 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ command:
device_preview: ^1.2.0
diacritic: ^0.1.6
dio: ^5.11.0
drift: ^2.33.0
drift: ^2.34.4
equatable: ^2.0.8
ezanimation: ^0.6.0
firebase_core: ^4.0.0
Expand Down Expand Up @@ -121,6 +121,7 @@ command:
url_launcher: ^6.3.2
uuid: ^4.5.3
video_player: ^2.11.1
web: ^1.1.1
web_socket_channel: ^3.0.3

# List of all the dev_dependencies used in the project.
Expand All @@ -130,7 +131,7 @@ command:
emojis: ^0.9.9
substring_highlight: ^1.0.33
connectivity_plus_platform_interface: ^2.1.0
drift_dev: ^2.33.0
drift_dev: ^2.34.4
fake_async: ^1.3.3
faker_dart: ^0.2.3
flutter_launcher_icons: ^0.14.4
Expand Down Expand Up @@ -203,6 +204,13 @@ scripts:
run: $MELOS_ROOT_PATH/scripts/generate.sh
description: Generate the Chat Dart client from the Chat OpenAPI spec.

web:assets:
run: $MELOS_ROOT_PATH/scripts/fetch_web_assets.sh
description: >
Download the sqlite3.wasm and drift_worker.js files that
stream_chat_persistence needs on the web into every web app in this repo.
Re-run after bumping `drift` in melos.yaml.

version:update:
run: dart tools/generate_version.dart
description: Updates the version.dart file in stream_chat package based on pubspec.yaml version.
Expand Down
82 changes: 82 additions & 0 deletions migrations/v11-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ onto Stream's OpenAPI-generated API client.
- [Error Handling](#error-handling)
- [The error type changed too](#the-error-type-changed-too)
- [Feature Areas](#feature-areas)
- [Web Persistence](#web-persistence)
- [Migration Checklist](#migration-checklist)
- [For AI Agents](#for-ai-agents)
- [Contributing to this guide](#contributing-to-this-guide)
Expand Down Expand Up @@ -58,6 +59,7 @@ from the spec, so don't subclass them or depend on their private constructors.
| Feature Area | Key Changes |
| --- | --- |
| [**Error Handling**](#error-handling) | API calls return `Result<T>` instead of throwing; failures carry `stream_core`'s sealed `StreamException` family instead of `StreamChatNetworkError`; `ChatErrorCode` → `StreamErrorCode` |
| [**Web Persistence**](#web-persistence) | drift's deprecated sql.js backend replaced by WebAssembly, so `dart2wasm` builds are supported; `sql-wasm.js`/`sql-wasm.wasm` replaced by `sqlite3.wasm`/`drift_worker.js`; `webUseExperimentalIndexedDb` removed in favour of `webOptions`; web caches are refilled once |
| _(filled in per feature as PRs land)_ | |

---
Expand All @@ -73,6 +75,8 @@ search-and-replace you can apply directly. `Kind` is one of `renamed`, `removed`
| `StreamChatNetworkError.code` / `.message` / `.statusCode` | `StreamApiException.code` / `.message` / `.statusCode` | `moved` | `code` is now a `StreamErrorCode` |
| `StreamChatNetworkError.isRequestCancelledError` | `StreamNetworkException.isCancelled` | `moved` | |
| `ChatErrorCode` | `StreamErrorCode` (`stream_core`) | `removed` | Extension type over `int` with named constants |
| `StreamChatPersistenceClient(webUseExperimentalIndexedDb:)` | `StreamChatPersistenceClient(webOptions:)` | `removed` | Storage selection is automatic now, so there is no flag to forward |
| — | `StreamChatPersistenceWebOptions` | `renamed` | New type, exported from `package:stream_chat_persistence/stream_chat_persistence.dart` |
| _(more added per feature as PRs land)_ | | | |

---
Expand Down Expand Up @@ -157,6 +161,84 @@ counterpart: `code` is now a `StreamErrorCode` (an extension type over `int`, wi
_Each migrated feature gets a section here. Sections are added by the PR that migrates the feature, using the
template in [Contributing to this guide](#contributing-to-this-guide)._

### Web Persistence

#### Key Changes:

- `stream_chat_persistence` now runs sqlite3 as WebAssembly instead of through drift's deprecated sql.js
backend. Persistence works in apps compiled with `dart2wasm` for the first time; before, those builds fell
through to an implementation that threw `UnsupportedError`.
- The files you copy into `web/` changed: **remove** `sql-wasm.js` and `sql-wasm.wasm`, **add** `sqlite3.wasm`
and `drift_worker.js`. Take both from the same [drift release][drift-releases] — that is the only
combination guaranteed to be compatible.
- **Remove the `<script defer src="sql-wasm.js">` tag from `web/index.html`.** Nothing replaces it:
`drift_worker.js` is started by drift as a worker at runtime and must not be loaded into the page.
- `webUseExperimentalIndexedDb` is removed. drift now probes the browser and picks the most reliable storage it
supports on its own, which is what the flag was approximating.
- New `webOptions` parameter, taking a `StreamChatPersistenceWebOptions`, for pointing at the two files when they
are not served next to `index.html`.
- **Existing web caches are not migrated.** The first launch after upgrading starts from an empty offline cache
and refills it from the API. Nothing is lost that is not on the server — the local database is a cache — but the
first load on web hits the network.
- The storage drift chose is reported through the client's logger at `Level.INFO`, with a `WARNING` when the
browser can only offer storage that two open tabs could corrupt, and a `SEVERE` when it cannot persist at all.
- A cached database that cannot be opened is discarded and rebuilt from an empty one rather than failing
`connect`, so a cache damaged by a killed tab costs one extra sync instead of blocking sign-in.

#### Migration Steps:

**Before:**
```dart
final chatPersistentClient = StreamChatPersistenceClient(
logLevel: Level.INFO,
connectionMode: ConnectionMode.regular,
webUseExperimentalIndexedDb: true,
);
```
```html
<!-- web/index.html -->
<script defer src="sql-wasm.js"></script>
```

**After:**
```dart
final chatPersistentClient = StreamChatPersistenceClient(
logLevel: Level.INFO,
connectionMode: ConnectionMode.regular,
);
```
```html
<!-- web/index.html — no script tag needed -->
```

Copy `sqlite3.wasm` and `drift_worker.js` into `web/`, and serve your app with
`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` so Chrome and Safari
can use the origin private file system instead of IndexedDB. The
[package README](https://pub.dev/packages/stream_chat_persistence#flutter-web) has the per-browser table.

If the two files are hosted somewhere other than next to `index.html`:

```dart
final chatPersistentClient = StreamChatPersistenceClient(
webOptions: StreamChatPersistenceWebOptions(
sqlite3Uri: Uri.parse('/assets/sqlite3.wasm'),
driftWorkerUri: Uri.parse('/assets/drift_worker.js'),
),
);
```

The upgrade removes the two `localStorage` keys the old backend wrote (`moor_db_str_db_<userId>` and
`moor_db_version_db_<userId>`) on the first connect. If you opted into `webUseExperimentalIndexedDb`, its data
lives in an IndexedDB database named `moor_databases`, which is **not** removed automatically — that name is
shared with any other database your app opened through drift's legacy web backend, so deleting it is your call.

> **Why:** `package:drift/web.dart` is deprecated upstream and is built on `dart:html`, which does not exist
> under `dart2wasm` — so the old backend both blocked WebAssembly builds of consumer apps and was on a path to
> removal. The WebAssembly backend also stores data in the origin private file system or IndexedDB rather than a
> `localStorage` string, which removes the ~5 MB storage ceiling that came with the sql.js approach.

[drift-releases]: https://github.com/simolus3/drift/releases

---

## Migration Checklist
Expand Down
1 change: 1 addition & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

- Fixed reconnect state recovery surfacing an uncatchable error when the connection dropped again mid-recovery; it is now logged, and `connection.recovered` still fires. [#2910](https://github.com/GetStream/stream-chat-flutter/issues/2910)
- Fixed every failed websocket connect leaving an unhandled error in the root zone, which crash reporters listening on `PlatformDispatcher.onError` report as a fatal crash. [#2921](https://github.com/GetStream/stream-chat-flutter/issues/2921)
- Fixed `CurrentPlatform` throwing `UnimplementedError` on WebAssembly builds.

⚠️ Deprecated

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:meta/meta.dart' show visibleForTesting;
import 'platform_detector_stub.dart'
if (dart.library.html) 'platform_detector_web.dart'
if (dart.library.js_interop) 'platform_detector_web.dart'
if (dart.library.io) 'platform_detector_io.dart';

/// Possible platforms
Expand Down
1 change: 1 addition & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fixed a crash on web when the message list rebuilt while messages were selectable, for example after opening the attachment picker.
- Fixed the browser's native context menu reappearing over the message context menu on web after scrolling messages out of view or deleting one.
- Fixed the SDK re-enabling the browser's native context menu on web in apps that had disabled it themselves.
- Fixed `StreamAttachmentHandler` throwing `UnimplementedError` on WebAssembly builds.

## 10.3.0

Expand Down
Loading