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 beta] Keep rest positional parameters when nesting contextual components if needed. #13764

Merged
merged 1 commit into from
Jul 21, 2016

Conversation

Serabe
Copy link
Member

@Serabe Serabe commented Jun 27, 2016

Steps to reproduce the bug before this patch:

  1. Create a component with rest positional param (like link-to).
  2. Create contextual component ((component "link-to" "index")).
  3. Render it ({{component (component "link-to" "index")}}).
  4. Realize the component did not receive "index" at all.

What was causing it?

Because of how positional parameters work (both in components and contextual
components), it is needed to treat them at each level and then merge them.
Sadly, this was causing to overwrite the rest positional parameters because
when no parameters are passed, the attribute get an empty array nonetheless.

In the example above, assuming LinkToComponent.positionalParams === 'params':

  1. Contextual component in 2 gets its positional parameters processed and
    receives the following named parameters { params: ['index'] }.
  2. When rendering, the {{component}} processes its own parameters getting
    { params: [] }. Then it merges in a new EmptyObject() these attributes
    on top of the ones in the contextual component. (See what I did there?
    I used the JS keyword new as an adjective! He he. Don't judge me, it is
    pretty late in here)

Solving the issue

This PR changes the implementation of mergeInNewHash to keep the original
positional parameters if the new ones are empty and the positional parameter is
of type rest.

Fixes #13742

@Serabe
Copy link
Member Author

Serabe commented Jun 27, 2016

If you are wondering why so many tests, it is because the merging is done in several places. :)

@@ -40,6 +40,142 @@ moduleFor('@htmlbars Components test: closure components', class extends Renderi
this.assertText('Hodi Hodari');
}

['@test keeps nested rest positional parameters if rendered with no positional parameters']() {
Copy link
Member

Choose a reason for hiding this comment

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

can you add GH#13742 in the test title?

Copy link
Member Author

Choose a reason for hiding this comment

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

To all of them or just this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

By all of them I mean only those added in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I add that to the two that made sense to me. Let me know if you want it added to the rest!

@rwjblue
Copy link
Member

rwjblue commented Jul 21, 2016

Chatted in slack with @Serabe about this, he is going to rebase to trigger a fresh CI run then we can land for 2.7.

components if needed.

Steps to reproduce the bug before this patch:

1. Create a component with rest positional param (like `link-to`).
2. Create contextual component (`(component "link-to" "index")`).
3. Render it (`{{component (component "link-to" "index")}}`).
4. Realize the component did not receive `"index"` at all.

What was causing it?
====================

Because of how positional parameters work (both in components and contextual
components), it is needed to treat them at each level and then merge them.
Sadly, this was causing to overwrite the rest positional parameters because
when no parameters are passed, the attribute get an empty array nonetheless.

In the example above, assuming `LinkToComponent.positionalParams === 'params'`:

1. Contextual component in `2` gets its positional parameters processed and
   receives the following named parameters `{ params: ['index'] }`.
2. When rendering, the `{{component}}` processes its own parameters getting
   `{ params: [] }`. Then it merges in a `new EmptyObject()` these attributes
   on top of the ones in the contextual component. (See what I did there?
   I used the JS keyword `new` as an adjective! He he. Don't judge me, it is
   pretty late in here)

Solving the issue
=================

This PR changes the implementation of `mergeInNewHash` to keep the original
positional parameters if the new ones are empty and the positional parameter is
of type rest.

Fixes emberjs#13742
@rwjblue rwjblue merged commit 7246a37 into emberjs:master Jul 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants