Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

workaround for crashing clear-double-boot #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/instance-initializers/fastboot-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function prepDomForFastBoot() {
let start = document.getElementById('fastboot-body-start');
let end = document.getElementById('fastboot-body-end');

if (!start || !end) {
return;
}

if (start.parentElement !== end.parentElement) {
start.parentElement.appendChild(end);
}
}

export function initialize(/* appInstance */) {
if (typeof FastBoot === 'undefined') {
prepDomForFastBoot();
}
}

export default {
name: 'fastboot-fix',
before: 'clear-double-boot',

initialize,
};
32 changes: 32 additions & 0 deletions tests/integration/instance-initializers/fastboot-fix-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { prepDomForFastBoot } from 'gothamist-web-client/instance-initializers/fastboot-fix';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Instance Initializer | fastboot-fix', function(hooks) {
setupRenderingTest(hooks);

// Replace this with your real tests.
test('it ensures fastboot markers have the same parent', async function(assert) {
const BAD_BODY = `
<script type="x/boundary" id="fastboot-body-start"></script>
<div>
<p>
Great article content here.
</p>
<em>With additional reporting<em>
</div>
<script type="x/boundary" id="fastboot-body-end"></script>
`;
this.set('BAD_BODY', BAD_BODY);

await render(hbs`{{{BAD_BODY}}}`);

prepDomForFastBoot();

let startMarker = this.element.querySelector('#fastboot-body-start');
let endMarker = this.element.querySelector('#fastboot-body-end');
assert.deepEqual(startMarker.parentElement, endMarker.parentElement);
});
});