fix: Outlet's SPA fallback honours Route.static's load#49
Merged
Conversation
Fallback branch only checked route._loader and route._handlers. Route.static sets neither — its loader lives inside _staticConfig.load. So hasHooks was false, the fallback block was skipped, and routeData stayed at its default with data: undefined. route.render(undefined) then crashed on any static-route render that touched its data arg. Fallback now also runs _staticConfig?.load when present. Fixes Route.static in pure-SPA mode; also stops 'provider dropped through unexpectedly' cases from presenting as opaque 'Cannot read properties of undefined' errors from user code. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Deploying effex-api with
|
| Latest commit: |
932821b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://03e64dac.effex-api.pages.dev |
| Branch Preview URL: | https://fix-outlet-static-route-fall.effex-api.pages.dev |
Deploying effex with
|
| Latest commit: |
932821b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b6aef497.effex.pages.dev |
| Branch Preview URL: | https://fix-outlet-static-route-fall.effex.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`Outlet`'s fallback branch for "no `RouteDataProvider` in context" only checked `route._loader` and `route._handlers`. `Route.static` sets neither — its loader lives inside `_staticConfig.load` — so `hasHooks` was `false` for any static route, the branch was skipped, and `routeData` stayed at its initialized default:
```ts
let routeData: RouteDataService = {
data: undefined, // <-- STAYS undefined
loaderPath,
actions: {},
};
```
Then `route.render(routeData.data)` → user's render receives `undefined` → crashes on anything reading `data.title` / `data.foo` / etc.
Fix
Extend the fallback to run `_staticConfig?.load` when present:
```ts
const hasLoader =
route._loader != null || route._staticConfig?.load != null;
const hasHooks =
hasLoader || (route._handlers && route._handlers.length > 0);
if (hasHooks) {
const data = route._loader
? yield* route._loader({...})
: route._staticConfig?.load
? yield* route._staticConfig.load({ params: currentMatch.params })
: undefined;
routeData = { data, loaderPath, actions };
}
```
When this fires
Test plan
🤖 Generated with Claude Code