mirror of https://github.com/sveltejs/svelte
fix: better readonly checks for proxies (#9808)
- Expect the thing that's checked to be wrapped with the proxy already, so that we can just check for the state symbol - Make error message more descriptivepull/9816/head
parent
d5167e75b9
commit
5667785903
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: better readonly checks for proxies
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
/** @type {{ object: { count: number }}} */
|
||||
let { object } = $props();
|
||||
</script>
|
||||
|
||||
<button onclick={() => object = { count: object.count + 1 } }>
|
||||
clicks: {object.count}
|
||||
</button>
|
@ -0,0 +1,22 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
// Tests that readonly bails on setters/classes
|
||||
export default test({
|
||||
html: `<button>clicks: 0</button><button>clicks: 0</button>`,
|
||||
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
await btn1.click();
|
||||
await btn2.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>clicks: 1</button><button>clicks: 1</button>`);
|
||||
|
||||
await btn1.click();
|
||||
await btn2.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>clicks: 2</button><button>clicks: 2</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,25 @@
|
||||
<script>
|
||||
import Counter from './Counter.svelte';
|
||||
|
||||
function createCounter() {
|
||||
let count = $state(0)
|
||||
return {
|
||||
get count() {
|
||||
return count;
|
||||
},
|
||||
set count(upd) {
|
||||
count = upd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CounterClass {
|
||||
count = $state(0);
|
||||
}
|
||||
|
||||
const counterSetter = createCounter();
|
||||
const counterClass = new CounterClass();
|
||||
</script>
|
||||
|
||||
<Counter object={counterSetter} />
|
||||
<Counter object={counterClass} />
|
Loading…
Reference in new issue