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

[Bug] Arguments are lost when passed to Glimmer components via the {{component}} helper #19061

Closed
samselikoff opened this issue Jul 29, 2020 · 7 comments · Fixed by #19148
Closed

Comments

@samselikoff
Copy link
Contributor

🐞 Describe the Bug

The order in which named arguments are passed into the {{component}} helper seems to affect the values for corresponding properties on the this.args object if the referenced component is a Glimmer component.

In particular, all arguments other than the first one passed seem to not end up on the this.args object.

🔬 Minimal Reproduction

Here's a Twiddle: https://ember-twiddle.com/2fd6f1de858f527a8f29c9f31c4b7c5b?openFiles=templates.application%5C.hbs%2Ctemplates.components.my-component%5C.hbs

Note that in the first instance of my-component, this.args.one is "a" and this.args.two is undefined, while for the second instance, this.args.one is undefined and this.args.two is "b".

The only difference in the two invocations is the order the named arguments are passed.

😕 Actual Behavior

Only the first argument is assigned to the corresponding property on the this.args object.

🤔 Expected Behavior

All arguments are assigned to their corresponding properties on the this.args object.

🌍 Environment

  • Ember: - 3.18.1
@rwjblue
Copy link
Member

rwjblue commented Jul 29, 2020

This is strange indeed!

@rwjblue
Copy link
Member

rwjblue commented Jul 29, 2020

One thing to note (generally speaking) is that you probably should not use this.args.xxx in templates (ember-template-lint's no-args-paths rule will flag that) and instead you should use @xxx (I assume you probably just did this for demonstration purposes though). This is totally orthogonal to the bug here though (it still doesn't work with {{@two}}).

As an aside, ember-template-lint@2 (current release) removes all "stylistic" rules (I recall you disliking the preferences RE: attribute/block indentation) and the recommended set focuses on prevent actual bugs (similarly to what eslint's recommended does now).

@samselikoff
Copy link
Contributor Author

Ok good to know! And yes it was just for purposes of boiling it down to simplest example. In my EmberMap demo I was accessing this.args in an action (for purposes of routing). That’s ok right?

Also good to know re: updates to template-lint!

@rwjblue
Copy link
Member

rwjblue commented Jul 29, 2020

In my EmberMap demo I was accessing this.args in an action (for purposes of routing). That’s ok right?

Yep, absolutely! And regardless of {{this.args.xxx}} this should still work, it was just a semi-random aside.

@KrishnaRPatel
Copy link
Contributor

To add to this strangeness, adding any one of a large subset of characters (any alphanumeric character, $, ?, and probably others I haven't tested) to the n+1th argument name will render the right property. Example: {{component 'my-component' one="a" $two="b"}} will render.

Even more strange, this seems to work if you stick to the {{this.args.propertyName}} syntax but not for @propertyName. I can't find exactly where the argument strings passed to the component helper are parsed just this moment but I'd love to tackle this if at all possible!

See the forked gist here with more arguments to highlight the difference: https://ember-twiddle.com/e8ada6977f22dcd91e2f533d9f654106?openFiles=templates.application%5C.hbs%2Ctemplates.components.my-component%5C.hbs

@mtrunt
Copy link

mtrunt commented Aug 3, 2020

I also found this issue. After some debugging I found that all the attributes are passed, however the first character is removed for all the attributes after the first one.

e.g.

{{component "my-component"
  first=1
  second=2
  third=3
}}

will have the hash

{
  first: 1,
  econd: 2,
  hird: 3
}

Right now adding an extra character to the rest of the attributes, while not ideal, works fine.

rreckonerr added a commit to rreckonerr/glimmer-vm that referenced this issue Sep 21, 2020
Because iterator was not working as expected.
 `@` character was not applied to all of the @arg names in hash array,
 except for the first argument. It resulted in
 `[["@firstArg", "secondArg"], ["valOne", "valTwo"]]`, instead of
 `[["@firstArg", "@secondArg"], ["valOne", "valTwo"]]`

 Fixes emberjs/ember.js#19061
rreckonerr added a commit to rreckonerr/glimmer-vm that referenced this issue Sep 21, 2020
Because iterator was not working as expected.
 `@` character was not applied to all of the @arg names in hash array,
 except for the first argument. It resulted in
 `[["@firstArg", "secondArg"], ["valOne", "valTwo"]]`, instead of
 `[["@firstArg", "@secondArg"], ["valOne", "valTwo"]]`

 Fixes emberjs/ember.js#19061
@rwjblue
Copy link
Member

rwjblue commented Sep 22, 2020

The fix landed upstream, but reopening until we've landed the fix here in Ember.

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

Successfully merging a pull request may close this issue.

4 participants