Skip to content
Source
Sign inSign up
TanStack/router

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

Openokxint(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/7925/headopened

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.
    1. 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 a3ee355b5934215ab5716019fbb4b9f55acdd64f and 7a75acfe9ea0e8c6387928604758f4cbfd171531.

      📒 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 nameStatusExplanationResolution
      Out of Scope Changes check⚠️ WarningThe 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 nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title clearly matches the main fix: returning 406 instead of 500 for non-HTML Accept headers.
      Linked Issues check✅ PassedThe start-server-core change matches issue #7913 by returning 406 for rejected non-HTML Accept headers.
      Docstring Coverage✅ PassedNo 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.
    2. packages/router-plugin/src/core/code-splitter/compilers.ts line 626
      @@ -623,4 +623,3 @@
      623623 ) {
      624624 programPath.unshiftContainer('body', [
      625625 template.statement(
      626- `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,

      this file should not be changed in this PR

    3. packages/start-server-core/src/createStartHandler.ts line 560
      @@ -557,4 +557,3 @@
      557557 return normalizeSsrResponse(
      558558 Response.json(
      559559 { error: 'Only HTML requests are supported here' },
      560- { status: 500 },
    4. @okxint are you intending to fix this up to address review comments? if not, I can do so in a new pr

Sign in to join this conversation.