File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
compiler/compile/render_dom/wrappers Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,11 @@ export default class HeadWrapper extends Wrapper {
3636 let nodes ;
3737 if ( this . renderer . options . hydratable && this . fragment . nodes . length ) {
3838 nodes = block . get_unique_name ( 'head_nodes' ) ;
39- block . chunks . claim . push ( b `const ${ nodes } = @query_selector_all('[data-svelte="${ this . node . id } "]', @_document.head);` ) ;
39+ block . chunks . claim . push ( b `
40+ const ${ nodes } = [
41+ ...@query_selector_all('[data-svelte="${ this . node . id } "]', @_document.head),
42+ ...@get_hydratable_raw_elements(@_document.head)
43+ ];` ) ;
4044 }
4145
4246 this . fragment . render ( block , x `@_document.head` as unknown as Identifier , nodes ) ;
Original file line number Diff line number Diff line change @@ -640,6 +640,26 @@ export function query_selector_all(selector: string, parent: HTMLElement = docum
640640 return Array . from ( parent . querySelectorAll ( selector ) ) as ChildNodeArray ;
641641}
642642
643+ export function get_hydratable_raw_elements ( parent : HTMLElement = document . body ) {
644+ const elements = Array . from ( parent . childNodes ) ;
645+ let cursor = 0 ;
646+ while ( cursor < elements . length ) {
647+ const start_index = find_comment ( elements , 'HTML_TAG_START' , cursor ) ;
648+ const end_index = find_comment ( elements , 'HTML_TAG_END' , start_index ) ;
649+ if ( start_index === end_index ) {
650+ elements . splice ( cursor , elements . length - cursor ) ;
651+ break ;
652+ }
653+
654+ detach ( elements [ start_index ] ) ;
655+ detach ( elements [ end_index ] ) ;
656+
657+ elements . splice ( cursor , 1 + start_index - cursor ) ;
658+ cursor += end_index - start_index - 1 ;
659+ }
660+ return elements ;
661+ }
662+
643663export class HtmlTag {
644664 // parent for creating node
645665 e : HTMLElement ;
You can’t perform that action at this time.
0 commit comments