Skip to content

Support react-router middleware api #544

@qur2

Description

@qur2

Is your feature request related to a problem? Please describe.

My project is failing on netlify because I'm using middlewares, which are now stable in react-router. Here is the log:

Sep 24, 08:01:12 AM: dead8f89 ERROR  Error: Invalid `context` value provided to `handleRequest`. When middleware is enabled you must return an instance of `RouterContextProvider` from your `getLoadContext` function.
    at requestHandler (/var/task/node_modules/react-router/dist/development/index.js:1145:21)
    at file:///var/task/node_modules/@netlify/vite-plugin-react-router/dist/index.mjs:14:30
    at async WC (file:///var/task/___netlify-bootstrap.mjs:7:85589)
    at async Runtime.handler (file:///var/task/___netlify-bootstrap.mjs:7:84978)
    at async Runtime.handleOnceStreaming (file:///var/runtime/index.mjs:1239:26)

Describe the solution you'd like

It seems that the problem is fairly easy to fix, as it is documented (see for example the vercel related issue: vercel/vercel#13327).
I believe the code at https://github.com/netlify/remix-compute/blob/main/packages/remix-adapter/src/vite/plugin.ts#L26 needs attention. I don't know about the classic-compiler flavor.

Describe alternatives you've considered

I'm considering switching to a custom request handler to circumvent the issue.

Additional context

It's gonna be standard in the next major, so implementing that now is gonna be helpful to be ahead of the curve.

edit: added more info.
edit2: typos.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions