fix: signals not serialized with newer versions (#1348)

This commit is contained in:
Marvin Hagemeister
2023-06-23 11:58:07 +02:00
committed by GitHub
parent 76d838cf10
commit 95fc13a8cc
4 changed files with 81 additions and 1 deletions
+16
View File
@@ -155,6 +155,22 @@ 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;
}