Skip to content

Commit e392792

Browse files
author
magentaqin
committed
fix: fragment property of Empty Component is set as true in dev mode, inconsistent with production mode
1 parent 429e576 commit e392792

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/compiler/compile/render_dom/Block.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,16 @@ export default class Block {
428428
}
429429

430430
has_content(): boolean {
431+
// exclude "ThrowStatment" type node
432+
// as in dev mode, 'ThrowStatement' type node will always be added, which will make has_content() always return true in dev mode
433+
const validClaims = this.chunks.claim.filter(i => Array.isArray(i) && i[0] && i[0].type !== 'ThrowStatement');
431434
return !!this.first ||
432435
this.event_listeners.length > 0 ||
433436
this.chunks.intro.length > 0 ||
434437
this.chunks.outro.length > 0 ||
435438
this.chunks.create.length > 0 ||
436439
this.chunks.hydrate.length > 0 ||
437-
this.chunks.claim.length > 0 ||
440+
validClaims.length > 0 ||
438441
this.chunks.mount.length > 0 ||
439442
this.chunks.update.length > 0 ||
440443
this.chunks.destroy.length > 0 ||

src/compiler/compile/render_dom/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,10 @@ export default function dom(
333333
// $$props arg is still needed for unknown prop check
334334
args.push(x`$$props`);
335335
}
336-
337-
const has_create_fragment = component.compile_options.dev || block.has_content();
336+
// fix: remove "component.compile_options.dev" condition, which
337+
// will set has_create_fragment always be true in dev mode,
338+
// inconsistent with the behavior in production mode.
339+
const has_create_fragment = block.has_content();
338340
if (has_create_fragment) {
339341
body.push(b`
340342
function create_fragment(#ctx) {
@@ -593,7 +595,7 @@ export default function dom(
593595
constructor(options) {
594596
super(${options.dev && 'options'});
595597
@init(this, options, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${optional_parameters});
596-
${options.dev && b`@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: create_fragment.name });`}
598+
${options.dev && b`@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: ${has_create_fragment ? 'create_fragment.name' : 'this.name'} });`}
597599
598600
${dev_props_check}
599601
}

0 commit comments

Comments
 (0)