1- // When using `ember serve` when fastboot addon is installed the application
2- // output will already be rendered to the DOM when the actual JavaScript
3- // loads. Ember does not automatically clear its `rootElement` so this
4- // leads to the "double" applications being visible at once (only the
1+ // When using `ember serve` when fastboot addon is installed the application
2+ // output will already be rendered to the DOM when the actual JavaScript
3+ // loads. Ember does not automatically clear its `rootElement` so this
4+ // leads to the "double" applications being visible at once (only the
55// "bottom" one is running via JS and is interactive).
66//
77// This removes any pre-rendered ember-view elements, so that the booting
@@ -15,12 +15,18 @@ export default {
1515 var originalDidCreateRootView = instance . didCreateRootView ;
1616
1717 instance . didCreateRootView = function ( ) {
18- let elements = document . querySelectorAll ( instance . rootElement + ' .ember-view' ) ;
19- for ( let i = 0 ; i < elements . length ; i ++ ) {
20- let element = elements [ i ] ;
21- element . parentNode . removeChild ( element ) ;
18+ let current = document . getElementById ( 'fastboot-body-start' ) ;
19+ if ( current ) {
20+ let endMarker = document . getElementById ( 'fastboot-body-end' ) ;
21+ let parent = current . parentElement ;
22+ let nextNode ;
23+ do {
24+ nextNode = current . nextSibling ;
25+ parent . removeChild ( current ) ;
26+ current = nextNode ;
27+ } while ( nextNode && nextNode !== endMarker ) ;
28+ parent . removeChild ( endMarker ) ;
2229 }
23-
2430 originalDidCreateRootView . apply ( instance , arguments ) ;
2531 } ;
2632 }
0 commit comments