@@ -114,18 +114,23 @@ export default class SlotWrapper extends Wrapper {
114
114
get_slot_context_fn = 'null' ;
115
115
}
116
116
117
+ let has_fallback = ! ! this . fallback ;
117
118
if ( this . fallback ) {
118
119
this . fragment . render ( this . fallback , null , x `#nodes` as Identifier ) ;
120
+ has_fallback = this . fallback . has_content ( ) ;
121
+ if ( ! has_fallback ) {
122
+ renderer . remove_block ( this . fallback ) ;
123
+ }
119
124
}
120
125
121
126
const slot = block . get_unique_name ( `${ sanitize ( slot_name ) } _slot` ) ;
122
127
const slot_definition = block . get_unique_name ( `${ sanitize ( slot_name ) } _slot_template` ) ;
123
- const slot_or_fallback = this . fallback ? block . get_unique_name ( `${ sanitize ( slot_name ) } _slot_or_fallback` ) : slot ;
128
+ const slot_or_fallback = has_fallback ? block . get_unique_name ( `${ sanitize ( slot_name ) } _slot_or_fallback` ) : slot ;
124
129
125
130
block . chunks . init . push ( b `
126
131
const ${ slot_definition } = ${ renderer . reference ( '$$slots' ) } .${ slot_name } ;
127
132
const ${ slot } = @create_slot(${ slot_definition } , #ctx, ${ renderer . reference ( '$$scope' ) } , ${ get_slot_context_fn } );
128
- ${ this . fallback ? b `const ${ slot_or_fallback } = ${ slot } || ${ this . fallback . name } (#ctx);` : null }
133
+ ${ has_fallback ? b `const ${ slot_or_fallback } = ${ slot } || ${ this . fallback . name } (#ctx);` : null }
129
134
` ) ;
130
135
131
136
block . chunks . create . push (
@@ -161,7 +166,7 @@ export default class SlotWrapper extends Wrapper {
161
166
162
167
const dynamic_dependencies = Array . from ( this . dependencies ) . filter ( is_dependency_dynamic ) ;
163
168
164
- const fallback_dynamic_dependencies = this . fallback
169
+ const fallback_dynamic_dependencies = has_fallback
165
170
? Array . from ( this . fallback . dependencies ) . filter ( is_dependency_dynamic )
166
171
: [ ] ;
167
172
@@ -173,7 +178,7 @@ export default class SlotWrapper extends Wrapper {
173
178
);
174
179
}
175
180
` ;
176
- const fallback_update = this . fallback && fallback_dynamic_dependencies . length > 0 && b `
181
+ const fallback_update = has_fallback && fallback_dynamic_dependencies . length > 0 && b `
177
182
if (${ slot_or_fallback } && ${ slot_or_fallback } .p && ${ renderer . dirty ( fallback_dynamic_dependencies ) } ) {
178
183
${ slot_or_fallback } .p(#ctx, #dirty);
179
184
}
0 commit comments