Title: Discussion for possible `@angular/elements` public API changes · Issue #21585 · angular/angular · GitHub
Open Graph Title: Discussion for possible `@angular/elements` public API changes · Issue #21585 · angular/angular
X Title: Discussion for possible `@angular/elements` public API changes · Issue #21585 · angular/angular
Description: Possible @angular/elements public API (breaking) changes for discussion: Rename NgElementConstructor.is to NgElementConstructor.name. Background / Previous discussion Originally, we called this `selector`. @robwormald suggested renaming ...
Open Graph Description: Possible @angular/elements public API (breaking) changes for discussion: Rename NgElementConstructor.is to NgElementConstructor.name. Background / Previous discussion Originally, we called this `se...
X Description: Possible @angular/elements public API (breaking) changes for discussion: Rename NgElementConstructor.is to NgElementConstructor.name. Background / Previous discussion Originally, we called this `se...
Opengraph URL: https://github.com/angular/angular/issues/21585
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Discussion for possible `@angular/elements` public API changes","articleBody":"Possible `@angular/elements` public API (breaking) changes for discussion:\r\n\r\n- [ ] Rename `NgElementConstructor.is` to `NgElementConstructor.name`.\r\n \u003cdetails>\r\n \u003csummary>Background / Previous discussion\u003c/summary>\r\n Originally, we called this `selector`. @robwormald suggested renaming to `is` to match what Polymer does. `is` is special according to the spec when defining \"customized built-in elements\" (which we currently do not support, but might support in the future).\r\n\r\n @IgorMinar said:\r\n Shouldn't this be called `element-name`? You can't use other kind of selector anyway.\r\n\r\n @gkalpak said:\r\n ATM `selector` and `nodeName`/`element-name` mean pretty much the same thing. But if we add support for \"customized built-in elements\", then `is` will be more accurate. Or maybe `name` or `definedName`, which is what [the spec calls it](https://html.spec.whatwg.org/multipage/custom-elements.html#concept-custom-element-definition-name).\r\n\r\n @IgorMinar said:\r\n `name` would work for me.\r\n \u003c/details>\r\n\r\n##\r\n- [ ] Remove the `NgElementConstructor#upgrade()` method.\r\n \u003cdetails>\r\n \u003csummary>Background / Previous discussion\u003c/summary>\r\n This method can be used to upgrade any DOM element to an Angular Custom Element.\r\n AFAICT, the initial reasoning was to be able to support environments that do not natively support Custom Elements. But using polyfills instead would result in a much better (and uniform) experience.\r\n\r\n We could hide it from the public API, but keep the implementation in case it turns out to be useful.\r\n \u003c/details>\r\n\r\n##\r\n- [ ] Support using a component in Angular templates _and_ exporting it as a custom element (in the same app).\r\n The solution we had previously agreed on (for lack of a better alternative), was to prefix the selectors of Custom Elements. (So, if you define an Angular component with selector `foo-bar`, the Custom Element will be registered with selector `\u003cprefix>-foo-bar`.)\r\n \u003cdetails>\r\n \u003csummary>Background / Previous discussion\u003c/summary>\r\n **Issue:**\r\n ATM, when an Angular component is registered as a Custom Element, using it inside an Angular template causes it to be instantiated twice: Once by Angular’s compiler and once by the browser (which recognizes it as a Custom Element and calls its `connectedCallback()`). Essentially, there is no way to tell whether an element is part of an Angular view and therefore should not be treated as a custom element.\r\n\r\n **Example:**\r\n I want to publish my `\u003cfancy-button>` and `\u003cfancy-datepicker>` Angular components as Custom Elements (part of the same `NgModule`). `\u003cfancy-datepicker>` uses `\u003cfancy-button>` inside its template.\r\n\r\n **Ideal solution:** _(currently not possible)_\r\n Be able to detect from inside the `NgElementConstructor` (or at least the `connectedCallback()`) that something is inside an Angular view (e.g. in an Angular component’s template) and do nothing (i.e. not instantiate a component instance).\r\n\r\n **Possible work-arounds:**\r\n Use different selectors. E.g. `\u003cfancy-button>` inside Angular templates and `\u003cgk-fancy-button>` when used as a Custom Element.\r\n - _Option 1_: We could add a new optional property to the `@Component` decorator (e.g. `customElementSelector: string`), which would default to the value of the `selector` property (useful when there is no intention to use the same component both as a Custom Element and inside Angular templates on the same page).\r\n - _Option 2_: We could automatically prefix all selectors with a pre-defined (configurable) prefix when registering as custom elements (e.g. in `NgElements#register()`). So, `\u003cfancy-button>` would be (by default) registered as `'nge-fancy-button'` (where `nge` is a configurable prefix). This has the added benefit that essentially \"name-spaces\" the components and makes it easier to avoid conflicts between different Custom Element libraries. (Although, this might be a moot point, since it is already recommended to prefix your components with a custom prefix.)\r\n - _Option 3_: Have an annotation which would tell the compiler that this element is CE. This way the renderer could create the element with a marker which would inhibit the CE facade from doing anything.\r\n\r\n @mhevery said:\r\n The only way I can think of doing this is for Renderer to put an expando on the DOM elements. That way when elements facade wakes up it can check for the presence of the expando and short circuit itself. The expando would have some cost on the DOM creation.\r\n I think the easiest thing to do for now is to have a different prefix/suffix for the elements.\r\n\r\n @gkalpak said:\r\n Since the CE constructor is called before Angular instantiates the component, could we set a special property from the CE constructor that Angular could check and ignore the element?\r\n (Will that be compatible with AoT?)\r\n\r\n @mhevery said:\r\n I don't think that is something that we could do since it would mean that ALL Angular apps would be penalized with the check regardless if they are using `@angular/elements`. I think our solution will have to be such that the onus is on `@angular/elements` to do the check. It's the CE which has to be suppressed rather than the Angular component.\r\n So I think CE needs to be able to detect that Angular component is active and than become a noop. Not sure what is the best way to do that without penalizing everyone.\r\n One idea is that we change the renderer to put an expand on all elements which have a dash. The issue is that checking if `-` dash is present and than monkey patching is not free, especially if you have to do the check for each element. So maybe the check would have to be done at compile time and then at runtime we would have to pass an extra info to the renderer. (Or maybe we don't have to change the compiler but change the view engine to do the check once per view).\r\n \u003c/details>\r\n\r\n##\r\n- [ ] Remove the second signature of `registerAsCustomElements()`. \r\n \u003cdetails>\r\n \u003csummary>Background / Previous discussion\u003c/summary>\r\n ATM, `registerAsCustomElements()` supports two signatures:\r\n\r\n ```ts\r\n function registerAsCustomElements(\r\n customElementComponents: Type[],\r\n bootstrapFn: () => Promise\u003cNgModuleRef>): Promise\u003cNgModuleRef>;\r\n ```\r\n\r\n ```ts\r\n function registerAsCustomElements(\r\n customElementComponents: Type[],\r\n platformRef: PlatformRef,\r\n moduleFactory: NgModuleFactory): Promise\u003cNgModuleRef>;\r\n ```\r\n\r\n The second is just a shorthand for:\r\n \r\n ```ts\r\n registerAsCustomElements(\r\n customElementComponents,\r\n () => platformRef.bootstrapModuleFactory(moduleFactory))\r\n ```\r\n\r\n Unless there is any benefit to it (e.g. it is easier for the CLI to auto-rewrite for JiT/AoT, then I don't see any benefit in keeping both.\r\n\r\n \u003c/details>\r\n","author":{"url":"https://github.com/gkalpak","@type":"Person","name":"gkalpak"},"datePublished":"2018-01-17T11:11:10Z","url":"https://github.com/angular/angular/issues/21585"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4000b7b0-33f0-ed55-690d-5cd4d98530f3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEB2:3F8AB1:1C426C8:23EF62B:6B013FDC |
| html-safe-nonce | 82467e5e2b277e8d3156f134891f16318757c07b1fdccf2be37671b4b4f9aa46 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUIyOjNGOEFCMToxQzQyNkM4OjIzRUY2MkI6NkIwMTNGREMiLCJ2aXNpdG9yX2lkIjoiMTMwNzU5MDc4MjAzODkxNzA4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fa4e14fa0054984c9ecc8b15bbbb95b9f5dc4bf363d0544a9ae5d6c3ba4df77a |
| hovercard-subject-tag | issue:289227684 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/21585/issue_layout |
| twitter:image | https://opengraph.githubassets.com/abbfbd0bb8ed27172a433d0e8b5a44e623e1f2780f88874a6445d20bea255458/angular/angular/issues/21585 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/abbfbd0bb8ed27172a433d0e8b5a44e623e1f2780f88874a6445d20bea255458/angular/angular/issues/21585 |
| og:image:alt | Possible @angular/elements public API (breaking) changes for discussion: Rename NgElementConstructor.is to NgElementConstructor.name. Background / Previous discussion Originally, we called this `se... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gkalpak |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width