-
Notifications
You must be signed in to change notification settings - Fork 644
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
Error for unrecognized tags #560
Comments
If you are using webcomponents, you will be able to list those tags in a The Error message will contain helpful info. Something like
|
An error should not be thrown -- https://html.spec.whatwg.org/multipage/scripting.html#custom-elements |
@jsumners see the comment from @mlrawlings above. The idea is that you would need to whitelist the custom elements by registering them in your project's src/marko.json: {
"<my-custom-element>": { /* empty */ }
} It's a tradeoff, but I am in favor of catching problems earlier at compile-time. |
That just goes back to the boilerplate issue I opened a while back -- lasso-js/lasso-marko#3 Now, if the parser encounters |
I suppose we could come up with a way for declaring non-standard tags as being tags that should passthrough. For example:
I'm not saying that is a good idea, but I am just through that out there. Personally, I think registering the tag in |
We do already throw errors for mismatched tags. This may come up more in concise mode since the tag does not need to be repeated, but also in HTML when using the self-closing syntax. I'm not sure this is a good idea, but we could have a global "off" switch for this behavior if there are users that are heavily using Custom Elements and don't wish to list them all. If there was info about how to do that in the docs linked in the error I think that would eliminate any potential confusion. |
I think @jsumners has a point. It might only make sense to throw an error on a would-be concise tag. My vote is for disabling concise mode by default (with exceptions for |
I'm definitely against this being the default, but I would love to have this as an opt-in setting. |
I can definitely see how having many tags to whitelist would be annoying. For example a-frame has 20+ custom tags implemented as web components. But if we allowed you to whitelist patterns like @Hesulan If we're doing this it needs to be the default as one of the big reasons for these kind of helpful error messages is to help beginners who likely won't realize there's some way to opt-in to warnings. @mindeavor
While we could put some modifier in the template (e.g. Root level text would also be an issue if there was some global way to turn concise on or off because what would be parsed as text in HTML mode would be parsed as concise tags in concise mode. |
I'm not convinced this is the right idea, but we could also only have the warning for tags names without dashes in their name. Custom Elements require hyphens in their names so we wouldn't catch those tags with this rule. |
When building a complex project you will often need to rename a UI component. It would be really nice if you could recompile all of your templates to figure out exactly which UI components broke as a result of the name change. I'm strongly in favor of throwing an error when the Marko detects an unrecognized tag as long as we get the error message perfect (the developer should know exactly what to do to register the tag and it should be super simple). |
Sorry, I meant a global flag. Something like |
That won't work because the syntax highlighter would not have that context and do syntax highlighting independently. |
Can there not be two highlighter definitions? Sublime supports it, at least. Someone enabling |
Whitelisting tags is decent, but whitelisting tags b/c hopefully someday somebody will use concise-mode is making the wrong tradeoff in my mind. Disable concise-mode by default. All (most) issues with top-level tags magically go away (eg: the following gem
|
@mindeavor @ramses0 How would disabling concise mode actually solve the problem being discussed, which is whether to throw an error when an invalid tag is encountered? I understand that you don't like the syntax, but many of us do and are using it in production. P.S.: You can use HTML syntax for the new tags, too: |
@Hesulan - root level text is terrible. My vote is for putting it into a The current single-file-component format has the benefit that it is backed by working code, but as an outsider / recreational user of markojs, I see it as full of traps for implementors and users, especially compared to non-single-file-components. It also appears as though you can't really opt out of single-file component mode either. |
@Hesulan I don't dislike concise mode per se; I only point out that supporting both concise and normal syntax at the same time is the root of all these problems. If concise were opt-in, all the pitfalls disappear (or at least be hidden behind a global flag). |
@ramses0 Single-file components are still entirely optional, they're just more convenient than writing a separate I do understand preferring HTML over concise, and it's my opinion that the official documentation should try to use HTML syntax as much as possible (even though I almost always use concise). |
@mindeavor I'm still unclear on how disabling concise syntax would solve the problem, or how it's at the root of it. |
If concise were disabled, @ramses0's examples of surprises would no longer be surprising; they would do what you'd expect in any HTML document. this is
for
you
<h1>Test</h1>
var not_a_var = "this is just text, just like HTML"
for this is text as well!
${ "interpolated" + "value" }
$ console.log("this is JS code. Iffy, but acceptable")
I am plain text
<my-custom-element>
No problems here
</my-custom-element> |
+1 for throwing an error. Many complex projects rely on knowing when there is an issue with an unknown or incorrect tag. |
@mindeavor I'm not sure what that has to do with throwing errors for invalid tag names, and those are all just different examples of the same thing - plain text as a root element. @patrick-steele-idem On further thought, I think I would agree with throwing errors by default, as long as it's easy to disable and clearly documented. |
@Hesulan As clarification, the idea for this originally stemmed from the discussion we (@mindeavor, @ramses0 and I) had on how to reduce any confusion around syntax, specifically concise syntax at the root, but I think it has enough merit to stand on its own. That it would throw an error for unintentional concise tags at the root is only one benefit. |
Related to this, Patrick and I are looking at creating a "standard" of sort that could be adopted by web component libraries to make their custom tags visible to tooling. Marko's autocomplete in Atom was originally forked from We're thinking that we could submit a PR back to the original package that would support discovering an This would allow a web component package to simply add this file (which could be generated) and autocomplete would be made available to the And of course so would Marko. If we could get the web community to adopt this, it would mean you might never (or rather, rarely) have to add definitions/exceptions for third-party custom element tags on your own. That's definitely a big "IF", but between reaching out to other developers, possibly making some PRs to popular libraries and the fact that there's benefit to the libraries and end users (it's not purely driven by a need of Marko) it could very well work. |
Great idea. I fully support that. |
@Hesulan Saving people from root-level text is the whole point of this thread, isn't it? It's only a problem because of automatic concise mode.
|
@mindeavor Ah, I see what you meant now. That's not the point though, the point is to catch invalid tag names. Root level text in concise mode is just one of the many ways that a typo could slip past, and to simply disable such a widely used feature by default would be a huge overreaction and wouldn't solve the problem of invalid tag names. Catching accidental root-level concise tags is only a nice side-effect of the proposed solution. |
@Hesulan I know the goal is to prevent typos, but the only reason this came up is because of concise mode. After all, any custom element tag is valid HTML. In principle there should be no errors thrown, because an unknown tag is 100% valid in the browser. However, in practice I don't feel that strongly about it, and wouldn't mind if these errors made it in. Actually, this just dawned on me – custom element tags are only valid HTML if they contain a dash within the name. Since JavaScript keywords nor identifiers can contain dashes, doesn't that mean there is only a reason to throw errors on unrecognized single-word tags? |
@mindeavor From what I understood, the reason this came up is because if you type something like I do think only throwing on single-word tags is a reasonable condition, and I believe @mlrawlings mentioned something similar earlier in this thread. |
oops, I totally missed his comment on that :) |
I still think starting with throwing on all unrecognized tags is a sane default and the error message would point you to information on how to configure things: Configuring in
|
@mlrawlings would you be in favor of splitting out the potential discussion: "require concise mode to be explicitly opted in to"? I believe it would require:
...which makes total sense to me. Or a flag to explicitly opt out of the potential bugginess / confusion of mixing concise-mode, markojs single file components, javascript, and HTML? I keep hearing |
For the record, I now believe this was the right choice. After upgrading to rc.13, marko immediately informed me about two invalid tags that I forgot to change during a rename! 😄 |
@mindeavor I experienced the same thing. We had some tests that were incorrectly referring to unregistered tags. I'm not very impressed with the Github Wiki system, but we decided to put details on errors in the Wiki: https://github.com/marko-js/marko/wiki/Error%3A-Unrecognized-Tag Please let us know if you see any issues! |
Currently, if you have a template with the following
<some-tag-that-does-not-exist/>
The following HTML will be output:
We should instead throw an Error if the tag is not a standard HTML tag or has not been defined as a Marko custom tag. This will help catch typos as well as users who might accidentally write concise style tags at the root when they meant text (or tried to write JS).
The text was updated successfully, but these errors were encountered: