fix: throw error when no partials found (#1853)

This commit is contained in:
Marvin Hagemeister
2023-10-04 15:38:43 +02:00
committed by GitHub
parent ea91687ea3
commit be1c15f8f3
7 changed files with 83 additions and 3 deletions
+6
View File
@@ -687,6 +687,12 @@ export async function applyPartials(res: Response): Promise<void> {
sib = sib.nextSibling;
}
if (encounteredPartials.length === 0) {
throw new Error(
`Found no partials in HTML response. Please make sure to render at least one partial. Requested url: ${res.url}`,
);
}
// Update all encountered partials
for (let i = 0; i < encounteredPartials.length; i++) {
const { vnode, marker } = encounteredPartials[i];
+8 -2
View File
@@ -71,7 +71,10 @@ import * as $65 from "./routes/mode/replace.tsx";
import * as $66 from "./routes/no_islands/index.tsx";
import * as $67 from "./routes/no_islands/injected.tsx";
import * as $68 from "./routes/no_islands/update.tsx";
import * as $69 from "./routes/partial_slot_inside_island.tsx";
import * as $69 from "./routes/no_partial_response/index.tsx";
import * as $70 from "./routes/no_partial_response/injected.tsx";
import * as $71 from "./routes/no_partial_response/update.tsx";
import * as $72 from "./routes/partial_slot_inside_island.tsx";
import * as $$0 from "./islands/Counter.tsx";
import * as $$1 from "./islands/CounterA.tsx";
import * as $$2 from "./islands/CounterB.tsx";
@@ -158,7 +161,10 @@ const manifest = {
"./routes/no_islands/index.tsx": $66,
"./routes/no_islands/injected.tsx": $67,
"./routes/no_islands/update.tsx": $68,
"./routes/partial_slot_inside_island.tsx": $69,
"./routes/no_partial_response/index.tsx": $69,
"./routes/no_partial_response/injected.tsx": $70,
"./routes/no_partial_response/update.tsx": $71,
"./routes/partial_slot_inside_island.tsx": $72,
},
islands: {
"./islands/Counter.tsx": $$0,
@@ -0,0 +1,26 @@
import { Partial } from "$fresh/runtime.ts";
import CounterA from "../../islands/CounterA.tsx";
import { Fader } from "../../islands/Fader.tsx";
export default function WarnDemo() {
return (
<div>
<Partial name="slot-1">
<Fader>
<p class="status-initial">Initial content</p>
<CounterA />
</Fader>
</Partial>
<p>
<a
class="update-link"
href="/no_partial_response/injected"
f-partial="/no_partial_response/update"
>
update
</a>
</p>
<pre id="logs"></pre>
</div>
);
}
@@ -0,0 +1,10 @@
import { defineRoute } from "$fresh/src/server/defines.ts";
export default defineRoute(() => {
return new Response("", {
status: 302,
headers: {
Location: "/no_partial_response",
},
});
});
@@ -0,0 +1,11 @@
import { defineRoute } from "$fresh/src/server/defines.ts";
import { RouteConfig } from "$fresh/server.ts";
export const config: RouteConfig = {
skipAppWrapper: true,
skipInheritedLayouts: true,
};
export default defineRoute((req, ctx) => {
return <p class="status-append">append content</p>;
});
+21
View File
@@ -955,5 +955,26 @@ Deno.test("Updates active links outside of vdom", async () => {
);
});
Deno.test("throws an error when response contains no partials", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
const logs: string[] = [];
page.on("pageerror", (msg) => logs.push(msg.message));
await page.goto(`${address}/no_partial_response`);
await waitFor(async () => {
const logEl = await page.$eval("#logs", (el) => el.textContent);
return /mount Counter/.test(logEl);
});
await page.click(".update-link");
await waitFor(() => logs.length > 0);
assertMatch(logs[0], /Found no partials/);
},
);
});
// TODO Head merging
// TODO Children Keys
+1 -1
View File
@@ -155,7 +155,7 @@ export default function DocsPage(props: PageProps<Data>) {
<meta property="og:image" content={ogImageUrl} />
<meta name="view-transition" content="same-origin" />
</Head>
<div class="flex flex-col min-h-screen">
<div class="flex flex-col min-h-screen" f-client-nav>
<Header title="docs" active="/docs" />
<Main page={props.data.page} />
<Footer />