fix: set statusCode to 500 if error occurs#5541
Conversation
WalkthroughThe PR fixes SSR status code handling by computing appropriate HTTP status codes (404 for not-found, 500 for errors) when loaders throw exceptions. It exports the Changes
Sequence DiagramsequenceDiagram
participant Client
participant Router as Router (SSR)
participant Loader
participant StateManager as Router State
Client->>Router: Navigate / Initial Load
Router->>Loader: Execute loader/beforeLoad
alt Loader throws Error
Loader-->>Router: Error
Router->>Router: Compute newStatusCode = 500
Router->>StateManager: Update statusCode to 500
Router-->>Client: Response (500)
else Loader throws notFound
Loader-->>Router: notFound()
Router->>Router: Compute newStatusCode = 404
Router->>StateManager: Update statusCode to 404
Router-->>Client: Response (404)
else Loader succeeds
Loader-->>Router: Success
Router->>Router: No status code change
Router-->>Client: Response (200)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes The changes involve conditional logic modifications in the router's load handling and new test coverage across multiple scenarios. The logic shift from unconditional to conditional status code assignment requires careful verification of edge cases, but the overall scope remains focused on status code handling. Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (3)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/router-core/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/{react-router,solid-router}/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-10-08T08:11:47.088ZApplied to files:
🧬 Code graph analysis (1)packages/react-router/tests/router.test.tsx (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (4)
Comment |
|
View your CI Pipeline Execution ↗ for commit 3d15cc7
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/nitro-v2-vite-plugin
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-static-server-functions
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
fixes #5535
Summary by CodeRabbit
New Features
notFoundis now available as a public API export from router core.Bug Fixes
Tests