@@ -132,6 +132,70 @@ export class InElementDocumentFragmentSuite extends RenderTest {
132132 this . assertHTML ( '<!----><!---->' ) ;
133133 }
134134
135+ @test
136+ 'After fragment is attached to DOM, text updates and new conditional elements appear in the container' ( ) {
137+ const fragment = document . createDocumentFragment ( ) ;
138+ const container = document . createElement ( 'div' ) ;
139+
140+ this . render (
141+ '{{#in-element this.fragment}}' +
142+ '<p id="msg">{{this.message}}</p>' +
143+ '{{#if this.show}}<span id="extra">extra</span>{{/if}}' +
144+ '{{/in-element}}' ,
145+ {
146+ fragment,
147+ message : 'initial' ,
148+ show : false ,
149+ }
150+ ) ;
151+
152+ this . assert . step ( 'initial render into fragment' ) ;
153+ const p = fragment . querySelector ( '#msg' ) as HTMLElement ;
154+ this . assert . strictEqual ( p ?. textContent , 'initial' , 'p rendered in fragment' ) ;
155+ this . assert . notOk ( fragment . querySelector ( '#extra' ) , 'no extra span in fragment yet' ) ;
156+
157+ // Move fragment's children (including Glimmer's comment bounds) into the container
158+ container . appendChild ( fragment ) ;
159+ this . assert . step ( 'fragment attached to DOM' ) ;
160+ this . assert . strictEqual ( fragment . childNodes . length , 0 , 'fragment is empty after append' ) ;
161+ this . assert . strictEqual (
162+ container . querySelector ( '#msg' ) ?. textContent ,
163+ 'initial' ,
164+ 'p is in the container'
165+ ) ;
166+
167+ // Text-node update: Glimmer holds a direct reference to the text node, so the
168+ // update is visible in the container even though the fragment is now empty.
169+ this . rerender ( { message : 'updated' } ) ;
170+ this . assert . step ( 'text updated' ) ;
171+ this . assert . strictEqual (
172+ container . querySelector ( '#msg' ) ?. textContent ,
173+ 'updated' ,
174+ 'text update is reflected in the container'
175+ ) ;
176+ this . assert . strictEqual ( fragment . childNodes . length , 0 , 'fragment remains empty after text update' ) ;
177+
178+ // New-element update: Glimmer inserts the span relative to the comment bounds,
179+ // which also moved to the container, so the new element appears in the container.
180+ this . rerender ( { show : true } ) ;
181+ this . assert . step ( 'conditional element shown' ) ;
182+ this . assert . ok (
183+ container . querySelector ( '#extra' ) ,
184+ 'new conditional element appears in the container (comment bounds moved with the fragment)'
185+ ) ;
186+ this . assert . notOk (
187+ fragment . querySelector ( '#extra' ) ,
188+ 'new conditional element is not in the (now-empty) fragment'
189+ ) ;
190+
191+ this . assert . verifySteps ( [
192+ 'initial render into fragment' ,
193+ 'fragment attached to DOM' ,
194+ 'text updated' ,
195+ 'conditional element shown' ,
196+ ] ) ;
197+ }
198+
135199 @test
136200 'Multiple in-element calls to the same DocumentFragment with insertBefore=null' ( ) {
137201 const fragment = document . createDocumentFragment ( ) ;
0 commit comments