fix: only send revive() script when needed (#1825)
This commit is contained in:
@@ -113,7 +113,9 @@ export function renderFreshTags(
|
||||
script += `import p${i} from "${url}";runPlugin(p${i},STATE[1][${i}]);`;
|
||||
}
|
||||
|
||||
if (renderState.encounteredIslands.size > 0 || renderState.partialCount > 0) {
|
||||
const needsMainScript = renderState.encounteredIslands.size > 0 ||
|
||||
renderState.partialCount > 0;
|
||||
if (needsMainScript) {
|
||||
// Load the main.js script
|
||||
const url = addImport("main.js");
|
||||
script += `import { revive } from "${url}";`;
|
||||
@@ -135,8 +137,10 @@ export function renderFreshTags(
|
||||
}
|
||||
|
||||
// Always revive to detect partials
|
||||
script += `const propsArr = typeof STATE !== "undefined" ? STATE[0] : [];`;
|
||||
script += `revive({${islandRegistry}}, propsArr);`;
|
||||
if (needsMainScript) {
|
||||
script += `const propsArr = typeof STATE !== "undefined" ? STATE[0] : [];`;
|
||||
script += `revive({${islandRegistry}}, propsArr);`;
|
||||
}
|
||||
|
||||
// Append the inline script.
|
||||
if (isPartial && Object.keys(islandMapping).length > 0) {
|
||||
|
||||
@@ -70,6 +70,24 @@ Deno.test("warns on missing partial", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("does not include revive() when no island present", async () => {
|
||||
await withPageName(
|
||||
"./tests/fixture_partials/main.ts",
|
||||
async (page, address) => {
|
||||
const logs: string[] = [];
|
||||
page.on("pageerror", (msg) => logs.push(msg.message));
|
||||
|
||||
const initialUrl = `${address}`;
|
||||
await page.goto(initialUrl, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
|
||||
// Should not error
|
||||
assertEquals(logs, []);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("injects content with island and keeps island instance alive", async () => {
|
||||
await withPageName(
|
||||
"./tests/fixture_partials/main.ts",
|
||||
|
||||
Reference in New Issue
Block a user