Skip to content
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

passing @arguments to regular html elements doesn't give a great error message #18951

Closed
fivetanley opened this issue May 6, 2020 · 9 comments · Fixed by glimmerjs/glimmer-vm#1102 or #18982

Comments

@fivetanley
Copy link
Member

Twiddle: https://ember-twiddle.com/83bd6cc98d5038094a80cc21c11c98cb?openFiles=templates.application%5C.hbs%2C
Ember Version: 3.17.0

Tried searching for this one but apologies if I couldn't find it.

Given:

<div @someProperty={{action "foo"}}></div>

The following error appears at runtime:

jquery.js:3827 Uncaught TypeError: func is not a function
    at StatementCompilers.compile (VM32 ember.debug.js:43121)
    at compileStatements (VM32 ember.debug.js:44323)
    at maybeCompile (VM32 ember.debug.js:44312)
    at CompilableTemplateImpl.compile (VM32 ember.debug.js:44292)
    at Object.evaluate (VM32 ember.debug.js:51011)
    at AppendOpcodes.evaluate (VM32 ember.debug.js:49382)
    at LowLevelVM.evaluateSyscall (VM32 ember.debug.js:52284)
    at LowLevelVM.evaluateInner (VM32 ember.debug.js:52240)
    at LowLevelVM.evaluateOuter (VM32 ember.debug.js:52232)
    at JitVM.next (VM32 ember.debug.js:53175)

Would it be possible to give a better error message at runtime like @arguments are not allowed on regular html elements ?
Would it be possible for this to be an error at compile time?

@rwjblue
Copy link
Member

rwjblue commented May 6, 2020

I definitely think that the error should be much better here.

@fivetanley
Copy link
Member Author

fivetanley commented May 6, 2020

@rwjblue is this the kind of thing we would want to implement at the template compiler level in glimmer, or is it intentionally undefined behavior to have arguments passed to regular html nodes in glimmer to open up future possibilities?

@chancancode
Copy link
Member

I think fixing it in the compiler seems good. I think the code was just too dynamic (ie TypeScript didn’t help) and so this combination was missed. Don’t think it was intentional. That said if it’s easier to do it in ember as an ast plug-in, or because we have more information (file name and stuff) that’s fine too.

@deanpapastrat
Copy link

deanpapastrat commented May 8, 2020

We recently had an outage in one of our sites at Square since we had an @size attribute accidentally attached to an "a" tag in a page header in what happened to be an untested code path during a migration, and it caused the entire site to fail to render. It was near impossible for us to figure out since there's no description of what's failing in a way that Sentry could useful data for: just Cannot read property 'syscall' of null.

Is there any way we could make this warn in production, and not break the entire render cycle? In its current state, it's dangerous; at the end of day, everyone will accidentally write bugs or mis-type things, and this is a pretty harsh penalty to pay.

This was on ember-source version 3.18.1

@deanpapastrat
Copy link

And, added a PR for a lint rule to prevent this at lint time, which should help other people encountering this in the future: ember-template-lint/ember-template-lint#1332

@chancancode
Copy link
Member

IMO, we should just fix it as a compile-time syntax error (either in glimmer-vm or in ember)

@rwjblue
Copy link
Member

rwjblue commented May 9, 2020

Yep, agreed. Doesn't hurt to land the template lint rule also, but it is just a stop gap for fixing it in the VM.

fivetanley added a commit to fivetanley/glimmer that referenced this issue May 18, 2020
Adds an error message in the compile phase to inform the developer that
`@arguments` are not allowed on HTML nodes. This can often come from
copy/pasting refactoring errors.

For example, given the following template:

Before, the developer would get a vague error at runtime ([Example taken from
ember.js#18951](emberjs/ember.js#18951)):

```
jquery.js:3827 Uncaught TypeError: func is not a function
    at StatementCompilers.compile (VM32 ember.debug.js:43121)
    at compileStatements (VM32 ember.debug.js:44323)
    at maybeCompile (VM32 ember.debug.js:44312)
    at CompilableTemplateImpl.compile (VM32 ember.debug.js:44292)
    at Object.evaluate (VM32 ember.debug.js:51011)
    at AppendOpcodes.evaluate (VM32 ember.debug.js:49382)
    at LowLevelVM.evaluateSyscall (VM32 ember.debug.js:52284)
    at LowLevelVM.evaluateInner (VM32 ember.debug.js:52240)
    at LowLevelVM.evaluateOuter (VM32 ember.debug.js:52232)
    at JitVM.next (VM32 ember.debug.js:53175)
```

Now, they get an error message that looks like:

```
SyntaxError: ${attribute.name} is not a valid attribute name. @arguments
are only allowed on components, but the tag for this element
(\`${elementNode.tag}\`) is a regular, non-component HTML element. (location
line and column)
```

Given that there's no special behavior glimmer adds for `@arguments` on regular
HTML nodes, and it seems invalid to put `@` in attribute names in regular HTML
(validator.w3c.org gives ` Attribute @OnClick is not serializable as XML 1.0`
error message for the example template below), it seems helpful for the glimmer
compiler to fail at build time to prevent copy/paste errors and mistakes.

Fixes emberjs/ember.js#18951
@fivetanley
Copy link
Member Author

opened glimmerjs/glimmer-vm#1102 to help address this

fivetanley added a commit to fivetanley/glimmer that referenced this issue May 18, 2020
Adds an error message in the compile phase to inform the developer that
`@arguments` are not allowed on HTML nodes. This can often come from
copy/pasting refactoring errors.

For example, given the following template:

Before, the developer would get a vague error at runtime ([Example taken from
ember.js#18951](emberjs/ember.js#18951)):

```
jquery.js:3827 Uncaught TypeError: func is not a function
    at StatementCompilers.compile (VM32 ember.debug.js:43121)
    at compileStatements (VM32 ember.debug.js:44323)
    at maybeCompile (VM32 ember.debug.js:44312)
    at CompilableTemplateImpl.compile (VM32 ember.debug.js:44292)
    at Object.evaluate (VM32 ember.debug.js:51011)
    at AppendOpcodes.evaluate (VM32 ember.debug.js:49382)
    at LowLevelVM.evaluateSyscall (VM32 ember.debug.js:52284)
    at LowLevelVM.evaluateInner (VM32 ember.debug.js:52240)
    at LowLevelVM.evaluateOuter (VM32 ember.debug.js:52232)
    at JitVM.next (VM32 ember.debug.js:53175)
```

Now, they get an error message that looks like:

```
SyntaxError: ${attribute.name} is not a valid attribute name. @arguments
are only allowed on components, but the tag for this element
(\`${elementNode.tag}\`) is a regular, non-component HTML element. (location
line and column)
```

Given that there's no special behavior glimmer adds for `@arguments` on regular
HTML nodes, and it seems invalid to put `@` in attribute names in regular HTML
(validator.w3c.org gives ` Attribute @OnClick is not serializable as XML 1.0`
error message for the example template below), it seems helpful for the glimmer
compiler to fail at build time to prevent copy/paste errors and mistakes.

Fixes emberjs/ember.js#18951
fivetanley added a commit to fivetanley/glimmer that referenced this issue May 18, 2020
Adds an error message in the compile phase to inform the developer that
`@arguments` are not allowed on HTML nodes. This can often come from
copy/pasting refactoring errors.

For example, given the following template:

```handlebars
<a href="https://emberjs.com" @OnClick={{action "foo"}}>Ember.js</a>
```

Before, the developer would get a vague error at runtime ([Example taken from
ember.js#18951](emberjs/ember.js#18951)):

```
jquery.js:3827 Uncaught TypeError: func is not a function
    at StatementCompilers.compile (VM32 ember.debug.js:43121)
    at compileStatements (VM32 ember.debug.js:44323)
    at maybeCompile (VM32 ember.debug.js:44312)
    at CompilableTemplateImpl.compile (VM32 ember.debug.js:44292)
    at Object.evaluate (VM32 ember.debug.js:51011)
    at AppendOpcodes.evaluate (VM32 ember.debug.js:49382)
    at LowLevelVM.evaluateSyscall (VM32 ember.debug.js:52284)
    at LowLevelVM.evaluateInner (VM32 ember.debug.js:52240)
    at LowLevelVM.evaluateOuter (VM32 ember.debug.js:52232)
    at JitVM.next (VM32 ember.debug.js:53175)
```

Now, they get an error message that looks like:

```
SyntaxError: ${attribute.name} is not a valid attribute name. @arguments
are only allowed on components, but the tag for this element
(\`${elementNode.tag}\`) is a regular, non-component HTML element. (location
line and column)
```

Given that there's no special behavior glimmer adds for `@arguments` on regular
HTML nodes, and it seems invalid to put `@` in attribute names in regular HTML
(validator.w3c.org gives ` Attribute @OnClick is not serializable as XML 1.0`
error message for the example template below), it seems helpful for the glimmer
compiler to fail at build time to prevent copy/paste errors and mistakes.

Fixes emberjs/ember.js#18951
@rwjblue rwjblue reopened this May 18, 2020
@rwjblue
Copy link
Member

rwjblue commented May 18, 2020

(reopened to track landing the fix in Ember)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants