Summary
When an index.tsx or [catchall].tsx route module exports client
middleware, the generated main.tsx imports the module eagerly, but Client
treats index/catchall as a lazy loader and calls it as a function. The call
throws a TypeError whenever that route's lazy loader runs.
Where
At 64fc98e:
src/_build.ts:307 and src/_build.ts:310: when hasMiddlewareExport is
true, properties.index and properties.catchall get directImport
(await import("…")), which is the module namespace object.
src/client.tsx:53 and :58: ClientRoute.index / .catchall are typed
RouteModuleLoader only. Unlike main, they have no RouteModule branch.
src/client.tsx:183 and :216: both are always passed to
createLazyRoute(route.index, …) / createLazyRoute(route.catchall, …).
src/_client.tsx createLazyRoute: await lazyRouteFile() on a module
object throws TypeError: lazyRouteFile is not a function. That lands in the
load-failure recovery branch, which treats it as a stale-deploy chunk failure
and hard-navigates to the destination. The retry guard (shouldReload,
MAX_RELOAD_RETRIES within RELOAD_WINDOW_MS) should eventually stop the
reloads and surface the error, but the page reloads repeatedly first. The
exact runtime reload behavior is UNVERIFIED.
There is a second problem even without the crash: middleware can't be lazy in
React Router, so createLazyRoute strips it. An index or catchall route's
client middleware therefore never runs through this path.
Expected
An index or catchall .tsx module that exports middleware builds and runs,
with its middleware applied, the same way a main.tsx or regular child route
does: an eager RouteModule whose route object is built by createRoute.
Notes
Found during review of #136. That PR doesn't fix this; it only adds
shouldRevalidate passthrough.
Summary
When an
index.tsxor[catchall].tsxroute module exports clientmiddleware, the generatedmain.tsximports the module eagerly, butClienttreats
index/catchallas a lazy loader and calls it as a function. The callthrows a
TypeErrorwhenever that route's lazy loader runs.Where
At
64fc98e:src/_build.ts:307andsrc/_build.ts:310: whenhasMiddlewareExportistrue,
properties.indexandproperties.catchallgetdirectImport(
await import("…")), which is the module namespace object.src/client.tsx:53and:58:ClientRoute.index/.catchallare typedRouteModuleLoaderonly. Unlikemain, they have noRouteModulebranch.src/client.tsx:183and:216: both are always passed tocreateLazyRoute(route.index, …)/createLazyRoute(route.catchall, …).src/_client.tsxcreateLazyRoute:await lazyRouteFile()on a moduleobject throws
TypeError: lazyRouteFile is not a function. That lands in theload-failure recovery branch, which treats it as a stale-deploy chunk failure
and hard-navigates to the destination. The retry guard (
shouldReload,MAX_RELOAD_RETRIESwithinRELOAD_WINDOW_MS) should eventually stop thereloads and surface the error, but the page reloads repeatedly first. The
exact runtime reload behavior is UNVERIFIED.
There is a second problem even without the crash: middleware can't be lazy in
React Router, so
createLazyRoutestrips it. An index or catchall route'sclient middleware therefore never runs through this path.
Expected
An index or catchall
.tsxmodule that exportsmiddlewarebuilds and runs,with its middleware applied, the same way a
main.tsxor regular child routedoes: an eager
RouteModulewhose route object is built bycreateRoute.Notes
Found during review of #136. That PR doesn't fix this; it only adds
shouldRevalidatepassthrough.