Skip to content

Loaders not called when any middleware throws an error (Framework mode) #14416

@freshollie

Description

@freshollie

Reproduction

https://stackblitz.com/edit/github-tuw4zfdp?file=app%2Froutes%2Fsuccess.tsx,app%2Froutes%2Fnested.tsx,app%2Froutes%2Ferror.tsx,app%2Froutes.ts,app%2Froutes%2Fhome.tsx

System Info

System:
    OS: macOS 14.8.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 98.63 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.5.1 - ~/Library/Caches/fnm_multishells/38932_1759406901915/bin/node
    Yarn: 3.2.1 - ~/Library/Caches/fnm_multishells/38932_1759406901915/bin/yarn
    npm: 9.8.0 - ~/Library/Caches/fnm_multishells/38932_1759406901915/bin/npm
  Browsers:
    Chrome: 141.0.7390.55
    Safari: 26.0.1
  npmPackages:
    @react-router/dev: 7.9.2 => 7.9.2 
    @react-router/express: 7.9.2 => 7.9.2 
    @react-router/node: 7.9.2 => 7.9.2 
    @react-router/remix-routes-option-adapter: 7.9.2 => 7.9.2
    @react-router/serve: 7.9.2 => 7.9.2 
    react-router: 7.9.2 => 7.9.2 
    vite: ^6.3.5 => 6.3.5

Used Package Manager

yarn

Expected Behavior

From the docs, it seems like middleware should behave the same as loaders/actions. If a child loader/action errors, then the parent route is still rendered but the child route renders an error boundary.

I was expecting middleware to act in exactly the same way.

Actual Behavior

From debugging locally, when a child route middleware throws an error this branch is called:

// We never even got to the handlers, so we've got no data -
which explicitly states that we didn't make it to the "handlers", which I guess means that the loader data is not queried from the parent routes and so we render whatever we can.

If the highest parent has a loader than it will defer to the error boundary of that parent I guess because none of the loader data has been collected.

I am looking for feedback on this though, perhaps my usage in the example is wrong?

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