Skip to content

Commit 2ca3c87

Browse files
authored
fix: correctly reflect readonly proxy marker (#9893)
1 parent 7238e1d commit 2ca3c87

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

.changeset/rotten-bags-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: correctly reflect readonly proxy marker

packages/svelte/src/internal/client/proxy/proxy.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ const handler = {
149149
},
150150

151151
get(target, prop, receiver) {
152-
if (DEV && prop === READONLY_SYMBOL) return target[READONLY_SYMBOL];
153-
152+
if (DEV && prop === READONLY_SYMBOL) {
153+
return Reflect.get(target, READONLY_SYMBOL);
154+
}
154155
const metadata = target[STATE_SYMBOL];
155156
let s = metadata.s.get(prop);
156157

@@ -184,6 +185,9 @@ const handler = {
184185
},
185186

186187
has(target, prop) {
188+
if (DEV && prop === READONLY_SYMBOL) {
189+
return Reflect.has(target, READONLY_SYMBOL);
190+
}
187191
if (prop === STATE_SYMBOL) {
188192
return true;
189193
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import Component2 from './Component2.svelte';
3+
const {state} = $props();
4+
5+
function render(state) {
6+
return state
7+
}
8+
</script>
9+
10+
<Component2 state={render(state)} />
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
const {state} = $props();
3+
</script>
4+
5+
{state}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
dev: true
6+
},
7+
async test({ assert, target }) {
8+
const btn = target.querySelector('button');
9+
10+
await btn?.click();
11+
assert.htmlEqual(target.innerHTML, `<button></button>\n[object Object]`);
12+
}
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Component from './Component.svelte';
3+
4+
let state = $state();
5+
</script>
6+
7+
<button onclick={() => {
8+
state = {}
9+
}}></button>
10+
{#if state}
11+
<Component state={state} />
12+
{/if}

0 commit comments

Comments
 (0)