Skip to content

Commit 8ef32d7

Browse files
authored
produce better code for <slot/> (#3631)
1 parent 0d36f1a commit 8ef32d7

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608))
1313
* Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619))
1414
* Support `{#await}` with `{:catch}` but no `{:then}` ([#3623](https://github.com/sveltejs/svelte/issues/3623))
15+
* Clean up dead code emitted for `<slot/>`s ([#3631](https://github.com/sveltejs/svelte/issues/3631))
1516
* Fix tracking of dependencies of compound assignments in reactive statements ([#3634](https://github.com/sveltejs/svelte/issues/3634))
1617
* Flush changes in newly attached block when using `{#await}` ([#3660](https://github.com/sveltejs/svelte/issues/3660))
1718
* Throw exception immediately when calling `createEventDispatcher()` after component instantiation ([#3667](https://github.com/sveltejs/svelte/pull/3667))

src/compiler/compile/render_dom/wrappers/Slot.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ export default class SlotWrapper extends Wrapper {
137137
block.render_listeners(`_${slot.name}`);
138138
block.event_listeners = listeners;
139139

140-
if (block.chunks.create) create.push(b`if (!${slot}) { ${block.chunks.create} }`);
141-
if (block.chunks.claim) claim.push(b`if (!${slot}) { ${block.chunks.claim} }`);
142-
if (block.chunks.hydrate) hydrate.push(b`if (!${slot}) { ${block.chunks.hydrate} }`);
143-
if (block.chunks.mount) mount.push(b`if (!${slot}) { ${block.chunks.mount} }`);
144-
if (block.chunks.update) update.push(b`if (!${slot}) { ${block.chunks.update} }`);
145-
if (block.chunks.destroy) destroy.push(b`if (!${slot}) { ${block.chunks.destroy} }`);
140+
if (block.chunks.create.length) create.push(b`if (!${slot}) { ${block.chunks.create} }`);
141+
if (block.chunks.claim.length) claim.push(b`if (!${slot}) { ${block.chunks.claim} }`);
142+
if (block.chunks.hydrate.length) hydrate.push(b`if (!${slot}) { ${block.chunks.hydrate} }`);
143+
if (block.chunks.mount.length) mount.push(b`if (!${slot}) { ${block.chunks.mount} }`);
144+
if (block.chunks.update.length) update.push(b`if (!${slot}) { ${block.chunks.update} }`);
145+
if (block.chunks.destroy.length) destroy.push(b`if (!${slot}) { ${block.chunks.destroy} }`);
146146

147147
block.chunks.create = create;
148148
block.chunks.claim = claim;
@@ -155,9 +155,11 @@ export default class SlotWrapper extends Wrapper {
155155
b`if (${slot}) ${slot}.c();`
156156
);
157157

158-
block.chunks.claim.push(
159-
b`if (${slot}) ${slot}.l(${parent_nodes});`
160-
);
158+
if (renderer.options.hydratable) {
159+
block.chunks.claim.push(
160+
b`if (${slot}) ${slot}.l(${parent_nodes});`
161+
);
162+
}
161163

162164
block.chunks.mount.push(b`
163165
if (${slot}) {

0 commit comments

Comments
 (0)