Skip to content

Commit

Permalink
[BUGFIX release] On re-render, ensure child views of non-dirty compon…
Browse files Browse the repository at this point in the history
…ents get the correct parentView

On re-render of a non-dirty component, the `env` was simply passed down when
rendering the component's template, which means its parentView was wrong; this
patch mimics what keywords already do to solve this for components.

Fixes #11554

(cherry picked from commit bc9dbcd)
  • Loading branch information
jder authored and rwjblue committed Jul 6, 2015
1 parent a9e8379 commit 35f8a35
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export function createComponent(_component, isAngleBracket, _props, renderNode,

component._renderNode = renderNode;
renderNode.emberView = component;
renderNode.buildChildEnv = buildChildEnv;
return component;
}

Expand Down Expand Up @@ -360,3 +361,7 @@ function mergeBindings(target, attrs) {

return target;
}

function buildChildEnv(state, env) {
return env.childWithView(this.emberView);
}
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,38 @@ QUnit.test('components in template of a yielding component should have the prope
equal(outer.parentView, view, 'x-outer receives the ambient scope as its parentView');
});

QUnit.test('components should receive the viewRegistry from the parent view', function() {
QUnit.test('newly-added sub-components get correct parentView', function() {
var outer, inner;

registry.register('component:x-outer', Component.extend({
init() {
this._super(...arguments);
outer = this;
}
}));

registry.register('component:x-inner', Component.extend({
init() {
this._super(...arguments);
inner = this;
}
}));

view = EmberView.extend({
template: compile('{{#x-outer}}{{#if view.showInner}}{{x-inner}}{{/if}}{{/x-outer}}'),
container: container,
showInner: false
}).create();

runAppend(view);

run(() => { view.set('showInner', true); });

equal(inner.parentView, outer, 'receives the wrapping component as its parentView in template blocks');
equal(outer.parentView, view, 'x-outer receives the ambient scope as its parentView');
});

QUnit.test("components should receive the viewRegistry from the parent view", function() {
var outer, innerTemplate, innerLayout;

var viewRegistry = {};
Expand Down

0 comments on commit 35f8a35

Please sign in to comment.