Skip to content

[breaking change] No longer allow extending HtmlElement and other native types. #53264

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
sigmundch opened this issue Aug 17, 2023 · 16 comments
Closed
Assignees
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). breaking-change-approved breaking-change-request This tracks requests for feedback on breaking changes

Comments

@sigmundch
Copy link
Member

sigmundch commented Aug 17, 2023

Change Intent

We intend to disallow extending HtmlElement and other native types, this entails removing the .created constructors for types in dart:html and eventually marking those classes with the interface class modifier.

Justification

Historically, all native types were sealed within the SDK and couldn't be extended (using tricks like only providing factory constructors publicly). This was relaxed only to support custom elements v0.5 long time ago. Last year we deprecated and removed support for custom element (see #49536).

Now we would like to do some additional cleanup in our compilers to remove technical debt related to custom elements. To ensure users don't accidentally trip over old unsupported logic, we would like to make it a static error to use the unsupported patterns. Namely, that would be to make it a static error to extend from HtmlElement going forward.

Impact

Code like:

class A extends HtmlElement {
  A.created() : super.created();
}

will now give a compile-time error.

These classes could only be used in combination with the registerElement API that was removed with Dart 3.0, because of that we believe the impact of this change is limited. The change can affect only developers that removed calls to registerElement but left intact the classes associated with those calls on the previous breaking change. Note that those classes cannot be instantiated anymore, as such we think the impact of this change is pretty low. Given the correlation of the two APIs, we believe it will be rare for developers to encounter the breaking change.

Mitigation

The recommended mitigation is to remove the subclass,. In the rare case that such subclasses were used for mocking in tests, developers can use implements instead of extends to achieve their goals.

@sigmundch sigmundch added the breaking-change-request This tracks requests for feedback on breaking changes label Aug 17, 2023
@itsjustkevin
Copy link
Contributor

@sigmundch do you have a proposed timeline for possibly breaking users here? Will the method be deprecated for a while before it is removed?

@sigmundch
Copy link
Member Author

Even though this is a breaking change, we hope it is effectively not breaking because of the previous breaking change we did to custom elements. Because of that, we'd like to assess whether we can land this breaking change w/o a deprecation period. We will validate that indeed has the limited impact that we predict (both by looking at internal systems and waiting for community feedback), and if all goes well, we can hopefully land this in the next release.

@mit-mit mit-mit added the area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). label Aug 18, 2023
@kevmoo
Copy link
Member

kevmoo commented Aug 18, 2023

SGTM!

@sigmundch
Copy link
Member Author

quick update: an internal global presubmit of the breaking change had no failures. Implementation for the breaking change is here: https://dart-review.googlesource.com/c/sdk/+/321741

@sigmundch
Copy link
Member Author

friendly ping :)

@itsjustkevin
Copy link
Contributor

@Hixie @vsmenon @grouma

@vsmenon
Copy link
Member

vsmenon commented Sep 17, 2023

lgtm

@grouma
Copy link
Member

grouma commented Sep 18, 2023

LGTM

@Hixie
Copy link
Contributor

Hixie commented Sep 22, 2023

fine by me

@kevmoo
Copy link
Member

kevmoo commented Mar 8, 2025

What's the story here?

@kevmoo kevmoo removed their assignment Mar 8, 2025
@sigmundch
Copy link
Member Author

Unfortunately I think I dropped the ball here. We made the public breaking change announcement and, as we expected, there was no concern expressed. I believe we are good to move forward, we just need to rebase the change and push it though.

@natebiggs @srujzs - do you recall any other concerns, if not, would you be willing to take over the CL to push it through?

@kevmoo - I'm curious if you have an additional motivation here. On our end, the main benefit was to clean up tech debt in dart2js. Now that the entire library is marked as deprecated, the prioritization may be different.

@biggs0125
Copy link

Seems reasonable to push forward if we have good motivation. I'm not sure it makes sense to take on the additional cleanup right now. But given we have the CL and it looks like it shouldn't be too painful to rebase, we should go ahead and land it now. That way if we ever do choose to follow up with any of the extra custom element cleanup this doesn't become a blocker again.

@srujzs
Copy link
Contributor

srujzs commented Mar 10, 2025

I have no concerns here - I can go ahead and rebase the CL, do a TGP, and then land.

@sigmundch
Copy link
Member Author

thank you!

copybara-service bot pushed a commit that referenced this issue Mar 11, 2025
This change removes the `.created` constructor in the html
class hierarchy. These classes now only offer public factory
constructors. As a result, developers will no longer be able
to extend these classes in their libraries.

This is a breaking change, however we don't expect there to
be as much use of this feature (extending html element
classes). In particular, the ability to extend html elements
was intended for web components.  Dart only ever supported
the 0.5 spec of web components, which is old and long
deprecated.  Previously, in Dart 3.0, we removed APIs used
to register custom elements from `dart:html`, so the ability
to extend html elements has not been useful since then.

For more details see #53264

CoreLibraryReviewExempt: ddc/dart2js-specific library.
Change-Id: I43d8c9ae99dc83545e70e1f3b9dfc9f1b274a5c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321741
Reviewed-by: Lasse Nielsen <[email protected]>
Reviewed-by: Srujan Gaddam <[email protected]>
Reviewed-by: Stephen Adams <[email protected]>
Commit-Queue: Srujan Gaddam <[email protected]>
@srujzs
Copy link
Contributor

srujzs commented Mar 11, 2025

https://dart-review.googlesource.com/c/sdk/+/321741 has landed. @itsjustkevin I'll leave this open for your tracking purposes, but this should be resolved.

@sigmundch
Copy link
Member Author

Thanks so much for pushing it through!

@github-project-automation github-project-automation bot moved this from In review to Complete in Breaking Changes Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). breaking-change-approved breaking-change-request This tracks requests for feedback on breaking changes
Projects
Status: Complete
Development

No branches or pull requests

9 participants