Skip to content

Commit 1057950

Browse files
authored
Merge pull request #96 from sandydoo/master
Fix wormhole insertion in FastBoot
2 parents 1befc94 + 3e25ca1 commit 1057950

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

addon/components/ember-wormhole.js

+13-23
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,24 @@ export default Component.extend({
4141
this._wormholeHeadNode = this._dom.createTextNode('');
4242
this._wormholeTailNode = this._dom.createTextNode('');
4343

44-
// A prop to help in the mocking of didInsertElement timing for Fastboot
45-
this._didInsert = false;
46-
},
47-
48-
/*
49-
* didInsertElement does not fire in Fastboot. Here we use willRender and
50-
* a _didInsert property to approximate the timing. Importantly we want
51-
* to run appendToDestination after the child nodes have rendered.
52-
*/
53-
willRender() {
54-
this._super(...arguments);
55-
if (!this._didInsert) {
56-
this._didInsert = true;
57-
run.schedule('afterRender', () => {
58-
if (this.isDestroyed) { return; }
59-
this._element = this._wormholeHeadNode.parentNode;
60-
if (!this._element) {
61-
throw new Error('The head node of a wormhole must be attached to the DOM');
62-
}
63-
this._appendToDestination();
64-
});
65-
}
44+
/*
45+
* didInsertElement does not fire in Fastboot, so we schedule this in
46+
* init to be run after render. Importantly, we want to run
47+
* appendToDestination after the child nodes have rendered.
48+
*/
49+
run.schedule('afterRender', () => {
50+
if (this.isDestroyed) { return; }
51+
this._element = this._wormholeHeadNode.parentNode;
52+
if (!this._element) {
53+
throw new Error('The head node of a wormhole must be attached to the DOM');
54+
}
55+
this._appendToDestination();
56+
});
6657
},
6758

6859
willDestroyElement: function() {
6960
// not called in fastboot
7061
this._super(...arguments);
71-
this._didInsert = false;
7262
let { _wormholeHeadNode, _wormholeTailNode } = this;
7363
run.schedule('render', () => {
7464
this._removeRange(_wormholeHeadNode, _wormholeTailNode);

0 commit comments

Comments
 (0)