File tree Expand file tree Collapse file tree 4 files changed +36
-16
lines changed
tests/runtime-runes/samples/proxy-set-with-parent Expand file tree Collapse file tree 4 files changed +36
-16
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: don't set state withing ` with_parent ` in proxy
Original file line number Diff line number Diff line change @@ -93,21 +93,19 @@ export function proxy(value) {
93
93
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/getOwnPropertyDescriptor#invariants
94
94
e . state_descriptors_fixed ( ) ;
95
95
}
96
-
97
- with_parent ( ( ) => {
98
- var s = sources . get ( prop ) ;
99
-
100
- if ( s === undefined ) {
101
- s = source ( descriptor . value , stack ) ;
96
+ var s = sources . get ( prop ) ;
97
+ if ( s === undefined ) {
98
+ s = with_parent ( ( ) => {
99
+ var s = source ( descriptor . value , stack ) ;
102
100
sources . set ( prop , s ) ;
103
-
104
101
if ( DEV && typeof prop === 'string' ) {
105
102
tag ( s , get_label ( path , prop ) ) ;
106
103
}
107
- } else {
108
- set ( s , descriptor . value , true ) ;
109
- }
110
- } ) ;
104
+ return s ;
105
+ } ) ;
106
+ } else {
107
+ set ( s , descriptor . value , true ) ;
108
+ }
111
109
112
110
return true ;
113
111
} ,
@@ -268,11 +266,8 @@ export function proxy(value) {
268
266
// object property before writing to that property.
269
267
if ( s === undefined ) {
270
268
if ( ! has || get_descriptor ( target , prop ) ?. writable ) {
271
- s = with_parent ( ( ) => {
272
- var s = source ( undefined , stack ) ;
273
- set ( s , proxy ( value ) ) ;
274
- return s ;
275
- } ) ;
269
+ s = with_parent ( ( ) => source ( undefined , stack ) ) ;
270
+ set ( s , proxy ( value ) ) ;
276
271
277
272
sources . set ( prop , s ) ;
278
273
Original file line number Diff line number Diff line change
1
+ import { test } from '../../test' ;
2
+
3
+ export default test ( {
4
+ async test ( ) { }
5
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ function with_writes (initialState ) {
3
+ const derive = $state (initialState)
4
+ return derive
5
+ }
6
+
7
+ let data = $state ({ example: ' Example' })
8
+ let my_derived = $derived (with_writes ({ example: data .example }))
9
+
10
+ $effect (() => {
11
+ my_derived .example = ' Bar'
12
+ });
13
+ </script >
14
+
15
+ <input bind:value ={data .example } />
You can’t perform that action at this time.
0 commit comments