diff --git a/packages/ember-htmlbars/lib/node-managers/component-node-manager.js b/packages/ember-htmlbars/lib/node-managers/component-node-manager.js index 94b7417a7e3..3c1d03b455e 100644 --- a/packages/ember-htmlbars/lib/node-managers/component-node-manager.js +++ b/packages/ember-htmlbars/lib/node-managers/component-node-manager.js @@ -253,6 +253,8 @@ export function createComponent(_component, isAngleBracket, _props, renderNode, } props.renderer = props.parentView ? props.parentView.renderer : env.container.lookup('renderer:-dom'); + props._viewRegistry = props.parentView ? props.parentView._viewRegistry : props.container && props.container.lookup('-view-registry:main'); + let component = _component.create(props); // for the fallback case diff --git a/packages/ember-htmlbars/lib/node-managers/view-node-manager.js b/packages/ember-htmlbars/lib/node-managers/view-node-manager.js index 98aa15e2532..b9a9423543e 100644 --- a/packages/ember-htmlbars/lib/node-managers/view-node-manager.js +++ b/packages/ember-htmlbars/lib/node-managers/view-node-manager.js @@ -172,6 +172,7 @@ export function createOrUpdateComponent(component, options, createOptions, rende mergeBindings(props, shadowedAttrs(proto, snapshot)); props.container = options.parentView ? options.parentView.container : env.container; props.renderer = options.parentView ? options.parentView.renderer : props.container && props.container.lookup('renderer:-dom'); + props._viewRegistry = options.parentView ? options.parentView._viewRegistry : props.container && props.container.lookup('-view-registry:main'); if (proto.controller !== defaultController || hasSuppliedController) { delete props._context; diff --git a/packages/ember-htmlbars/tests/integration/component_invocation_test.js b/packages/ember-htmlbars/tests/integration/component_invocation_test.js index a06d28b9237..0c3900d955b 100644 --- a/packages/ember-htmlbars/tests/integration/component_invocation_test.js +++ b/packages/ember-htmlbars/tests/integration/component_invocation_test.js @@ -613,6 +613,47 @@ 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() { + var outer, innerTemplate, innerLayout; + + var viewRegistry = {}; + + registry.register('component:x-outer', Component.extend({ + init() { + this._super(...arguments); + outer = this; + } + })); + + registry.register('component:x-inner-in-template', Component.extend({ + init() { + this._super(...arguments); + innerTemplate = this; + } + })); + + registry.register('component:x-inner-in-layout', Component.extend({ + init() { + this._super(...arguments); + innerLayout = this; + } + })); + + registry.register('template:components/x-outer', compile('{{x-inner-in-layout}}{{yield}}')); + + view = EmberView.extend({ + _viewRegistry: viewRegistry, + template: compile('{{#x-outer}}{{x-inner-in-template}}{{/x-outer}}'), + container: container + }).create(); + + runAppend(view); + + equal(innerTemplate._viewRegistry, viewRegistry); + equal(innerLayout._viewRegistry, viewRegistry); + equal(outer._viewRegistry, viewRegistry); +}); + QUnit.test("comopnent should rerender when a property (with a default) is changed during children's rendering", function() { expectDeprecation(/modified value twice in a single render/);