File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -158,11 +158,24 @@ class CoCreateServerSideRender {
158158 let chunkDom = parse ( chunk ) ;
159159 chunkDom = await render ( chunkDom ) ;
160160
161- el . setAttribute ( "rendered" , "" ) ;
162- el . innerHTML = "" ;
163- // Append all child nodes of chunkDom to el
164- for ( const child of chunkDom . childNodes ) {
165- el . appendChild ( child ) ;
161+ // If element requests outerHTML insertion, replace the element
162+ // with the fetched chunk's content. Otherwise append children.
163+ const valueType = el . getAttribute && el . getAttribute ( "value-type" ) ;
164+ if ( valueType === "outerHTML" ) {
165+ // Replace the element with the parsed chunk's child nodes
166+ // spread child nodes so we don't create an extra wrapper
167+ if ( chunkDom . childNodes && chunkDom . childNodes . length ) {
168+ el . replaceWith ( ...chunkDom . childNodes ) ;
169+ } else {
170+ // If no child nodes, just remove the element
171+ el . remove ( ) ;
172+ }
173+ } else {
174+ el . setAttribute ( "rendered" , "" ) ;
175+ el . innerHTML = "" ;
176+ for ( const child of chunkDom . childNodes ) {
177+ el . appendChild ( child ) ;
178+ }
166179 }
167180 }
168181 }
You can’t perform that action at this time.
0 commit comments