fix: bring back island module preloading (#2503)
This commit is contained in:
@@ -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"/,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user