fix(core,web): compile isA checks on Dart < 3.12 - #18612
Conversation
isA is only available on Object? from Dart 3.12, but catch (e) is Object and firebase_core_web still supports sdk ^3.6.0. Use is! JSError so web still compiles on Flutter 3.35/3.38 without raising the SDK constraint.
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
Summary
firebase_core_web3.11.0 fails to dart2js on Flutter < 3.44 (The method 'isA' isn't defined for the type 'Object').as JSErrorcast (same pattern as #18176, not covered by that fix) #18548 behavior: Dart exceptions fromguardNotInitialized()(e.g.core/not-initialized) are rethrown instead of being force-cast toJSError.sdk: ^3.6.0).Why
is! JSErrorinstead ofisA#18552 added
e.isA<JSObject>()oncatch (e)so we could distinguish JS Firebase errors from Dart exceptions without aninvalid_runtime_check_with_js_interop_typesignore.That only compiles on Dart ≥ 3.12.
isAlived onJSAny?until 3.12, when it moved toNullableObjectUtilExtension on Object?(Dart changelog).catch (e)typeseasObject, so on Dart 3.6–3.11 the extension does not apply.FlutterFire CI did not catch this: web jobs run on floating
stable(currently Flutter 3.44 / Dart 3.12). Users still on Flutter 3.35 / 3.38 (Dart 3.9 / 3.10) — whichsdk: ^3.6.0still allows — cannot compile for web.Raising the constraint to
^3.12.0would “fix” the compile error by refusing to resolve on those SDKs. That would drop Flutter 3.35/3.38, which is a much larger break than this patch.So this PR uses
e is! JSErrorwith the same lint ignore already used in FlutterFire web (firebase_auth_web,cloud_functions_web, and this file’sflutterfire_ignore_scriptspath). That:as JSErrorcast (same pattern as #18176, not covered by that fix) #18548 fix)FirebaseErrors through_getJSErrorCode/_catchJSErrorWe do not use
(e as JSAny).isA<JSObject>()to keep callingisA. That recasts Dart exceptions into JS types and can reintroduce the #18548TypeError, especially on dart2wasm.Test plan
flutter test --platform chromeinpackages/firebase_core/firebase_core_web(covers the [firebase_core_web]: FirebaseCoreWeb.app() masks the real error with an unsafeas JSErrorcast (same pattern as #18176, not covered by that fix) #18548core/not-initializedregression test)flutter build webagainst this package on Flutter 3.35 or 3.38 (the reported failure)flutter build webon current stable (3.44+) still succeeds