mirror of https://github.com/sveltejs/svelte
fix: reuse proxy between objects (#9821)
* chore: reuse proxy between objects * lint --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/9824/head
parent
3fb917dc6d
commit
5797bb34ce
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: reuse existing proxy when object has multiple references
|
@ -0,0 +1,30 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<button>0</button>
|
||||||
|
<button>0</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [btn1, btn2] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
await btn1?.click();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>1</button>
|
||||||
|
<button>1</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
await btn2?.click();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>2</button>
|
||||||
|
<button>2</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,14 @@
|
|||||||
|
<script>
|
||||||
|
let obj = { count: 0 };
|
||||||
|
|
||||||
|
let a = $state(obj);
|
||||||
|
let b = $state(obj);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => a.count += 1}>
|
||||||
|
{a.count}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button onclick={() => b.count += 1}>
|
||||||
|
{b.count}
|
||||||
|
</button>
|
Loading…
Reference in new issue