feat(server): plugins can create islands (#1472)

This commit is contained in:
Reed von Redwitz
2023-11-22 11:19:13 +01:00
committed by GitHub
parent ad2341dada
commit 72edafde46
9 changed files with 137 additions and 11 deletions
+16 -4
View File
@@ -1,6 +1,7 @@
import { MiddlewareHandlerContext, Plugin } from "$fresh/server.ts";
import { handler as testMiddleware } from "./sample_routes/_middleware.ts";
import { AppBuilder } from "./sample_routes/AppBuilder.tsx";
import IslandPluginComponent from "./sample_routes/PluginRouteWithIsland.tsx";
import { SimpleRoute } from "./sample_routes/simple-route.tsx";
export type { Options };
@@ -43,9 +44,20 @@ export default function routePlugin(
},
path: "lots-of-middleware",
}],
routes: [{
path: "/_app",
component: AppBuilder(options),
}, { path: "no-leading-slash-here", component: SimpleRoute }],
routes: [
{
path: "/_app",
component: AppBuilder(options),
},
{ path: "no-leading-slash-here", component: SimpleRoute },
{
path: "pluginroutewithisland",
component: IslandPluginComponent,
},
],
islands: {
baseLocation: import.meta.url,
paths: ["./sample_islands/IslandFromPlugin.tsx"],
},
};
}
@@ -0,0 +1,10 @@
import { IS_BROWSER } from "../../../../src/runtime/utils.ts";
export default function IslandFromPlugin() {
const id = IS_BROWSER ? "csr_alt_folder" : "ssr_alt_folder";
return (
<div>
<p id={id}>{id}</p>
</div>
);
}
@@ -0,0 +1,11 @@
import Island from "../../islands/Island.tsx";
import IslandFromPlugin from "../sample_islands/IslandFromPlugin.tsx";
export default function IslandPluginComponent() {
return (
<div>
<Island />
<IslandFromPlugin />
</div>
);
}
+28
View File
@@ -107,6 +107,34 @@ Deno.test("plugin route no leading slash", async () => {
);
});
Deno.test({
name: "plugin supports islands",
async fn(t) {
await withPageName(
"./tests/fixture_plugin/main.ts",
async (page, address) => {
async function idTest(id: string) {
const elem = await page.waitForSelector(`#${id}`);
const value = await elem?.evaluate((el) => el.textContent);
assert(value === `${id}`, `value ${value} not equal to id ${id}`);
}
await page.goto(`${address}/pluginroutewithisland`, {
waitUntil: "networkidle2",
});
await t.step("verify tags", async () => {
await idTest("csr");
await idTest("csr_alt_folder");
});
},
);
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "/with-island hydration",
async fn(t) {