From cd971d08cefc7ce2565427452d01a3e8e05895eb Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 19 Dec 2022 17:33:59 -0500 Subject: [PATCH] Adjust hasErrorBoundary logic --- packages/remix-react/browser.tsx | 3 ++- packages/remix-react/routes.tsx | 15 +++++++++++++-- packages/remix-react/server.tsx | 6 +++++- packages/remix-server-runtime/routes.ts | 13 +++++++++---- packages/remix-server-runtime/server.ts | 2 +- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/remix-react/browser.tsx b/packages/remix-react/browser.tsx index e2993283335..db53e8fe016 100644 --- a/packages/remix-react/browser.tsx +++ b/packages/remix-react/browser.tsx @@ -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; diff --git a/packages/remix-react/routes.tsx b/packages/remix-react/routes.tsx index 15c237a7da3..3c3a7f7c2bb 100644 --- a/packages/remix-react/routes.tsx +++ b/packages/remix-react/routes.tsx @@ -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 { [routeId: string]: Route; @@ -41,13 +42,18 @@ export interface EntryRoute extends Route { export function createServerRoutes( manifest: RouteManifest, 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: , @@ -71,13 +77,18 @@ export function createServerRoutes( export function createClientRoutes( manifest: RouteManifest, 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, diff --git a/packages/remix-react/server.tsx b/packages/remix-react/server.tsx index 2525ee24945..07b48c51733 100644 --- a/packages/remix-react/server.tsx +++ b/packages/remix-react/server.tsx @@ -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 ( diff --git a/packages/remix-server-runtime/routes.ts b/packages/remix-server-runtime/routes.ts index 19a48e589f4..e22e11cbc62 100644 --- a/packages/remix-server-runtime/routes.ts +++ b/packages/remix-server-runtime/routes.ts @@ -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 { @@ -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 diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 39c26ca934d..a75dca78049 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -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);