Skip to content

[Bug]: resource route does not work with HTTP POST #12916

@sdavids

Description

@sdavids

I'm using React Router as a...

framework

Reproduction

The example has a simple resource route.

First terminal:

$ cd /tmp
$ git clone https://github.com/sdavids/react-router-form-post-bug
$ cd react-router-form-post-bug
$ npm i
$ node --run dev

Second terminal:

$ http --form POST http://localhost:5173/to-uppercase content=test
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Thu, 30 Jan 2025 16:43:47 GMT
Keep-Alive: timeout=5
Transfer-Encoding: chunked
Vary: Origin
content-type: text/plain

Unexpected Server Error

Error: Expected a Response to be returned from resource route handler


$ http --form POST http://localhost:5173/to-uppercase content=
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Thu, 30 Jan 2025 16:45:20 GMT
Keep-Alive: timeout=5
Transfer-Encoding: chunked
Vary: Origin
content-type: text/plain

Unexpected Server Error

Error: Expected a Response to be returned from resource route handler


$ http --form POST http://localhost:5173/to-uppercase
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Date: Thu, 30 Jan 2025 16:46:33 GMT
Keep-Alive: timeout=5
Transfer-Encoding: chunked
Vary: Origin
content-type: text/plain

Unexpected Server Error

Error: Expected a Response to be returned from resource route handler

The first terminal will show:

{ message: 'TEST' }
The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose
Error: Expected a Response to be returned from resource route handler
    at invariant3 (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:8539:11)
    at handleResourceRequest (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:9275:5)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at requestHandler (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:9061:18)
    at nodeHandler (/private/tmp/react-router-form-post-bug/node_modules/@react-router/dev/dist/vite.js:2006:30)
    at /private/tmp/react-router-form-post-bug/node_modules/@react-router/dev/dist/vite.js:2012:17
{ error: 'content cannot be empty' }
The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose
Error: Expected a Response to be returned from resource route handler
    at invariant3 (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:8539:11)
    at handleResourceRequest (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:9275:5)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at requestHandler (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:9061:18)
    at nodeHandler (/private/tmp/react-router-form-post-bug/node_modules/@react-router/dev/dist/vite.js:2006:30)
    at /private/tmp/react-router-form-post-bug/node_modules/@react-router/dev/dist/vite.js:2012:17
{ error: 'content cannot be empty' }
The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose
Error: Expected a Response to be returned from resource route handler
    at invariant3 (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:8539:11)
    at handleResourceRequest (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:9275:5)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at requestHandler (file:///private/tmp/react-router-form-post-bug/node_modules/react-router/dist/development/chunk-SYFQ2XB5.mjs:9061:18)
    at nodeHandler (/private/tmp/react-router-form-post-bug/node_modules/@react-router/dev/dist/vite.js:2006:30)
    at /private/tmp/react-router-form-post-bug/node_modules/@react-router/dev/dist/vite.js:2012:17

Open http://localhost:5173 to verify that the application works.

System Info

System:
    OS: macOS 12.7.6
    CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
    Memory: 94.95 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 22.13.0 - ~/.local/run/fnm_multishells/34165_1738255229341/bin/node
    npm: 10.9.2 - ~/.local/run/fnm_multishells/34165_1738255229341/bin/npm
  Browsers:
    Brave Browser: 131.1.73.104
    Chrome: 132.0.6834.112
    Safari: 17.6
  npmPackages:
    @react-router/dev: 7.1.3 => 7.1.3 
    @react-router/node: 7.1.3 => 7.1.3 
    @react-router/serve: 7.1.3 => 7.1.3 
    react-router: 7.1.3 => 7.1.3 
    vite: 6.0.11 => 6.0.11

Used Package Manager

npm

Expected Behavior

The POST request returns a response.

Actual Behavior

Originally I was trying cy.request():

cy.request({
  method: 'POST',
  url: '/to-uppercase',
  body: { content: 'test' },
  form: true,
}).then((res) => {
  expect(res.status).to.eq(200);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions