Skip to content

Commit 2a16477

Browse files
committed
Refactor
1 parent 4366a72 commit 2a16477

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

packages/react-router/lib/dom/ssr/routes.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,12 @@ export function createClientRoutes(
502502
}
503503

504504
dataRoute.lazy = {
505-
loader: dataRoute.loader
506-
? undefined
507-
: async () => {
508-
let { clientLoader } = await getLazyRoute();
509-
if (clientLoader) {
505+
loader:
506+
dataRoute.loader || !route.hasClientLoader
507+
? undefined
508+
: async () => {
509+
let { clientLoader } = await getLazyRoute();
510+
invariant(clientLoader, "No `clientLoader` export found");
510511
return (args: LoaderFunctionArgs, singleFetch?: unknown) =>
511512
clientLoader({
512513
...args,
@@ -515,13 +516,13 @@ export function createClientRoutes(
515516
return fetchServerLoader(singleFetch);
516517
},
517518
});
518-
}
519-
},
520-
action: dataRoute.action
521-
? undefined
522-
: async () => {
523-
let { clientAction } = await getLazyRoute();
524-
if (clientAction) {
519+
},
520+
action:
521+
dataRoute.action || !route.hasClientAction
522+
? undefined
523+
: async () => {
524+
let { clientAction } = await getLazyRoute();
525+
invariant(clientAction, "No `clientAction` export found");
525526
return (args: ActionFunctionArgs, singleFetch?: unknown) =>
526527
clientAction({
527528
...args,
@@ -530,8 +531,7 @@ export function createClientRoutes(
530531
return fetchServerAction(singleFetch);
531532
},
532533
});
533-
}
534-
},
534+
},
535535
unstable_middleware: !route.hasClientMiddleware
536536
? undefined
537537
: async () => {
@@ -542,7 +542,7 @@ export function createClientRoutes(
542542
);
543543
invariant(
544544
clientMiddlewareModule?.unstable_clientMiddleware,
545-
"No `unstable_clientMiddleware` export in chunk"
545+
"No `unstable_clientMiddleware` export found"
546546
);
547547
return clientMiddlewareModule.unstable_clientMiddleware;
548548
},
@@ -559,7 +559,9 @@ export function createClientRoutes(
559559
// No need to wrap these in layout since the root route is never
560560
// loaded via route.lazy()
561561
Component: async () => (await getLazyRoute()).Component,
562-
ErrorBoundary: async () => (await getLazyRoute()).ErrorBoundary,
562+
ErrorBoundary: route.hasErrorBoundary
563+
? async () => (await getLazyRoute()).ErrorBoundary
564+
: undefined,
563565
};
564566
}
565567

packages/react-router/lib/router/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ export interface MapRoutePropertiesFunction {
388388
}
389389

390390
/**
391-
* Keys we cannot change from within a lazy object.
391+
* Keys we cannot change from within a lazy object. We spread all other keys
392+
* onto the route. Either they're meaningful to the router, or they'll get
393+
* ignored.
392394
*/
393395
type UnsupportedLazyRouteObjectKey =
394396
| "lazy"

0 commit comments

Comments
 (0)