Skip to content

Commit

Permalink
Merge pull request #12829 from emberjs/fastboot-tagless
Browse files Browse the repository at this point in the history
[BUGFIX canary] Support tagless components in fastboot
  • Loading branch information
rwjblue committed Jan 18, 2016
2 parents f2adc4f + a844921 commit 551a231
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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)
)
]);
});


}

0 comments on commit 551a231

Please sign in to comment.