Skip to content

fix(start-server-core): return 406 instead of 500 for non-HTML Accept headers - #7925

Open
okxint wants to merge 2 commits into
TanStack:mainfrom
okxint:fix/start-406-not-acceptable
Open

fix(start-server-core): return 406 instead of 500 for non-HTML Accept headers#7925
okxint wants to merge 2 commits into
TanStack:mainfrom
okxint:fix/start-406-not-acceptable

Conversation

@okxint

@okxint okxint commented Jul 30, 2026

Copy link
Copy Markdown

Problem

When a request's Accept header doesn't include HTML or */*, createStartHandler correctly rejects it but returns HTTP 500 Internal Server Error. This is wrong — the problem is with the request, not the server.

Fix

Return HTTP 406 Not Acceptable, which is what the HTTP spec defines for failed content negotiation.

- { status: 500 },
+ { status: 406 },

Fixes #7913

Summary by CodeRabbit

  • Bug Fixes
    • Fixed code-split route loading when generated paths contain single quotes.
    • Requests that do not accept HTML now receive the appropriate 406 Not Acceptable response instead of a server error.

okxint added 2 commits July 24, 2026 11:38
… headers

When a request's Accept header doesn't include HTML or */*, the handler
correctly rejects it but was returning HTTP 500 (Server Error). Failed
content negotiation is a client-side condition; HTTP 406 Not Acceptable
is the correct status code for this case.

Fixes TanStack#7913
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 752b3803-61a5-4690-ba28-24ab011a9e7b

📥 Commits

Reviewing files that changed from the base of the PR and between a3ee355 and 7a75acf.

📒 Files selected for processing (2)
  • packages/router-plugin/src/core/code-splitter/compilers.ts
  • packages/start-server-core/src/createStartHandler.ts

📝 Walkthrough

Walkthrough

The change escapes single quotes in generated dynamic imports for two code-splitting strategies and changes unsupported HTML request responses from HTTP 500 to HTTP 406.

Changes

Code-split import generation

Layer / File(s) Summary
Escape dynamic import URLs
packages/router-plugin/src/core/code-splitter/compilers.ts
The lazyRouteComponent and lazyFn importer generators escape single quotes in splitUrl before creating dynamic import() calls.

HTTP content negotiation

Layer / File(s) Summary
Return 406 for unsupported Accept headers
packages/start-server-core/src/createStartHandler.ts
Requests whose Accept header excludes HTML and wildcards now receive a 406 JSON error response instead of 500.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: schiller-manuel, sheraff

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The router-plugin import-escaping change is unrelated to issue #7913 and appears outside the requested scope. Remove or justify the compilers.ts change, or split it into a separate PR so this patch stays focused on the 406 fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: returning 406 instead of 500 for non-HTML Accept headers.
Linked Issues check ✅ Passed The start-server-core change matches issue #7913 by returning 406 for rejected non-HTML Accept headers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

) {
programPath.unshiftContainer('body', [
template.statement(
`const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should not be changed in this PR

return normalizeSsrResponse(
Response.json(
{ error: 'Only HTML requests are supported here' },
{ status: 500 },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add an e2e test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start: page route returns 500 when Accept excludes HTML

2 participants