Skip to content

Commit

Permalink
Fix BoundaryShell usage in default HydrateFallback (#8906)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Feb 27, 2024
1 parent d96d909 commit 3f9c84a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-rice-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

[REMOVE] Fix issue with hydrate fallback boundary shell usage
1 change: 0 additions & 1 deletion integration/root-route-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ test.describe("root route", () => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await page.waitForSelector("h1");
console.log(await app.getHtml());
expect(await app.getHtml("title")).toMatch("Layout Title");
expect(await app.getHtml("h1")).toMatch("Application Error");

Expand Down
2 changes: 2 additions & 0 deletions integration/spa-mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ test.describe("SPA Mode", () => {
let html = await res.text();
expect(html.match(/<html/g)?.length).toBe(1);
expect(html.match(/<\/html/g)?.length).toBe(1);
expect(html.match(/window.__remixContext =/g)?.length).toBe(1);
expect(html.match(/💿 Hey developer 👋/g)?.length).toBe(1);
});
});

Expand Down
38 changes: 20 additions & 18 deletions packages/remix-react/errorBoundaries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import type { Location } from "@remix-run/router";
import { isRouteErrorResponse } from "react-router-dom";

import { useRemixContext } from "./components";
import { Scripts, useRemixContext } from "./components";

type RemixErrorBoundaryProps = React.PropsWithChildren<{
location: Location;
Expand Down Expand Up @@ -66,12 +66,25 @@ export class RemixErrorBoundary extends React.Component<
export function RemixRootDefaultErrorBoundary({ error }: { error: unknown }) {
console.error(error);

let heyDeveloper = (
<script
dangerouslySetInnerHTML={{
__html: `
console.log(
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://remix.run/guides/errors for more information."
);
`,
}}
/>
);

if (isRouteErrorResponse(error)) {
return (
<BoundaryShell title="Unhandled Thrown Response!">
<h1 style={{ fontSize: "24px" }}>
{error.status} {error.statusText}
</h1>
{heyDeveloper}
</BoundaryShell>
);
}
Expand Down Expand Up @@ -102,36 +115,24 @@ export function RemixRootDefaultErrorBoundary({ error }: { error: unknown }) {
>
{errorInstance.stack}
</pre>
{heyDeveloper}
</BoundaryShell>
);
}

export function BoundaryShell({
title,
renderScripts,
children,
}: {
title: string;
renderScripts?: boolean;
children: React.ReactNode | React.ReactNode[];
}) {
let { routeModules } = useRemixContext();

let contents = (
<>
{children}
<script
dangerouslySetInnerHTML={{
__html: `
console.log(
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://remix.run/guides/errors for more information."
);
`,
}}
/>
</>
);

if (routeModules.root?.Layout) {
return contents;
return children;
}

return (
Expand All @@ -146,7 +147,8 @@ export function BoundaryShell({
</head>
<body>
<main style={{ fontFamily: "system-ui, sans-serif", padding: "2rem" }}>
{contents}
{children}
{renderScripts ? <Scripts /> : null}
</main>
</body>
</html>
Expand Down
4 changes: 1 addition & 3 deletions packages/remix-react/fallback.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from "react";

import { Scripts } from "./components";
import { BoundaryShell } from "./errorBoundaries";

// If the user sets `clientLoader.hydrate=true` somewhere but does not
Expand All @@ -9,8 +8,7 @@ import { BoundaryShell } from "./errorBoundaries";
// `clientLoader` functions
export function RemixRootDefaultHydrateFallback() {
return (
<BoundaryShell title="Loading...">
<Scripts />
<BoundaryShell title="Loading..." renderScripts>
<script
dangerouslySetInnerHTML={{
__html: `
Expand Down

0 comments on commit 3f9c84a

Please sign in to comment.