Skip to content

Commit

Permalink
Adjust hasErrorBoundary logic
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Dec 19, 2022
1 parent ae9c4c1 commit cd971d0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/remix-react/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function RemixBrowser(_props: RemixBrowserProps): ReactElement {
if (!router) {
let routes = createClientRoutes(
window.__remixManifest.routes,
window.__remixRouteModules
window.__remixRouteModules,
window.__remixContext.future
);

let hydrationData = window.__remixContext.state;
Expand Down
15 changes: 13 additions & 2 deletions packages/remix-react/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { fetchData, isCatchResponse, isRedirectResponse } from "./data";
import { prefetchStyleLinks } from "./links";
import invariant from "./invariant";
import { RemixRoute, RemixRouteError } from "./components";
import { FutureConfig } from "./entry";

export interface RouteManifest<Route> {
[routeId: string]: Route;
Expand Down Expand Up @@ -41,13 +42,18 @@ export interface EntryRoute extends Route {
export function createServerRoutes(
manifest: RouteManifest<EntryRoute>,
routeModules: RouteModules,
future: FutureConfig,
parentId?: string
): DataRouteObject[] {
return Object.values(manifest)
.filter((route) => route.parentId === parentId)
.map((route) => {
let hasErrorBoundary =
route.id === "root" || route.hasErrorBoundary || route.hasCatchBoundary;
future.v2_errorBoundary === true
? route.id === "root" || route.hasErrorBoundary
: route.id === "root" ||
route.hasCatchBoundary ||
route.hasErrorBoundary;
let dataRoute: DataRouteObject = {
caseSensitive: route.caseSensitive,
element: <RemixRoute id={route.id} />,
Expand All @@ -71,13 +77,18 @@ export function createServerRoutes(
export function createClientRoutes(
manifest: RouteManifest<EntryRoute>,
routeModulesCache: RouteModules,
future: FutureConfig,
parentId?: string
): DataRouteObject[] {
return Object.values(manifest)
.filter((entryRoute) => entryRoute.parentId === parentId)
.map((route) => {
let hasErrorBoundary =
route.id === "root" || route.hasErrorBoundary || route.hasCatchBoundary;
future.v2_errorBoundary === true
? route.id === "root" || route.hasErrorBoundary
: route.id === "root" ||
route.hasCatchBoundary ||
route.hasErrorBoundary;

let dataRoute: DataRouteObject = {
caseSensitive: route.caseSensitive,
Expand Down
6 changes: 5 additions & 1 deletion packages/remix-react/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export function RemixServer({ context, url }: RemixServerProps): ReactElement {
}

let { manifest, routeModules, serverHandoffString } = context;
let routes = createServerRoutes(manifest.routes, routeModules);
let routes = createServerRoutes(
manifest.routes,
routeModules,
context.future
);
let router = createStaticRouter(routes, context.staticHandlerContext);

return (
Expand Down
13 changes: 9 additions & 4 deletions packages/remix-server-runtime/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
} from "@remix-run/router";

import { callRouteActionRR, callRouteLoaderRR } from "./data";
import { FutureConfig } from "./entry";
import type { ServerRouteModule } from "./routeModules";

export interface RouteManifest<Route> {
Expand Down Expand Up @@ -54,17 +55,21 @@ export function createRoutes(
// createStaticHandler
export function createStaticHandlerDataRoutes(
manifest: ServerRouteManifest,
future: FutureConfig,
parentId?: string
): AgnosticDataRouteObject[] {
return Object.values(manifest)
.filter((route) => route.parentId === parentId)
.map((route) => {
let hasErrorBoundary =
future.v2_errorBoundary === true
? route.id === "root" || route.module.ErrorBoundary != null
: route.id === "root" ||
route.module.CatchBoundary != null ||
route.module.ErrorBoundary != null;
let commonRoute = {
// Always include root due to default boundaries
hasErrorBoundary:
route.id === "root" ||
route.module.CatchBoundary != null ||
route.module.ErrorBoundary != null,
hasErrorBoundary,
id: route.id,
path: route.path,
loader: route.module.loader
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createRequestHandler: CreateRequestHandlerFunction = (
mode
) => {
let routes = createRoutes(build.routes);
let dataRoutes = createStaticHandlerDataRoutes(build.routes);
let dataRoutes = createStaticHandlerDataRoutes(build.routes, build.future);
let serverMode = isServerMode(mode) ? mode : ServerMode.Production;
let staticHandler = createStaticHandler(dataRoutes);

Expand Down

0 comments on commit cd971d0

Please sign in to comment.