Start SSR enters infinite 307 loop when custom search serializer emits comma-delimited arrays

未关闭
#8,777 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@pavstev 已经在做这个了。

开始于 2026年11月3日。

  • #8782 来自 @mixelburg —— 已关闭,未合并
  • #8848 来自 @pavstev —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
57/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript
领域
backend

调研方向

Start in the loadServerRoute and getNormalizedURL code paths described in the issue, then compare how each constructs and compares the request URL for comma and %2C query values. Use the linked StackBlitz reproduction or the provided curl command to observe the repeated 307 redirects. Done means the request converges without redirecting forever, including when the router's rewrite option is used.

由索引模型根据 Issue 内容生成。

描述

Which project does this relate to?

Router

Describe the bug

TanStack Start SSR can enter an infinite self-redirect loop when a custom stringifySearch emits comma-delimited arrays.
For GET /test?tags=1,2, server URL normalization serializes the query as tags=1%2C2. The configured parser and route's validateSearch turn this into tags: ['1', '2'], then the configured stringifier canonicalizes it back to the literal-comma form, /test?tags=1,2.
loadServerRoute compares the normalized next.publicHref with the canonical publicHref, sees %2C and , as different, and redirects to canonical publicHref with 307 Location: /test?tags=1,2. The redirected request repeats the same process indefinitely. Browser show ERR_TOO_MANY_REDIRECTS.

Complete minimal reproducer

https://stackblitz.com/edit/github-tnsncrms-xorkcit6?file=src%2Frouter.tsx

Steps to Reproduce the Bug
  1. Visit reproduction link https://stackblitz.com/edit/github-tnsncrms-xorkcit6?file=src%2Frouter.tsx
  2. Click the link in the landing page to navigate to /test?tags=1,2
  3. Observe "redirected you too many times" error in browser and document response:
   HTTP/1.1 307
   Location: /test?tags=1,2

Reproducible with curl:
4. Open new terminal in sandbox
5. Run curl -sL --max-redirs 3 'http://localhost:3000/test?tags=1,2'
6. Observe curl exits with: curl: (47) Maximum (3) redirects followed

Expected behavior

The request should converge—ideally return 200 for /test?tags=1,2; at minimum it must not redirect to the identical public URL forever.
Equivalent encodings of a query value, such as , and %2C, should not cause a canonicalization redirect

Screenshots or Videos

No response

Platform
  • @tanstack/react-router: 1.170.45
  • @tanstack/react-start: 1.169.3
  • React: 19.3.1
  • Node: 22.16.0
  • OS: macOS 15.6 (Darwin 24.6.0)
  • Bundler: Vite 8.3.4
  • Browser: any; reproducible with curl
Additional context

getNormalizedURL rebuilds the query with URLSearchParams(...).toString(), which encodes , as %2C, before loadServerRoute compares next.publicHref with the serializer's canonical output.

Workaround:

Split parsed params by comma in stringifySearch: Request search string is ?tags=1,2, after server normalization becomes ?tags=1%2C2, in stringifySearch is is parsed into { 'tags' : '1,2' }, after splitting { 'tags' : ['1', '2'] }
This is not a proper solution, but a way to mitigate the redirect loop while keeping the functionality as close as possible. It splits already escaped characters ?tag=1%2C2,3&input=foo%2Cbar -> { tags: ['1', '2', '3'], input: ['foo', 'bar'] } which is undesired.
This workaround doesn't work when rewrite option is provided in router. In that case stringifySearch doesn't affect the publicHref which is built from the history's href (see code) and SSR enters the infinite redirect loop.

主要语言
TypeScript
星标
15.3k
派生
1.9k
平均合并
1 天 5 小时
30 天内合并 PR
46

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/router 的其他 Issue

查看 TanStack/router 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。