Skip to content

Commit

Permalink
fix: skip is_standalone optimisation for dynamic components (#12767)
Browse files Browse the repository at this point in the history
* fix: skip `is_standalone` optimisation for dynamic components

* changeset
  • Loading branch information
Rich-Harris authored Aug 8, 2024
1 parent 60148d3 commit ec8a029
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-bottles-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
---
'svelte': patch
---

fix: skip `is_standalone` optimisation for dynamic components
1 change: 1 addition & 0 deletions packages/svelte/src/compiler/phases/3-transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 283,7 @@ export function clean_nodes(
((first.type === 'RenderTag' && !first.metadata.dynamic) ||
(first.type === 'Component' &&
!state.options.hmr &&
!first.metadata.dynamic &&
!first.attributes.some(
(attribute) => attribute.type === 'Attribute' && attribute.name.startsWith('--')
))),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
<script>
let { id } = $props();
</script>

<span>{id}</span>
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
html: `<button>flip</button> <span>0</span><span>1</span><span>2</span>`,

async test({ assert, target }) {
const button = target.querySelector('button');

flushSync(() => button?.click());
assert.htmlEqual(
target.innerHTML,
`<button>flip</button> <span>2</span><span>1</span><span>0</span>`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 1,13 @@
<script>
import Row from './Row.svelte';
const items = $state([{ id: 0 }, { id: 1 }, { id: 2 }]);
const Table = { Row };
</script>

<button onclick={() => items.reverse()}> flip </button>

{#each items as item (item.id)}
<Table.Row id={item.id} />
{/each}

0 comments on commit ec8a029

Please sign in to comment.