fix: Partials not working on error pages (#2072)
This commit is contained in:
@@ -639,10 +639,6 @@ class NoPartialsError extends Error {}
|
|||||||
* Apply partials from a HTML response
|
* Apply partials from a HTML response
|
||||||
*/
|
*/
|
||||||
export async function applyPartials(res: Response): Promise<void> {
|
export async function applyPartials(res: Response): Promise<void> {
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(partialErrorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
const contentType = res.headers.get("Content-Type");
|
const contentType = res.headers.get("Content-Type");
|
||||||
if (contentType !== "text/html; charset=utf-8") {
|
if (contentType !== "text/html; charset=utf-8") {
|
||||||
throw new Error(partialErrorMessage);
|
throw new Error(partialErrorMessage);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// This file SHOULD be checked into source version control.
|
// This file SHOULD be checked into source version control.
|
||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import * as $_404 from "./routes/_404.tsx";
|
||||||
import * as $_app from "./routes/_app.tsx";
|
import * as $_app from "./routes/_app.tsx";
|
||||||
import * as $active_nav_foo_bar from "./routes/active_nav/foo/bar.tsx";
|
import * as $active_nav_foo_bar from "./routes/active_nav/foo/bar.tsx";
|
||||||
import * as $active_nav_foo_index from "./routes/active_nav/foo/index.tsx";
|
import * as $active_nav_foo_index from "./routes/active_nav/foo/index.tsx";
|
||||||
@@ -35,6 +36,7 @@ import * as $deep_partial_index from "./routes/deep_partial/index.tsx";
|
|||||||
import * as $deep_partial_injected from "./routes/deep_partial/injected.tsx";
|
import * as $deep_partial_injected from "./routes/deep_partial/injected.tsx";
|
||||||
import * as $deep_partial_update from "./routes/deep_partial/update.tsx";
|
import * as $deep_partial_update from "./routes/deep_partial/update.tsx";
|
||||||
import * as $duplicate_name_index from "./routes/duplicate_name/index.tsx";
|
import * as $duplicate_name_index from "./routes/duplicate_name/index.tsx";
|
||||||
|
import * as $error_404 from "./routes/error_404.tsx";
|
||||||
import * as $form_index from "./routes/form/index.tsx";
|
import * as $form_index from "./routes/form/index.tsx";
|
||||||
import * as $form_injected from "./routes/form/injected.tsx";
|
import * as $form_injected from "./routes/form/injected.tsx";
|
||||||
import * as $form_update from "./routes/form/update.tsx";
|
import * as $form_update from "./routes/form/update.tsx";
|
||||||
@@ -133,6 +135,7 @@ import { Manifest } from "$fresh/server.ts";
|
|||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
|
"./routes/_404.tsx": $_404,
|
||||||
"./routes/_app.tsx": $_app,
|
"./routes/_app.tsx": $_app,
|
||||||
"./routes/active_nav/foo/bar.tsx": $active_nav_foo_bar,
|
"./routes/active_nav/foo/bar.tsx": $active_nav_foo_bar,
|
||||||
"./routes/active_nav/foo/index.tsx": $active_nav_foo_index,
|
"./routes/active_nav/foo/index.tsx": $active_nav_foo_index,
|
||||||
@@ -166,6 +169,7 @@ const manifest = {
|
|||||||
"./routes/deep_partial/injected.tsx": $deep_partial_injected,
|
"./routes/deep_partial/injected.tsx": $deep_partial_injected,
|
||||||
"./routes/deep_partial/update.tsx": $deep_partial_update,
|
"./routes/deep_partial/update.tsx": $deep_partial_update,
|
||||||
"./routes/duplicate_name/index.tsx": $duplicate_name_index,
|
"./routes/duplicate_name/index.tsx": $duplicate_name_index,
|
||||||
|
"./routes/error_404.tsx": $error_404,
|
||||||
"./routes/form/index.tsx": $form_index,
|
"./routes/form/index.tsx": $form_index,
|
||||||
"./routes/form/injected.tsx": $form_injected,
|
"./routes/form/injected.tsx": $form_injected,
|
||||||
"./routes/form/update.tsx": $form_update,
|
"./routes/form/update.tsx": $form_update,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<Partial name="body">
|
||||||
|
<p class="status-404">Not found - Error 404</p>
|
||||||
|
</Partial>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Partial } from "$fresh/runtime.ts";
|
||||||
|
|
||||||
|
export default function ModeDemo() {
|
||||||
|
return (
|
||||||
|
<div f-client-nav>
|
||||||
|
<Partial name="body">
|
||||||
|
<p class="status">default content</p>
|
||||||
|
</Partial>
|
||||||
|
<p>
|
||||||
|
<a
|
||||||
|
class="update-link"
|
||||||
|
href="/error_404/asdf"
|
||||||
|
>
|
||||||
|
update
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1509,3 +1509,16 @@ Deno.test("partials with redirects", async () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("render 404 partial", async () => {
|
||||||
|
await withPageName(
|
||||||
|
"./tests/fixture_partials/main.ts",
|
||||||
|
async (page, address) => {
|
||||||
|
await page.goto(`${address}/error_404`);
|
||||||
|
await page.waitForSelector(".status");
|
||||||
|
|
||||||
|
await page.click(".update-link");
|
||||||
|
await page.waitForSelector(".status-404");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user