Skip to content

Action handler is not called on a route with middleware unless a loader is also present #14429

@carlosalbertolajr

Description

@carlosalbertolajr

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:

  1. Clone the repository, then run npm install and npm run dev.
  2. Navigate to the /action-and-middleware route in your browser.
  3. Open the terminal where the development server is running to view the logs.
  4. Click the "Button 1" on the page.
  5. 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.

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