fix: serialized compute signals re-created as normal signals (#3183)

Fixes https://github.com/denoland/fresh/issues/3182
This commit is contained in:
Marvin Hagemeister
2025-08-03 20:31:36 +02:00
committed by GitHub
parent 2e68c30d8d
commit 03f6981860
6 changed files with 421 additions and 11 deletions
+11 -1
View File
@@ -9,7 +9,7 @@ import {
options as preactOptions,
type VNode,
} from "preact";
import type { Signal } from "@preact/signals";
import type { ReadonlySignal, Signal } from "@preact/signals";
import type { Stringifiers } from "../../jsonify/stringify.ts";
import type { PageProps } from "../../render.ts";
import { Partial, type PartialProps } from "../shared.ts";
@@ -361,6 +361,13 @@ function isSignal(x: any): x is Signal {
);
}
// deno-lint-ignore no-explicit-any
function isComputedSignal(x: any): x is ReadonlySignal {
return isSignal(x) &&
(("x" in x && typeof x.x === "function") ||
"_fn" in x && typeof x._fn === "function");
}
// deno-lint-ignore no-explicit-any
function isVNode(x: any): x is VNode {
return x !== null && typeof x === "object" && "type" in x && "ref" in x &&
@@ -369,6 +376,9 @@ function isVNode(x: any): x is VNode {
}
const stringifiers: Stringifiers = {
Computed: (value: unknown) => {
return isComputedSignal(value) ? { value: value.peek() } : undefined;
},
Signal: (value: unknown) => {
return isSignal(value) ? { value: value.peek() } : undefined;
},