fix: __FRSH_BUILD_ID is not defined (#1207)
This could happen if the runtime/utils.ts coe was loaded prior to server/constants.ts, because they had some shared state on `globalThis`. I have mitigated this by not relying on global state anymore. Fixes #1191 --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
co-authored by
Asher Gomez
parent
675036b33c
commit
87b087e358
+6
-5
@@ -9,6 +9,7 @@ import {
|
||||
} from "./deps.ts";
|
||||
import manifest from "./fixture/fresh.gen.ts";
|
||||
import options from "./fixture/options.ts";
|
||||
import { BUILD_ID } from "../src/server/build_id.ts";
|
||||
|
||||
const ctx = await ServerContext.fromManifest(manifest, options);
|
||||
const handler = ctx.handler();
|
||||
@@ -345,7 +346,7 @@ Deno.test("static file - by 'hashed' path", async () => {
|
||||
const body = await resp.text();
|
||||
const imgFilePath = body.match(/img id="img-with-hashing" src="(.*?)"/)?.[1];
|
||||
assert(imgFilePath);
|
||||
assert(imgFilePath.includes(`?__frsh_c=${globalThis.__FRSH_BUILD_ID}`));
|
||||
assert(imgFilePath.includes(`?__frsh_c=${BUILD_ID}`));
|
||||
|
||||
// check the static file is served corectly under its cacheable route
|
||||
const resp2 = await router(
|
||||
@@ -373,20 +374,20 @@ Deno.test("static file - by 'hashed' path", async () => {
|
||||
)?.[1];
|
||||
assert(imgFilePathWithNoCache);
|
||||
assert(
|
||||
!imgFilePathWithNoCache.includes(globalThis.__FRSH_BUILD_ID),
|
||||
!imgFilePathWithNoCache.includes(BUILD_ID),
|
||||
"img-without-hashing",
|
||||
);
|
||||
|
||||
// ensure asset hook is applied on img within an island
|
||||
const imgInIsland = body.match(/img id="img-in-island" src="(.*?)"/)?.[1];
|
||||
assert(imgInIsland);
|
||||
assert(imgInIsland.includes(globalThis.__FRSH_BUILD_ID), "img-in-island");
|
||||
assert(imgInIsland.includes(BUILD_ID), "img-in-island");
|
||||
|
||||
// verify that the asset hook is applied to the srcset
|
||||
const imgInIslandSrcSet = body.match(/srcset="(.*?)"/)?.[1];
|
||||
assert(imgInIslandSrcSet);
|
||||
assert(
|
||||
imgInIslandSrcSet.includes(globalThis.__FRSH_BUILD_ID),
|
||||
imgInIslandSrcSet.includes(BUILD_ID),
|
||||
"img-in-island-srcset",
|
||||
);
|
||||
|
||||
@@ -394,7 +395,7 @@ Deno.test("static file - by 'hashed' path", async () => {
|
||||
const imgMissing = body.match(/img id="img-missing" src="(.*?)"/)?.[1];
|
||||
assert(imgMissing);
|
||||
assert(
|
||||
!imgMissing.includes(globalThis.__FRSH_BUILD_ID),
|
||||
!imgMissing.includes(BUILD_ID),
|
||||
"Applying hash on unknown asset",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user