fix: duplicate references for same signals (#1503)
This commit is contained in:
+10
-16
@@ -88,6 +88,16 @@ export function serialize(data: unknown): SerializeResult {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Bypass signal's `.toJSON` method because we want to serialize
|
||||
// the signal itself including the signal's value and not just
|
||||
// the value. This is needed because `JSON.stringify` always
|
||||
// calls `.toJSON` automatically if available.
|
||||
// deno-lint-ignore no-explicit-any
|
||||
if (key !== null && isSignal((this as any)[key])) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
value = (this as any)[key];
|
||||
}
|
||||
|
||||
// For some object types, the path in the object graph from root is not the
|
||||
// same between the serialized representation, and deserialized objects. For
|
||||
// these cases, we have to change the contents of the key stack to match the
|
||||
@@ -155,22 +165,6 @@ export function serialize(data: unknown): SerializeResult {
|
||||
parentStack.push(res);
|
||||
return res;
|
||||
} else {
|
||||
if (key !== null) {
|
||||
// Bypass signal's `.toJSON` method because we want to serialize
|
||||
// the signal itself including the signal's value and not just
|
||||
// the value. This is needed because `JSON.stringify` always
|
||||
// calls `.toJSON` automatically if available.
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const realValue = (this as any)[key];
|
||||
if (isSignal(realValue)) {
|
||||
requiresDeserializer = true;
|
||||
hasSignals = true;
|
||||
const res = { [KEY]: "s", v: realValue.peek() };
|
||||
parentStack.push(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
parentStack.push(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user