fix: bring back island module preloading (#2503)

This commit is contained in:
Marvin Hagemeister
2024-06-05 14:41:02 +02:00
committed by GitHub
parent f09130cebf
commit 19d3e452ac
3 changed files with 48 additions and 1 deletions
+27
View File
@@ -30,6 +30,7 @@ import { setBuildCache } from "../src/app.ts";
import { getBuildCache } from "../src/app.ts";
import type { FreshConfig } from "../src/config.ts";
import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx";
import { FakeServer } from "../src/test_utils.ts";
await buildProd(allIslandApp);
@@ -659,3 +660,29 @@ Deno.test({
});
},
});
Deno.test({
name: "islands - adds preload HTTP headers",
fn: async () => {
const selfCounter = getIsland("SelfCounter.tsx");
const app = testApp()
.use(staticFiles())
.island(selfCounter, "SelfCounter", SelfCounter)
.get("/", (ctx) =>
ctx.render(
<Doc>
<SelfCounter />
</Doc>,
));
const server = new FakeServer(await app.handler());
const res = await server.get("/");
await res.body?.cancel();
const link = res.headers.get("Link");
expect(link).toMatch(
/<\/fresh-runtime\.js\?__frsh_c=[^>]+>; rel="modulepreload"; as="script", <\/SelfCounter\.js\?__frsh_c=[^>]+>; rel="modulepreload"; as="script"/,
);
},
});
+1 -1
View File
@@ -162,7 +162,7 @@ export async function withChildProcessServer(
}
if (!found) {
throw new Error(`Could not find server addrews`);
throw new Error(`Could not find server address`);
}
try {