-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
Reproduction
I have created a minimal reproducible example in a GitHub repository that demonstrates the issue.
Link to Repository:
https://github.com/carlosalbertolajr/react-router-middleware-with-action-bug
Steps to Reproduce:
- Clone the repository, then run npm install and npm run dev.
- Navigate to the /action-and-middleware route in your browser.
- Open the terminal where the development server is running to view the logs.
- Click the "Button 1" on the page.
- Observe the server logs.
System Info
System:
OS: macOS 15.6.1
CPU: (8) arm64 Apple M2
Memory: 108.73 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.20.0 - /usr/local/bin/node
npm: 11.6.1 - /Users/caju/.npm-global/bin/npm
Browsers:
Chrome: 141.0.7390.56
npmPackages:
react-router: ^7.9.2 => 7.9.3
Used Package Manager
npm
Expected Behavior
When the form on the /action-and-middleware
page is submitted, I expect to see log messages from both the middleware and the action in my server terminal.
The console output should look like this:
POST /action-and-middleware hello from middleware
POST /action-and-middleware hello from action
Actual Behavior
When the form on the /action-and-middleware
page is submitted, only the log message from the middleware is printed to the console. The action function is never executed.
The actual console output is:
POST /action-and-middleware hello from middleware
This behavior seems to be a bug, as the action handler should run independently of whether a loader is present. The issue is resolved if an empty loader function is added to the route, as demonstrated by the /loader-and-action-and-middleware
route in the reproduction repository.