feat: Nested partials support (#1955)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 (
|
||||
<Partial name="inner">
|
||||
<Logger name="inner">
|
||||
<Fader>
|
||||
<p class="status-inner">inner</p>
|
||||
</Fader>
|
||||
</Logger>
|
||||
</Partial>
|
||||
);
|
||||
}
|
||||
|
||||
function Outer({ children }: { children: ComponentChildren }) {
|
||||
return (
|
||||
<Partial name="outer">
|
||||
<Logger name="outer">
|
||||
<Fader>
|
||||
<p class="status-outer">outer</p>
|
||||
|
||||
{children}
|
||||
</Fader>
|
||||
</Logger>
|
||||
</Partial>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SlotDemo() {
|
||||
return (
|
||||
<div>
|
||||
<Outer>
|
||||
<Inner />
|
||||
</Outer>
|
||||
<p>
|
||||
<button
|
||||
class="update-outer"
|
||||
f-partial="/nested/outer"
|
||||
>
|
||||
update outer component
|
||||
</button>
|
||||
<button
|
||||
class="update-inner"
|
||||
f-partial="/nested/inner"
|
||||
>
|
||||
update inner component
|
||||
</button>
|
||||
</p>
|
||||
<pre id="logs" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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(() => (
|
||||
<div>
|
||||
<div>
|
||||
<Partial name="inner">
|
||||
<Logger name="inner">
|
||||
<Fader>
|
||||
<p class="status-inner">updated inner</p>
|
||||
</Fader>
|
||||
</Logger>
|
||||
</Partial>
|
||||
</div>
|
||||
</div>
|
||||
));
|
||||
@@ -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(() => (
|
||||
<div>
|
||||
<div>
|
||||
<Partial name="outer">
|
||||
<Logger name="outer">
|
||||
<Fader>
|
||||
<p class="status-outer">updated outer</p>
|
||||
|
||||
<Inner />
|
||||
</Fader>
|
||||
</Logger>
|
||||
</Partial>
|
||||
</div>
|
||||
</div>
|
||||
));
|
||||
@@ -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");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user