Skip to content

Commit 8b692fb

Browse files
committed
Fix middleware on initial load without loaders
1 parent eebd2e8 commit 8b692fb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.changeset/twelve-dogs-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Fix Data Mode regression causing a 404 during initial load in when `middleware` exists without any `loader` functions

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5751,6 +5751,19 @@ function getDataStrategyMatch(
57515751
!isMutationMethod(request.method) &&
57525752
(match.route.lazy || match.route.loader))
57535753
) {
5754+
// If this match was marked `shouldLoad` due to a middleware and it
5755+
// doesn't have a `loader` to run and no `lazy` to add one, then we can
5756+
// just return undefined from the "loader" here
5757+
if (
5758+
match.route.middleware &&
5759+
match.route.middleware.length > 0 &&
5760+
match.route.loader == null &&
5761+
!match.route.lazy &&
5762+
!handlerOverride
5763+
) {
5764+
return Promise.resolve({ type: ResultType.data, result: undefined });
5765+
}
5766+
57545767
return callLoaderOrAction({
57555768
request,
57565769
match,

0 commit comments

Comments
 (0)