mirror of https://github.com/sveltejs/svelte
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>pull/14363/head
parent
f6117bb328
commit
741106879b
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure internal cloning can work circular values
|
@ -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]);
|
||||
}
|
||||
});
|
@ -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>
|
Loading…
Reference in new issue