Skip to content

React Router 7 GetLoadContext not available when using unstable_middleware #514

@jpinn97

Description

@jpinn97

``The getLoadContext function allows us to pass really anything to the context for usage in our React router loaders. The new unstable_middlewares flag means that getLoadContext doesn't return AppLoadContext, it returns an unstable_InitialContext which is a Map<unstable_RouterContext, unknown>.

THat is my understanding on the update. And my idea what it should be like, but basically a map of those contexts should be returned.

type AdapterContextType = {
	session: FastifySessionObject;
};

export const adapterContext = unstable_createContext<AdapterContextType>();

await app.register(reactRouterFastify, {
	getLoadContext(request: FastifyRequest): unstable_InitialContext {
		const map = new Map<unstable_RouterContext, unknown>();
		map.set(adapterContext, { session: request.session });
		return map;
	},
});

Essentially this code is used to pass the session to rr7, consoleing the context provides unstable_RouterContextProvider {}, and doing a context.get(adapterContext) provides no value for this context.

Perhaps I'm not understanding the usage, I had tried this with the middlewares in rr7 but had no values to get htere too.

I would appreciate this very much if you could look into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions