-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Templating creates unwanted custom elements #549
Comments
We aren't changing this. This convention-based approach is fundamental to Aurelia and is one of the reasons why people choose Aurelia. |
If you want to create a feature to configure Aurelia to opt-out of this, that's an option. But we can't change this all up. That would be devastatingly destructive. |
@EisenbergEffect From the official documentation
I don't see a mention that classes with random names are converted to custom elements. This is what happened in aurelia/dialog#283: a class that was not meant to be a custom element, named just |
Re-posting here from aurelia/dialog#283 (comment) Since it seems that this would be quite a breaking change, since the behavior is a "supported" (even if slightly discouraged) scenario -- is there a much easier (low risk) fix here? Without breaking things, it doesn't seem like you can reasonably stop people from exporting a module that matches a dom thing -- but honestly if you do that -- you are on your own. But because in this case it isn't the user naming it, it is webpack changing the names, could the template stuff just be protected from using single-letter names? Which I would think would cover the majority (if not all) of these issues caused by webpack name shortening. OR is there way to to control the webpack name shortening to include some prefix (I have no idea of the allowable characters in a module name -- but say $) so that they would never conflict with a dom element? |
User @eamodio made some good points in the original Apparently, using custom elements with no decorator and no naming convention is a thing.
So it's discouraged, but supported. I'm afraid making the Yet I still believe we have an important bug that more and more users of As a reminder, the bug arises from the fact that import { MyDialog } from 'dialogs/whatever';
dialogService.open({ viewModel: MyDialog }); Somehow, Maybe an alternative fix is to only allow convention-less custom elements when going through |
@jods4 but isn't it worse than that?
Because webpack shortens the name of |
@eamodio The situation is indeed worse now that tools like Webpack rename the imports, which can create custom elements for But fundamentally, I don't think renaming is the cause of the issue. It just makes it worse/more visible. |
Yeah, for me that makes it dramatically worse -- because it isn't self inflicted. And doubly so, because the errors it causes are so far removed from the actual problem -- we spun for the better part of a day trying to figure out what was going on (before we found the github issue about it) during our (ongoing) conversion from systemjs/jspm to webpack. |
This seems quite an urgent issue since WebPack is now the default in Aurelia/Cli. |
Ok, thanks to @bigopon, the problem goes away by using |
This workaround for |
@sflanker tou can refactor eitber in the user of the view model, or the view model itself by giving it an explicit name via a |
@bigopon So if I simply explicitly decorate every dialog viewModel type, I can safely continue to references these view models using the type name imported using an ES style import? That is good news 🙏 Just to clarify to be sure I understand the workaround:
|
@sflanker yes thats exactly it |
I am editing this issue, the original text is below.
I originally thought that the root of the problem was Aurelia creating custom elements from exports without convention nor decorator. But from comments below it was clarified that this is actually supported in some scenarios.
With this in mind, I now think that the root of the problem is that Aurelia should not register a local custom element when instantiating a dialog like so:
This code should not result in the registration of a
<my-dialog>
custom element.It is mostly harmless, but if your exported name clashes with other tags it's breaking the app.
From aurelia/dialog#283:
When loading a component (e.g. a view model for a dialog, a page to be loaded in the router, etc.),
aurelia-templating
falls back to creating a custom element based on the exported component name.I think the logic for that is here:
templating/src/module-analyzer.js
Line 253 in 7693dbd
Now consider what happens if I choose to name my ViewModel
export class A { }
. When used by a dialog or router, it will create a<a>
custom element, which is of course unwanted and will trigger bugs if there are links in the template.Expected behavior:
Only classes decorated with
@customElement
or following a convention (by default ending inCustomElement
) should create custom elements.The text was updated successfully, but these errors were encountered: