Skip to content

Commit c4206a4

Browse files
author
Robert Jackson
committed
Prevent errors when fastboot-body-end is not present.
The current implementation of `clear-double-render` guards for when `fastboot-body-start` is not present, but does not check if `fastboot-body-end` is present before attempting to remove it (therefore causing an `Cannot call 'parentElement' of null` error). Note: There are still some issues with this approach (e.g. why is `fastboot-body-start` present but `fastboot-body-end` is missing), and this change does not directly address all of the issues. It **does** prevent a masking error from happening.
1 parent 67f07ae commit c4206a4

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

addon/instance-initializers/clear-double-boot.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
// application will replace the pre-rendered output
99
export function clearHtml() {
1010
let current = document.getElementById('fastboot-body-start');
11-
if (current) {
12-
let endMarker = document.getElementById('fastboot-body-end');
11+
let endMarker = document.getElementById('fastboot-body-end');
12+
13+
if (current && endMarker) {
1314
let shoeboxNodes = document.querySelectorAll('[type="fastboot/shoebox"]');
1415
let shoeboxNodesArray = []; // Note that IE11 doesn't support more concise options like Array.from, so we have to do something like this
1516
for(let i=0; i < shoeboxNodes.length; i++){

tests/integration/instance-initializers/clear-double-boot-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@ module('Instance-initializer: clear-double-boot', function(hooks) {
3636
assert.notOk(this.element.querySelector('#fastboot-body-end'), 'There is no end marker');
3737
assert.notOk(this.element.querySelector('#content-in-between'), 'The content is between is gone');
3838
})
39+
40+
test('It can handle missing fastboot-body-end', async function(assert) {
41+
this.set('BAD_HTML', `<script type="x/boundary" id="fastboot-body-start"></script>`);
42+
43+
// render the whole tree dynamically to more closely mimc bad markup cases
44+
await render(hbs`{{{BAD_HTML}}}`);
45+
46+
clearHtml();
47+
48+
assert.strictEqual(this.element.innerHTML, this.get('BAD_HTML'));
49+
})
3950
});

vendor/experimental-render-mode-rehydrate.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
// guarded for
2424
current.parentNode.removeChild(current);
2525
var end = document.getElementById('fastboot-body-end');
26-
end.parentNode.removeChild(end);
26+
27+
if (end) {
28+
end.parentNode.removeChild(end);
29+
}
2730
}
2831
}
2932
})();

0 commit comments

Comments
 (0)