fix: serialized compute signals re-created as normal signals (#3183)
Fixes https://github.com/denoland/fresh/issues/3182
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { useComputed, useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
export function ComputedSignal(props: { id?: string }) {
|
||||
const status = useSignal("it doesn't work");
|
||||
const c = useComputed(() => 1);
|
||||
|
||||
const active = useSignal(false);
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div id={props.id} class={active.value ? "ready" : ""}>
|
||||
<button
|
||||
type="button"
|
||||
class="trigger"
|
||||
onClick={() => {
|
||||
try {
|
||||
// This should throw
|
||||
// deno-lint-ignore no-explicit-any
|
||||
(c as any).value = 10;
|
||||
status.value = "it doesn't work";
|
||||
} catch {
|
||||
status.value = "it works";
|
||||
}
|
||||
}}
|
||||
>
|
||||
trigger
|
||||
</button>
|
||||
<p class="output">{status}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import type { FreshConfig } from "../src/config.ts";
|
||||
import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx";
|
||||
import { FakeServer } from "../src/test_utils.ts";
|
||||
import { PARTIAL_SEARCH_PARAM } from "../src/constants.ts";
|
||||
import { ComputedSignal } from "./fixtures_islands/Computed.tsx";
|
||||
|
||||
const allIslandCache = await buildProd({ islandDir: ALL_ISLAND_DIR });
|
||||
const islandGroupCache = await buildProd({ root: ISLAND_GROUP_DIR });
|
||||
@@ -123,6 +124,29 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
// Note that computed signals are detached because we cannot
|
||||
// serialize the whole signal tree at the moment.
|
||||
name: "islands - should serialize computed",
|
||||
fn: async () => {
|
||||
const app = testApp()
|
||||
.get("/", (ctx) => {
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<ComputedSignal id="comp" />
|
||||
</Doc>,
|
||||
);
|
||||
});
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "load" });
|
||||
await page.locator("#comp.ready").wait();
|
||||
await page.locator("#comp .trigger").click();
|
||||
await waitForText(page, "#comp .output", "it works");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "islands - import json",
|
||||
fn: async () => {
|
||||
|
||||
Reference in New Issue
Block a user