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

[BUGFIX] Prevent accidental dynamic component lookup #1152

Merged
merged 1 commit into from
Sep 2, 2020

Conversation

pzuraq
Copy link
Member

@pzuraq pzuraq commented Sep 2, 2020

Dynamic components invoked via {{component}} share a codepath with
ones invoked via <this.foo>, and because of that currently if
<this.foo> is a referring to a string, it will dynamically lookup the
component. This is not expected behavior, and this PR prevents it by
using a different, more restricted opcode for these lookups.

Closes #1149
Addresses emberjs/ember.js#17744

@rwjblue rwjblue added the bug label Sep 2, 2020
@pzuraq pzuraq force-pushed the bugfix/prevent-dynamic-invocation branch from 2a8fb00 to cdff060 Compare September 2, 2020 15:11

if (DEBUG && !isCurriedComponentDefinition(value)) {
throw new Error(
`A curried component definition. You may have accidentally done <this.dynamicComponent>, where dynamicComponent was a string instead of a curried component definition. You must use the {{component}} helper to create a component definition when invoking dynamically.`
Copy link
Contributor

@lifeart lifeart Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use real path / value for error?

one more use case is: (emberjs/ember.js#18686)

{{#let "my-component" as |AnyComponent|}}
   <AnyComponent />
{{/let}}
{{#let (hash AnyComponent="my-component") as |ctx|}}
   <ctx.AnyComponent />
{{/let}}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the error message to reference the debugLabel of the reference, which should give better context in general.

Re: the use case, that is what we are trying to prevent, and is not a valid use case in general. You should convert forward to:

{{#let (hash AnyComponent=(component "my-component")) as |ctx|}}
   <ctx.AnyComponent />
{{/let}}

Copy link
Contributor

@lifeart lifeart Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it not valid, my point is to have debug information pointing to such usage in case of error :)
(error may appear not only in this/@.foo invocation)

Dynamic components invoked via `{{component}}` share a codepath with
ones invoked via `<this.foo>`, and because of that currently if
`<this.foo>` is a referring to a string, it will dynamically lookup the
component. This is not expected behavior, and this PR prevents it by
using a different, more restricted opcode for these lookups.
@pzuraq pzuraq force-pushed the bugfix/prevent-dynamic-invocation branch from cdff060 to a8b53cd Compare September 2, 2020 16:11
@rwjblue rwjblue merged commit 574e36c into master Sep 2, 2020
@rwjblue rwjblue deleted the bugfix/prevent-dynamic-invocation branch September 2, 2020 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants