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 canary] Support tagless components in fastboot #12829

Merged
merged 1 commit into from
Jan 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ember-views/lib/components/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assert, deprecate } from 'ember-metal/debug';
import environment from 'ember-metal/environment';

import TargetActionSupport from 'ember-runtime/mixins/target_action_support';
import View from 'ember-views/views/view';
Expand Down Expand Up @@ -163,7 +164,7 @@ var Component = View.extend(TargetActionSupport, {
// If in a tagless component, assert that no event handlers are defined
assert(
`You can not define a function that handles DOM events in the \`${this}\` tagless component since it doesn't have any DOM element.`,
this.tagName !== '' || !(() => {
this.tagName !== '' || !environment.hasDOM || !(() => {
let eventDispatcher = getOwner(this).lookup('event_dispatcher:main');
let events = (eventDispatcher && eventDispatcher._finalEvents) || {};

Expand Down
6 changes: 6 additions & 0 deletions packages/ember-views/lib/system/event_dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ActionManager from 'ember-views/system/action_manager';
import View from 'ember-views/views/view';
import assign from 'ember-metal/assign';
import { getOwner } from 'container/owner';
import environment from 'ember-metal/environment';

let ROOT_ELEMENT_CLASS = 'ember-application';
let ROOT_ELEMENT_SELECTOR = '.' + ROOT_ELEMENT_CLASS;
Expand Down Expand Up @@ -136,6 +137,11 @@ export default EmberObject.extend({
*/
canDispatchToEventManager: true,

init() {
this._super();
assert('EventDispatcher should never be instantiated in fastboot mode. Please report this as an Ember bug.', environment.hasDOM);
},

/**
Sets up event listeners for standard browser events.

Expand Down
17 changes: 17 additions & 0 deletions tests/node/visit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,21 @@ if (appModule.canRunTests) {
assert.strictEqual(xFooInstances, 0, 'it should not create any x-foo components');
});
});

QUnit.test('FastBoot: tagless components can render', function(assert) {
this.template('application', "<div class='my-context'>{{my-component}}</div>");
this.component('my-component', { tagName: '' });
this.template('components/my-component', '<h1>hello world</h1>');

var App = this.createApplication();

return RSVP.all([
fastbootVisit(App, '/').then(
assertFastbootResult(assert, { url: '/', body: /<div class="my-context"><h1>hello world<\/h1><\/div>/ }),
handleError(assert)
)
]);
});


}