diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index 339efb82..c18b2950 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -103,17 +103,12 @@ export function revive( ); for (let i = 0; i < result.length; i++) { - const { vnode, marker, rootFragment } = result[i]; + const { vnode, rootFragment } = result[i]; const _render = () => { render( vnode, rootFragment, ); - - if (marker.kind === MarkerKind.Partial) { - // deno-lint-ignore no-explicit-any - partials.set(marker.text, (vnode as any).__c); - } }; "scheduler" in window @@ -149,6 +144,10 @@ function addPropsChild(parent: VNode, vnode: ComponentChildren) { class PartialComp extends Component< { children?: ComponentChildren; mode: number; name: string } > { + componentDidMount() { + partials.set(this.props.name, this); + } + render() { return this.props.children; } @@ -432,11 +431,6 @@ function _walkInner( const parent = vnodeStack[vnodeStack.length - 1]!; addPropsChild(parent, vnode); - if (marker.kind === MarkerKind.Partial) { - // deno-lint-ignore no-explicit-any - partials.set(marker.text, (vnode as any).__c); - } - sib = marker.endNode.nextSibling; continue; } diff --git a/tests/fixture_partials/fresh.gen.ts b/tests/fixture_partials/fresh.gen.ts index 9b78e0bd..7b0062e5 100644 --- a/tests/fixture_partials/fresh.gen.ts +++ b/tests/fixture_partials/fresh.gen.ts @@ -90,17 +90,20 @@ import * as $84 from "./routes/mode/index.tsx"; import * as $85 from "./routes/mode/injected.tsx"; import * as $86 from "./routes/mode/prepend.tsx"; import * as $87 from "./routes/mode/replace.tsx"; -import * as $88 from "./routes/no_islands/index.tsx"; -import * as $89 from "./routes/no_islands/injected.tsx"; -import * as $90 from "./routes/no_islands/update.tsx"; -import * as $91 from "./routes/no_partial_response/index.tsx"; -import * as $92 from "./routes/no_partial_response/injected.tsx"; -import * as $93 from "./routes/no_partial_response/update.tsx"; -import * as $94 from "./routes/partial_slot_inside_island.tsx"; -import * as $95 from "./routes/relative_link/index.tsx"; -import * as $96 from "./routes/scroll_restoration/index.tsx"; -import * as $97 from "./routes/scroll_restoration/injected.tsx"; -import * as $98 from "./routes/scroll_restoration/update.tsx"; +import * as $88 from "./routes/nested/index.tsx"; +import * as $89 from "./routes/nested/inner.tsx"; +import * as $90 from "./routes/nested/outer.tsx"; +import * as $91 from "./routes/no_islands/index.tsx"; +import * as $92 from "./routes/no_islands/injected.tsx"; +import * as $93 from "./routes/no_islands/update.tsx"; +import * as $94 from "./routes/no_partial_response/index.tsx"; +import * as $95 from "./routes/no_partial_response/injected.tsx"; +import * as $96 from "./routes/no_partial_response/update.tsx"; +import * as $97 from "./routes/partial_slot_inside_island.tsx"; +import * as $98 from "./routes/relative_link/index.tsx"; +import * as $99 from "./routes/scroll_restoration/index.tsx"; +import * as $100 from "./routes/scroll_restoration/injected.tsx"; +import * as $101 from "./routes/scroll_restoration/update.tsx"; import * as $$0 from "./islands/Counter.tsx"; import * as $$1 from "./islands/CounterA.tsx"; import * as $$2 from "./islands/CounterB.tsx"; @@ -207,17 +210,20 @@ const manifest = { "./routes/mode/injected.tsx": $85, "./routes/mode/prepend.tsx": $86, "./routes/mode/replace.tsx": $87, - "./routes/no_islands/index.tsx": $88, - "./routes/no_islands/injected.tsx": $89, - "./routes/no_islands/update.tsx": $90, - "./routes/no_partial_response/index.tsx": $91, - "./routes/no_partial_response/injected.tsx": $92, - "./routes/no_partial_response/update.tsx": $93, - "./routes/partial_slot_inside_island.tsx": $94, - "./routes/relative_link/index.tsx": $95, - "./routes/scroll_restoration/index.tsx": $96, - "./routes/scroll_restoration/injected.tsx": $97, - "./routes/scroll_restoration/update.tsx": $98, + "./routes/nested/index.tsx": $88, + "./routes/nested/inner.tsx": $89, + "./routes/nested/outer.tsx": $90, + "./routes/no_islands/index.tsx": $91, + "./routes/no_islands/injected.tsx": $92, + "./routes/no_islands/update.tsx": $93, + "./routes/no_partial_response/index.tsx": $94, + "./routes/no_partial_response/injected.tsx": $95, + "./routes/no_partial_response/update.tsx": $96, + "./routes/partial_slot_inside_island.tsx": $97, + "./routes/relative_link/index.tsx": $98, + "./routes/scroll_restoration/index.tsx": $99, + "./routes/scroll_restoration/injected.tsx": $100, + "./routes/scroll_restoration/update.tsx": $101, }, islands: { "./islands/Counter.tsx": $$0, diff --git a/tests/fixture_partials/routes/nested/index.tsx b/tests/fixture_partials/routes/nested/index.tsx new file mode 100644 index 00000000..4b22319b --- /dev/null +++ b/tests/fixture_partials/routes/nested/index.tsx @@ -0,0 +1,55 @@ +import { Partial } from "$fresh/runtime.ts"; +import { ComponentChildren } from "preact"; +import { Fader } from "../../islands/Fader.tsx"; +import { Logger } from "../../islands/Logger.tsx"; + +export function Inner() { + return ( + + + +

inner

+
+
+
+ ); +} + +function Outer({ children }: { children: ComponentChildren }) { + return ( + + + +

outer

+ + {children} +
+
+
+ ); +} + +export default function SlotDemo() { + return ( +
+ + + +

+ + +

+
+    
+ ); +} diff --git a/tests/fixture_partials/routes/nested/inner.tsx b/tests/fixture_partials/routes/nested/inner.tsx new file mode 100644 index 00000000..0f197124 --- /dev/null +++ b/tests/fixture_partials/routes/nested/inner.tsx @@ -0,0 +1,24 @@ +import { defineRoute } from "$fresh/src/server/defines.ts"; +import { RouteConfig } from "$fresh/server.ts"; +import { Partial } from "$fresh/runtime.ts"; +import { Fader } from "../../islands/Fader.tsx"; +import { Logger } from "../../islands/Logger.tsx"; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default defineRoute(() => ( +
+
+ + + +

updated inner

+
+
+
+
+
+)); diff --git a/tests/fixture_partials/routes/nested/outer.tsx b/tests/fixture_partials/routes/nested/outer.tsx new file mode 100644 index 00000000..f604c994 --- /dev/null +++ b/tests/fixture_partials/routes/nested/outer.tsx @@ -0,0 +1,27 @@ +import { defineRoute } from "$fresh/src/server/defines.ts"; +import { RouteConfig } from "$fresh/server.ts"; +import { Partial } from "$fresh/runtime.ts"; +import { Inner } from "./index.tsx"; +import { Fader } from "../../islands/Fader.tsx"; +import { Logger } from "../../islands/Logger.tsx"; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default defineRoute(() => ( +
+
+ + + +

updated outer

+ + +
+
+
+
+
+)); diff --git a/tests/partials_test.ts b/tests/partials_test.ts index 2b210a95..ef18783c 100644 --- a/tests/partials_test.ts +++ b/tests/partials_test.ts @@ -1382,3 +1382,26 @@ Deno.test("supports relative links", async () => { }, ); }); + +Deno.test("nested partials are able to be updated", async () => { + await withPageName( + "./tests/fixture_partials/main.ts", + async (page, address) => { + await page.goto(`${address}/nested`); + await page.waitForSelector(".status-outer"); + await page.waitForSelector(".status-inner"); + + await page.click(".update-outer"); + await waitForText(page, ".status-outer", "updated outer"); + await waitForText(page, ".status-inner", "inner"); + + await page.click(".update-inner"); + await waitForText(page, ".status-outer", "updated outer"); + await waitForText(page, ".status-inner", "updated inner"); + + await page.click(".update-outer"); + await waitForText(page, ".status-outer", "updated outer"); + await waitForText(page, ".status-inner", "inner"); + }, + ); +});