Skip to content

Commit

Permalink
Merge pull request #763 from ember-fastboot/avoid-errors
Browse files Browse the repository at this point in the history
Prevent errors when `fastboot-body-end` is not present.
  • Loading branch information
rwjblue authored Jun 10, 2020
2 parents 67f07ae + c4206a4 commit 507e025
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 3 additions & 2 deletions addon/instance-initializers/clear-double-boot.js
Original file line number Diff line number Diff line change
@@ -8,8 +8,9 @@
// application will replace the pre-rendered output
export function clearHtml() {
let current = document.getElementById('fastboot-body-start');
if (current) {
let endMarker = document.getElementById('fastboot-body-end');
let endMarker = document.getElementById('fastboot-body-end');

if (current && endMarker) {
let shoeboxNodes = document.querySelectorAll('[type="fastboot/shoebox"]');
let shoeboxNodesArray = []; // Note that IE11 doesn't support more concise options like Array.from, so we have to do something like this
for(let i=0; i < shoeboxNodes.length; i++){
11 changes: 11 additions & 0 deletions tests/integration/instance-initializers/clear-double-boot-test.js
Original file line number Diff line number Diff line change
@@ -36,4 +36,15 @@ module('Instance-initializer: clear-double-boot', function(hooks) {
assert.notOk(this.element.querySelector('#fastboot-body-end'), 'There is no end marker');
assert.notOk(this.element.querySelector('#content-in-between'), 'The content is between is gone');
})

test('It can handle missing fastboot-body-end', async function(assert) {
this.set('BAD_HTML', `<script type="x/boundary" id="fastboot-body-start"></script>`);

// render the whole tree dynamically to more closely mimc bad markup cases
await render(hbs`{{{BAD_HTML}}}`);

clearHtml();

assert.strictEqual(this.element.innerHTML, this.get('BAD_HTML'));
})
});
5 changes: 4 additions & 1 deletion vendor/experimental-render-mode-rehydrate.js
Original file line number Diff line number Diff line change
@@ -23,7 +23,10 @@
// guarded for
current.parentNode.removeChild(current);
var end = document.getElementById('fastboot-body-end');
end.parentNode.removeChild(end);

if (end) {
end.parentNode.removeChild(end);
}
}
}
})();

0 comments on commit 507e025

Please sign in to comment.