Skip to content

Commit f97105b

Browse files
authored
Proxy server loader errors through serverLoader during hydration (#8304)
1 parent 37ee74e commit f97105b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

integration/client-data-test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { test, expect } from "@playwright/test";
22

3+
import { ServerMode } from "../packages/remix-server-runtime/mode.js";
34
import {
45
createAppFixture,
56
createFixture,
@@ -724,6 +725,61 @@ test.describe("Client Data", () => {
724725
html = await app.getHtml("main");
725726
expect(html).toMatch("Child Server Loader Data (2+) (mutated by client)");
726727
});
728+
729+
test("server loader errors are re-thrown from serverLoader()", async ({
730+
page,
731+
}) => {
732+
let _consoleError = console.error;
733+
console.error = () => {};
734+
appFixture = await createAppFixture(
735+
await createFixture(
736+
{
737+
files: {
738+
...getFiles({
739+
parentClientLoader: false,
740+
parentClientLoaderHydrate: false,
741+
childClientLoader: false,
742+
childClientLoaderHydrate: false,
743+
}),
744+
"app/routes/parent.child.tsx": js`
745+
import { ClientLoaderFunctionArgs, useRouteError } from "@remix-run/react";
746+
747+
export function loader() {
748+
throw new Error("Broken!")
749+
}
750+
751+
export async function clientLoader({ serverLoader }) {
752+
return await serverLoader();
753+
}
754+
clientLoader.hydrate = true;
755+
756+
export default function Index() {
757+
return <h1>Should not see me</h1>;
758+
}
759+
760+
export function ErrorBoundary() {
761+
let error = useRouteError();
762+
return <p id="child-error">{error.message}</p>;
763+
}
764+
`,
765+
},
766+
},
767+
ServerMode.Development // Avoid error sanitization
768+
),
769+
ServerMode.Development // Avoid error sanitization
770+
);
771+
let app = new PlaywrightFixture(appFixture, page);
772+
773+
await app.goto("/parent/child");
774+
let html = await app.getHtml("main");
775+
expect(html).toMatch("Broken!");
776+
// Ensure we hydrate and remain on the boundary
777+
await new Promise((r) => setTimeout(r, 100));
778+
html = await app.getHtml("main");
779+
expect(html).toMatch("Broken!");
780+
expect(html).not.toMatch("Should not see me");
781+
console.error = _consoleError;
782+
});
727783
});
728784

729785
test.describe("clientLoader - lazy route module", () => {

0 commit comments

Comments
 (0)