-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Bug Report: getLoadContext incompatible with React Router v7+ RouterContextProvider
Description
The getLoadContext function in the template returns a plain object, which is incompatible with React Router v7.9+ that requires returning an instance of RouterContextProvider when middleware is enabled.
According to React Router v7+ documentation, when middleware is enabled, getLoadContext must return a RouterContextProvider instance:
import { RouterContextProvider } from 'react-router';
const someContext = createContext<string | null>(null)
getLoadContext(context) {
const ctx = new RouterContextProvider();
ctx.set(someContext, 'value');
return ctx;
}Problem with Current Behavior
When attempting to return a RouterContextProvider instance (even while ignoring TypeScript errors), the context values are not properly set. When trying to access the context in server loaders or actions, the values are set to their initial values null, as if the context was never changed.
Environment
- elysia-react-router: ^0.4.4
- react-router: ^7.9.5
- @react-router/node: ^7.9.5
- @react-router/serve: ^7.9.5
- elysia: ^1.4.13
- vite: ^7.1.12
- Runtime: Bun v1.3.1+
Steps to Reproduce
- Set up elysia-react-router with React Router v7.9+
- Configure
getLoadContextto return a plain object - Observe the runtime error about invalid context
- Try to fix by returning
RouterContextProviderinstance - Access context in a route loader/action
- Observe that context still have the initial value.
Ps: ai generated report :>
Metadata
Metadata
Assignees
Labels
No labels