Skip to content

beforeLoad throwing non-Error value returns empty SSR response instead of rendering error component #7498

@alex35mil

Description

@alex35mil

Which project does this relate to?

Router

Describe the bug

Throwing a non-Error value from route’s beforeLoad during SSR does not render the configured error component. Instead, it returns an empty 200 HTML response.

Complete minimal reproducer

https://github.com/alex35mil/tanstack-beforeLoad-throw

Steps to Reproduce the Bug

  1. Start the server
  2. Go to the main page
  3. Should see 200 with empty body

Expected behavior

Error page should be rendered.

Screenshots or Videos

No response

Platform

  • Router / Start Version:
    "@tanstack/react-router": "1.168.10",
    "@tanstack/react-start": "1.167.16",
  • OS: macOS
  • Browser: Arc
  • Browser Version: 1.146.0
  • Bundler: vite
  • Bundler Version:
    "vite": "8.0.8",

Additional context

I work with ReScript and for expected errors, I throw error variant, so I could match against it in the error component. Variant is represented as JS string at runtime, and throwing string results in the described issue.

Simplified demonstration:

// Error.res
type t = [>
  | #Maintenance
  | #Internal
]
// Route.res
let beforeLoad = async _ => {
  // At runtime #Maintenance is a JS string
  #Maintenance->throw
}
// ErrorComponent.res
@react.component
let make = (~error: Error.t) => {
  switch error {
  | #Maintenance => <p> {"Maintenance"->React.string} </p>
  | #Internal 
  | _ => <p> {"Internal error"->React.string} </p>
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions