Skip to content

Commit 9ae0383

Browse files
committed
Clear fast boot rendered head on browser boot
Split initializers into fastboot & browser flavors. Use placeholder meta tags for marking extent of head.hbs content.
1 parent 79337af commit 9ae0383

7 files changed

Lines changed: 61 additions & 26 deletions

File tree

addon/instance-initializers/head.js

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<meta name="ember-cli-head-start" />{{head-content}}<meta name="ember-cli-head-end" />

app/components/head-layout.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Ember from 'ember';
2+
import layout from 'ember-cli-head/templates/components/head-layout';
3+
4+
export default Ember.Component.extend({
5+
tagName: '',
6+
layout
7+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Ember from 'ember';
2+
3+
export function initialize(instance) {
4+
// clear fast booted head (if any)
5+
Ember.$('meta[name="ember-cli-head-start"]')
6+
.nextUntil('meta[name="ember-cli-head-end"] ~')
7+
.addBack()
8+
.remove();
9+
const container = instance.lookup ? instance : instance.container;
10+
const renderer = container.lookup('renderer:-dom');
11+
const component = container.lookup('component:head-layout');
12+
component.appendTo(renderer._dom.document.head);
13+
}
14+
15+
export default {
16+
name: 'head-browser',
17+
initialize: initialize
18+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export function initialize(instance) {
2+
const container = instance.lookup ? instance : instance.container;
3+
const renderer = container.lookup('renderer:-dom');
4+
const componentFactory =
5+
instance._lookupFactory('component:head-layout');
6+
// explicitly set renderer & domhelper since we're in fastboot
7+
const component = componentFactory.create(
8+
instance.ownerInjection(),
9+
{
10+
renderer,
11+
_domHelper: renderer._dom
12+
}
13+
);
14+
component.appendTo(renderer._dom.document.head);
15+
}
16+
17+
export default {
18+
name: 'head-fastboot',
19+
initialize: initialize
20+
};

app/instance-initializers/head.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { moduleForComponent, test } from 'ember-qunit';
2+
import hbs from 'htmlbars-inline-precompile';
3+
4+
moduleForComponent('head-layout', 'Integration | Component | head layout', {
5+
integration: true
6+
});
7+
8+
test('it renders', function(assert) {
9+
10+
this.render(hbs`{{head-layout}}`);
11+
12+
assert.equal(this.$('meta[name="ember-cli-head-start"]').length, 1);
13+
assert.equal(this.$('meta[name="ember-cli-head-end"]').length, 1);
14+
15+
});

0 commit comments

Comments
 (0)