mirror of https://github.com/sveltejs/svelte
fix: don't turn component instances stored in $state into state proxies (#18646)
Fixes #18416. We previously said that we don't want to handle component instances specifically when they're wrapped with state in #16747 - though the use case presented back then was much more arcane than the one in #18416. Therefore we now don't proxify component instances anymore, which also makes the dev time proxy warning obsolete. --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>pull/14594/merge
parent
09a67efcfc
commit
2d2e5df26e
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: don't turn component instances stored in `$state` into state proxies
|
||||
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import { items } from './data.js';
|
||||
|
||||
export const myArr = items;
|
||||
</script>
|
||||
|
||||
<p>child</p>
|
||||
@ -0,0 +1,15 @@
|
||||
import { test } from '../../test';
|
||||
import { items } from './data.js';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
html: `<p>child</p>`,
|
||||
|
||||
test({ assert, instance }) {
|
||||
// ensure component instance doesn't get proxified (https://github.com/sveltejs/svelte/issues/18416)
|
||||
assert.ok(instance.get_first().myArr === items);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1 @@
|
||||
export const items = [{ id: 5, name: 'John' }];
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
const components = $state({});
|
||||
|
||||
export function get_first() {
|
||||
return components.first;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Child bind:this={components.first} />
|
||||
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import { items } from './data.js';
|
||||
|
||||
export const myArr = items;
|
||||
</script>
|
||||
|
||||
<p>child</p>
|
||||
@ -0,0 +1,11 @@
|
||||
import { test } from '../../test';
|
||||
import { items } from './data.js';
|
||||
|
||||
export default test({
|
||||
html: `<p>child</p>`,
|
||||
|
||||
test({ assert, instance }) {
|
||||
// ensure component instance doesn't get proxified (https://github.com/sveltejs/svelte/issues/18416)
|
||||
assert.ok(instance.get_first().myArr === items);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1 @@
|
||||
export const items = [{ id: 5, name: 'John' }];
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
const components = $state({});
|
||||
|
||||
export function get_first() {
|
||||
return components.first;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Child bind:this={components.first} />
|
||||
Loading…
Reference in new issue