Skip to content

[breaking change] Remove Object from ExternalDartReference's implemented types #56015

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

Closed
srujzs opened this issue Jun 14, 2024 · 15 comments
Closed
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. breaking-change-approved breaking-change-request This tracks requests for feedback on breaking changes web-js-interop Issues that impact all js interop

Comments

@srujzs
Copy link
Contributor

srujzs commented Jun 14, 2024

Change Intent

dart:js_interop's ExternalDartReference allows users to pass opaque references to Dart objects such that they can be passed through JavaScript back to Dart efficiently. The library provides two extension methods: toExternalReference and toDartObject to convert to and from the opaque reference.

ExternalDartReference will now instead be generic and toExternalReference will return a reference to any T, including null. Therefore, the extension type can longer implement Object, as the representation type will be nullable.

Justification

ExternalDartReference should be generic to avoid extra downcasts when compiling to JS, and to be able to represent what type of Dart object the reference refers to.

On top of this, we should include null values i.e. T extends Object? instead of T extends Object, so that other generic interfaces e.g. Finalizer that have an unbounded T do not have to include extra null-checks to be able to convert to and from an ExternalDartReference.

Original issues: #55536, #55342

Impact

Low. There is low usage in two repos:

  1. Flutter engine in order to use the JS FinalizationRegistry. 0 1 2 3
  2. svelte_js.dart. The owner is the same user who originally filed the request.

Mitigation

Any assignment of ExternalDartReference to Object can instead be made an assignment to Object?. For example:

// Object o = 0.toExternalReference;
Object? o = 0.toExternalReference;
// void f(Object o) {}
void f(Object? o) {}

f(0.toExternalReference);

Change Timeline

The implementation is already done (see below). Ideally, this should go in beta 2 so that we don't have to wait for the next stable to submit this as breaking changes can't be submitted in the last beta.

Associated CLs

https://dart-review.googlesource.com/c/sdk/+/370663

@srujzs srujzs added web-js-interop Issues that impact all js interop breaking-change-request This tracks requests for feedback on breaking changes area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. labels Jun 14, 2024
@srujzs srujzs changed the title [breaking change] Remove Object? from ExternalDartReference's implemented types [breaking change] Remove Object from ExternalDartReference's implemented types Jun 14, 2024
@srujzs
Copy link
Contributor Author

srujzs commented Jun 14, 2024

@itsjustkevin I sent out an email to [email protected] for this. Let me know if you need anything else to start the review process. Thanks!

@kevmoo
Copy link
Member

kevmoo commented Jun 14, 2024

LGTM!

@sigmundch
Copy link
Member

Thanks @srujzs. Breaking change LGTM too.

cc @mkustermann

@mkustermann
Copy link
Member

mkustermann commented Jun 17, 2024

LGTM

As the API that's being changed is relatively new with limited users, I'd suggest to use an accelerated process to ensure the breaking change will land before the next stable (to minimize change of more users to start relying on the now-deprecated API)

@mkustermann
Copy link
Member

@mit-mit @vsmenon The cutoff for next stable seems to be 1st of July. Can we get this approved beforehand to ensure it's included in the next stable? (If we delay this, people may start relying on this API more widely and changing it will cause more trouble for ecosystem, so the sooner we do it the better)

@mit-mit
Copy link
Member

mit-mit commented Jun 21, 2024

LGTM

@mit-mit
Copy link
Member

mit-mit commented Jun 21, 2024

Please make sure to post on dart-announce

@sigmundch
Copy link
Member

Thanks, it was posted last week. Usage currently is extremely minimal, so we don't expect to hear much.

@mkustermann
Copy link
Member

@itsjustkevin Does it need signoff from anyone else or can this be marked as approved and @srujzs can go ahead and land the change?

@sigmundch
Copy link
Member

FYI @itsjustkevin is OOO this week. We believe he will be back next week.

@sigmundch
Copy link
Member

Looking at the updated calendar, it seems @itsjustkevin will be OOO until mid week. I reviewed previous breaking change requests and it appears we typically seek approval from representatives in Flutter and ACX as well.

@Hixie @leonsenft @vsmenon - could you take a look at this breaking change request? Thank you!

@leonsenft
Copy link

LGTM 👍

@Hixie
Copy link
Contributor

Hixie commented Jun 24, 2024

no objection from me. cc @yjbanov

@vsmenon
Copy link
Member

vsmenon commented Jun 25, 2024

lgtm

@sigmundch
Copy link
Member

Thanks everyone! Following the protocol, I went ahead and marked this breaking change as approved

@itsjustkevin - when you are back, is there anything else do to for this issue or is it OK to close it now?

@srujzs - we should be OK to move forward now ahead of the upcoming cutoff next week

@github-project-automation github-project-automation bot moved this from In review to Complete in Breaking Changes Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. breaking-change-approved breaking-change-request This tracks requests for feedback on breaking changes web-js-interop Issues that impact all js interop
Projects
Status: Complete
Development

No branches or pull requests

8 participants