fix: correctly reflect readonly proxy marker (#9893)

pull/9894/head
Dominic Gannaway 1 year ago committed by GitHub
parent 7238e1d3ce
commit 2ca3c87d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly reflect readonly proxy marker

@ -149,8 +149,9 @@ const handler = {
},
get(target, prop, receiver) {
if (DEV && prop === READONLY_SYMBOL) return target[READONLY_SYMBOL];
if (DEV && prop === READONLY_SYMBOL) {
return Reflect.get(target, READONLY_SYMBOL);
}
const metadata = target[STATE_SYMBOL];
let s = metadata.s.get(prop);
@ -184,6 +185,9 @@ const handler = {
},
has(target, prop) {
if (DEV && prop === READONLY_SYMBOL) {
return Reflect.has(target, READONLY_SYMBOL);
}
if (prop === STATE_SYMBOL) {
return true;
}

@ -0,0 +1,11 @@
<script>
import Component2 from './Component2.svelte';
const {state} = $props();
function render(state) {
return state
}
</script>
<Component2 state={render(state)} />

@ -0,0 +1,5 @@
<script>
const {state} = $props();
</script>
{state}

@ -0,0 +1,13 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
async test({ assert, target }) {
const btn = target.querySelector('button');
await btn?.click();
assert.htmlEqual(target.innerHTML, `<button></button>\n[object Object]`);
}
});

@ -0,0 +1,12 @@
<script>
import Component from './Component.svelte';
let state = $state();
</script>
<button onclick={() => {
state = {}
}}></button>
{#if state}
<Component state={state} />
{/if}
Loading…
Cancel
Save