Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core, web): migrate web to js_interop to be compatible with WASM #12031

Merged
merged 10 commits into from Jan 10, 2024

Conversation

Lyokone
Copy link
Contributor

@Lyokone Lyokone commented Dec 13, 2023

Description

  • Migrate usage of dart:html to package:web
  • Migrate usage of dart:js, dart:js_util, and package:js to dart:js_interop

Related Issues

#12027

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@Lyokone Lyokone changed the title Feat/migrate web js interop feat(core, web): migrate web to js_interop to be compatible with WASM Dec 13, 2023
@Lyokone Lyokone marked this pull request as ready for review January 2, 2024 10:09
if (js_util.getProperty(e, 'name') == 'FirebaseError') {
String rawCode = js_util.getProperty(e, 'code');
FirebaseException _catchJSError(JSObject e) {
if (e.getProperty<JSString?>('name'.toJS)?.toDart == 'FirebaseError') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid code, but I'd use an interface to make this more readable. Here's an example:

@JS()
@staticInterop
class JSError {}

extension on JSError {
  external String? get name;
  external String? get message;
  external String? get code;
} 

which would let you write simpler code like:

if (e.name == 'FirebaseError')

return r.code ?? ''

and so forth. You may not have access to extension types since that will require >=3.3, but it's even more concise with one:

extension type Error(JSObject e) {
  external String? get name;
  external String? get message;
  external String? get code;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I've updated this as well.
We don't have access to Dart 3.3 yet, but I'll keep in mind to revisit this once Flutter supports it


@JS()
external List<AppJsImpl> getApps();
// List<AppJsImpl>
external JSArray getApps();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once AppJsImpl is moved to an extension type that implements JSObject, this can be JSArray<AppJsImpl>, and a cast won't be needed above, but for now this is the best alternative. :/

@@ -67,7 +67,7 @@ class FirebaseCoreWeb extends FirebasePlatform {
/// own risk as the version might be unsupported or untested against.
@visibleForTesting
String get firebaseSDKVersion {
return context['flutterfire_web_sdk_version'] ??
return globalContext.getProperty('flutterfire_web_sdk_version'.toJS) ??
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this works without a toJS as this returns a JSAny? iirc. Should this be globalContext.getProperty<JSString?>('flutterfire_web_sdk_version'.toJS)?.toDart? Or perhaps more concisely, (globalContext['flutterfire_web_sdk_version'] as JSString?)?.toDart?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, surprinsinlgy, declaring it in a variable triggered an analyzer error that wasn't triggered using ??
I've updated with your version

@Lyokone Lyokone merged commit 96f79d2 into master Jan 10, 2024
20 of 21 checks passed
@Lyokone Lyokone deleted the feat/migrate-web-js-interop branch January 10, 2024 10:35
@firebase firebase locked and limited conversation to collaborators Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants