diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index a981ca42..d708a71c 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -687,6 +687,12 @@ export async function applyPartials(res: Response): Promise { 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]; diff --git a/tests/fixture_partials/fresh.gen.ts b/tests/fixture_partials/fresh.gen.ts index 93fa50dc..d682bc98 100644 --- a/tests/fixture_partials/fresh.gen.ts +++ b/tests/fixture_partials/fresh.gen.ts @@ -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, diff --git a/tests/fixture_partials/routes/no_partial_response/index.tsx b/tests/fixture_partials/routes/no_partial_response/index.tsx new file mode 100644 index 00000000..7d76e8b5 --- /dev/null +++ b/tests/fixture_partials/routes/no_partial_response/index.tsx @@ -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 ( +
+ + +

Initial content

+ +
+
+

+ + update + +

+

+    
+ ); +} diff --git a/tests/fixture_partials/routes/no_partial_response/injected.tsx b/tests/fixture_partials/routes/no_partial_response/injected.tsx new file mode 100644 index 00000000..7606f2f6 --- /dev/null +++ b/tests/fixture_partials/routes/no_partial_response/injected.tsx @@ -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", + }, + }); +}); diff --git a/tests/fixture_partials/routes/no_partial_response/update.tsx b/tests/fixture_partials/routes/no_partial_response/update.tsx new file mode 100644 index 00000000..48077539 --- /dev/null +++ b/tests/fixture_partials/routes/no_partial_response/update.tsx @@ -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

append content

; +}); diff --git a/tests/partials_test.ts b/tests/partials_test.ts index 37345bf6..631e2923 100644 --- a/tests/partials_test.ts +++ b/tests/partials_test.ts @@ -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 diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 406f406f..e89f8511 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -155,7 +155,7 @@ export default function DocsPage(props: PageProps) { -
+