Skip to content

Commit f358a1e

Browse files
test(rsc): add test for sanitized production errors (#13974)
1 parent 68c2ad4 commit f358a1e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

integration/rsc/rsc-test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,55 @@ implementations.forEach((implementation) => {
20492049
// Ensure this is using RSC
20502050
validateRSCHtml(await page.content());
20512051
});
2052+
2053+
test("Handles sanitized production errors in server components correctly", async ({
2054+
page,
2055+
}) => {
2056+
let port = await getPort();
2057+
stop = await setupRscTest({
2058+
implementation,
2059+
port,
2060+
files: {
2061+
"src/routes/home.tsx": js`
2062+
export function loader() {
2063+
throw new Error("This error should be sanitized");
2064+
}
2065+
2066+
export default function HomeRoute() {
2067+
return <h2>This should not be rendered</h2>;
2068+
}
2069+
2070+
export { ErrorBoundary } from "./home.client";
2071+
`,
2072+
"src/routes/home.client.tsx": js`
2073+
"use client"
2074+
import { useRouteError } from "react-router";
2075+
2076+
export function ErrorBoundary() {
2077+
let error = useRouteError();
2078+
return (
2079+
<>
2080+
<h2 data-error-title>Error Caught!</h2>
2081+
<p data-error-message>{error.message}</p>
2082+
</>
2083+
);
2084+
}
2085+
`,
2086+
},
2087+
});
2088+
2089+
await page.goto(`http://localhost:${port}/`);
2090+
2091+
// Verify error boundary is shown
2092+
await page.waitForSelector("[data-error-title]");
2093+
await page.waitForSelector("[data-error-message]");
2094+
expect(await page.locator("[data-error-message]").textContent()).toBe(
2095+
"An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error."
2096+
);
2097+
2098+
// Ensure this is using RSC
2099+
validateRSCHtml(await page.content());
2100+
});
20522101
});
20532102
});
20542103
});

0 commit comments

Comments
 (0)