Skip to content

feat: Add isolate bootstrap helper for Amplify platform channels (#5302) - #7269

Draft
cadivus wants to merge 1 commit into
feat/isolate-spike-bg-messengerfrom
feat/isolate-bootstrap-helper
Draft

feat: Add isolate bootstrap helper for Amplify platform channels (#5302)#7269
cadivus wants to merge 1 commit into
feat/isolate-spike-bg-messengerfrom
feat/isolate-bootstrap-helper

Conversation

@cadivus

@cadivus cadivus commented Aug 12, 2026

Copy link
Copy Markdown
Member

PR2 of the #5302 stack, on top of #7266. Purely additive — no existing file modified, not exported from the barrel, so single-isolate behaviour is unchanged.

  • Adds ensureAmplifyIsolateInitialized(token) / amplifyRootIsolateToken / amplifyIsolateIsInitialized in packages/amplify/amplify_flutter/lib/src/amplify_isolate.dart. Home is amplify_flutter, not amplify_core: RootIsolateToken and BackgroundIsolateBinaryMessenger are Flutter types and amplify_core is deliberately Flutter-free.
  • @internal for now — promoting later is additive and non-breaking, while shipping it publicly now would commit us under semver before multi-isolate works end to end (the native SDK still rejects a second configure()). Recommend promoting in the PR that lands the broker + docs + example.
  • Two sharp edges the helper absorbs: it is a no-op on the root isolate (registering a background messenger there would replace the root's platform message handler), and amplifyRootIsolateToken returns null on web because RootIsolateToken.instance throws UnsupportedError there rather than returning null.
  • 9 tests, 7 of them running in CI on the VM (root/secondary behaviour, idempotency, root no-op); 2 web tests run by hand with --platform chrome since this package's CI is VM-only. Top-level functions rather than AmplifyIsolate.ensureInitialized because amplify_lints bans avoid_classes_with_only_static_members.

Purely additive. No existing file is modified, and the helper is not exported
from `amplify_flutter`'s barrel, so single-isolate behaviour is unchanged.

A secondary isolate already gets its own isolate-local Amplify state, but no
`BinaryMessenger`, so any plugin backed by a platform channel fails there.
`ensureAmplifyIsolateInitialized` repairs that from the root isolate's token.

Lives in `amplify_flutter` rather than `amplify_core`: `RootIsolateToken` and
`BackgroundIsolateBinaryMessenger` come from Flutter, and `amplify_core` is
deliberately Flutter-free.

Marked `@internal` for now. Promoting it later is additive and non-breaking,
whereas shipping it publicly now would commit us under semver before the
end-to-end story exists.

Two behaviours the helper absorbs so callers do not have to:
- No-op on the root isolate. Registering a background messenger there would
  replace the root isolate's platform message handler.
- `amplifyRootIsolateToken` returns null on web. `RootIsolateToken.instance`
  throws `UnsupportedError` there rather than returning null.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.03%. Comparing base (5f163d7) to head (dd1b8fd).

Additional details and impacted files
@@                         Coverage Diff                         @@
##           feat/isolate-spike-bg-messenger    #7269      +/-   ##
===================================================================
+ Coverage                            40.98%   41.03%   +0.04%     
===================================================================
  Files                                  121      122       +1     
  Lines                                 8273     8285      +12     
  Branches                              3598     3607       +9     
===================================================================
+ Hits                                  3391     3400       +9     
- Misses                                4882     4885       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants