Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/outlet-static-route-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effex/router": patch
---

Fix `Outlet`'s SPA fallback (no `RouteDataProvider` in context) to honour `Route.static`. The fallback branch only checked `route._loader` and `route._handlers` — `Route.static` puts its loader inside `_staticConfig.load` and sets neither of those, so `hasHooks` was `false`, the branch was skipped, and `routeData` stayed at its default with `data: undefined`. `route.render(undefined)` then crashed on any static-route render function that touched its `data` argument.

Now the fallback also runs `_staticConfig?.load` when present. `Route.static` routes work correctly in pure-SPA mode (no `@effex/platform`), and the "provider dropped through unexpectedly" cases stop presenting as opaque `Cannot read properties of undefined` from user code.
16 changes: 13 additions & 3 deletions packages/router/src/Outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,27 @@ const renderRouteWithGuard = <E, R>(
return yield* $.div();
}
} else {
// SPA fallback: no data provider in context (e.g. SPA-only app, or a
// component tree with a data provider bypassed). Run whichever loader
// the route has directly. Route.get sets `_loader`; Route.static puts
// its loader inside `_staticConfig.load` — both need to be honoured or
// the route's render will receive undefined data and crash.
const hasLoader =
route._loader != null || route._staticConfig?.load != null;
const hasHooks =
route._loader || (route._handlers && route._handlers.length > 0);
hasLoader || (route._handlers && route._handlers.length > 0);

if (hasHooks) {
// Default: run the loader directly, compute action paths
const data = route._loader
? yield* route._loader({
params: currentMatch.params,
searchParams: searchParamsObj,
})
: undefined;
: route._staticConfig?.load
? yield* route._staticConfig.load({
params: currentMatch.params,
})
: undefined;

const actions: Record<string, string> = {};
for (const h of route._handlers) {
Expand Down
Loading