-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure internal cloning can work circular values (#14347)
* fix: ensure internal cloning can work circular values * better fixc * 'original' feels slightly clearer than 'json_instance' * use an optional parameter, so we can omit it in most cases * Update packages/svelte/src/internal/shared/clone.js Co-authored-by: Rich Harris <rich.harris@vercel.com> --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
- Loading branch information
1 parent
f6117bb
commit 7411068
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: ensure internal cloning can work circular values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/svelte/tests/runtime-runes/samples/inspect-recursive-2/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
compileOptions: { | ||
dev: true | ||
}, | ||
|
||
async test({ assert, logs }) { | ||
var a = { | ||
a: {} | ||
}; | ||
a.a = a; | ||
|
||
var b = { | ||
a: { | ||
b: {} | ||
} | ||
}; | ||
b.a.b = b; | ||
|
||
assert.deepEqual(logs, ['init', a, 'init', b]); | ||
} | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/svelte/tests/runtime-runes/samples/inspect-recursive-2/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script> | ||
class A { | ||
toJSON(){ | ||
return { | ||
a: this | ||
} | ||
} | ||
} | ||
const state = $state(new A()); | ||
$inspect(state); | ||
class B { | ||
toJSON(){ | ||
return { | ||
a: { | ||
b: this | ||
} | ||
} | ||
} | ||
} | ||
const state2 = $state(new B()); | ||
$inspect(state2); | ||
</script> |