@@ -154,16 +154,18 @@ export default class IfBlockWrapper extends Wrapper {
154
154
155
155
const vars = { name, anchor, if_name, has_else, has_transitions } ;
156
156
157
+ const detaching = ( parent_node && parent_node !== 'document.head' ) ? '' : 'detaching' ;
158
+
157
159
if ( this . node . else ) {
158
160
if ( has_outros ) {
159
- this . render_compound_with_outros ( block , parent_node , parent_nodes , dynamic , vars ) ;
161
+ this . render_compound_with_outros ( block , parent_node , parent_nodes , dynamic , vars , detaching ) ;
160
162
161
163
block . builders . outro . add_line ( `if (${ name } ) ${ name } .o();` ) ;
162
164
} else {
163
- this . render_compound ( block , parent_node , parent_nodes , dynamic , vars ) ;
165
+ this . render_compound ( block , parent_node , parent_nodes , dynamic , vars , detaching ) ;
164
166
}
165
167
} else {
166
- this . render_simple ( block , parent_node , parent_nodes , dynamic , vars ) ;
168
+ this . render_simple ( block , parent_node , parent_nodes , dynamic , vars , detaching ) ;
167
169
168
170
if ( has_outros ) {
169
171
block . builders . outro . add_line ( `if (${ name } ) ${ name } .o();` ) ;
@@ -201,7 +203,8 @@ export default class IfBlockWrapper extends Wrapper {
201
203
parent_node : string ,
202
204
parent_nodes : string ,
203
205
dynamic ,
204
- { name, anchor, has_else, if_name, has_transitions }
206
+ { name, anchor, has_else, if_name, has_transitions } ,
207
+ detaching
205
208
) {
206
209
const select_block_type = this . renderer . component . get_unique_name ( `select_block_type` ) ;
207
210
const current_block_type = block . get_unique_name ( `current_block_type` ) ;
@@ -254,7 +257,7 @@ export default class IfBlockWrapper extends Wrapper {
254
257
` ) ;
255
258
}
256
259
257
- block . builders . destroy . add_line ( `${ if_name } ${ name } .d(${ parent_node ? '' : ' detaching' } );` ) ;
260
+ block . builders . destroy . add_line ( `${ if_name } ${ name } .d(${ detaching } );` ) ;
258
261
}
259
262
260
263
// if any of the siblings have outros, we need to keep references to the blocks
@@ -264,7 +267,8 @@ export default class IfBlockWrapper extends Wrapper {
264
267
parent_node : string ,
265
268
parent_nodes : string ,
266
269
dynamic ,
267
- { name, anchor, has_else, has_transitions }
270
+ { name, anchor, has_else, has_transitions } ,
271
+ detaching
268
272
) {
269
273
const select_block_type = this . renderer . component . get_unique_name ( `select_block_type` ) ;
270
274
const current_block_type_index = block . get_unique_name ( `current_block_type_index` ) ;
@@ -375,7 +379,7 @@ export default class IfBlockWrapper extends Wrapper {
375
379
}
376
380
377
381
block . builders . destroy . add_line ( deindent `
378
- ${ if_current_block_type_index } ${ if_blocks } [${ current_block_type_index } ].d(${ parent_node ? '' : ' detaching' } );
382
+ ${ if_current_block_type_index } ${ if_blocks } [${ current_block_type_index } ].d(${ detaching } );
379
383
` ) ;
380
384
}
381
385
@@ -384,7 +388,8 @@ export default class IfBlockWrapper extends Wrapper {
384
388
parent_node : string ,
385
389
parent_nodes : string ,
386
390
dynamic ,
387
- { name, anchor, if_name, has_transitions }
391
+ { name, anchor, if_name, has_transitions } ,
392
+ detaching
388
393
) {
389
394
const branch = this . branches [ 0 ] ;
390
395
@@ -450,6 +455,6 @@ export default class IfBlockWrapper extends Wrapper {
450
455
}
451
456
` ) ;
452
457
453
- block . builders . destroy . add_line ( `${ if_name } ${ name } .d(${ parent_node ? '' : ' detaching' } );` ) ;
458
+ block . builders . destroy . add_line ( `${ if_name } ${ name } .d(${ detaching } );` ) ;
454
459
}
455
460
}
0 commit comments