47ng / 47ng/nuqs

[bug] Tanstack Router: `parseAsTimestamp` parses defalt value as `1970-01-01T00:00:02.025Z` when reloaded or opened with searchParams

未關閉
#1,177 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
adapters/tanstack-router bug
主要語言
TypeScript
星號
10.8k
分支
294
平均合併
1 天 16 小時
30 天內合併 PR
21

描述

## Context

What's your version of `nuqs`?

```
"nuqs": "^2.7.2"
```

What framework are you using?

- ✅ Other (Tanstack Router)

Which version of your framework are you using?

```
"@tanstack/react-router": "^1.132.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
```

## Description

**BUG**: When query states is changed to `?from=1760207400000&to=1760812199999` and I reload the page or open the same URL in different tab, it fails to parse the value and changes the url to `?from="1970-01-01T00%3A00%3A02.025Z"&to="1970-01-01T00%3A00%3A02.025Z"`

**EXPECTED**: URL to be same and parse the timestamps correctly.

However this only happens when I add `validateSearch` in route definition
```ts
export const Route = createFileRoute("/")({
component: App,
// THE BUG ONLY HAPPENS WHEN USING validateSearch IF I REMOVE `validateSearch` IT WORKS AS EXPECTED
validateSearch: createStandardSchemaV1(searchParams, {
partialOutput: true,
}),
});
```

## Reproduction

Deployed Version: https://nuqs-repro.pages.dev/
GitHub Repo: https://github.com/mdhruvil/nuqs-repro

- Visit "/"
- Current Week is selected by default, see URL and values displayed on page
- Click on "Set to Previous Week"
- It changes url to select previous week (works as expected)
- Refresh the page or copy url and open in new tab
- It changes url to `?from="1970-01-01T00%3A00%3A02.025Z"&to="1970-01-01T00%3A00%3A02.025Z"` instead of parsing the actual timestamp values

貢獻指南

開啟貢獻指南

研究方向

在 Tanstack Router 的路由定義中使用 `validateSearch` 和 `createStandardSchemaV1` 時會發生此 bug。檢查 nuqs 原始碼中的 `parseAsTimestamp` parser,可能位於 parsers 模組中。重現 repository 顯示了這個問題:頁面重新載入時,timestamp 被錯誤地解析為預設日期。檢查 parser 在 hydration 期間如何處理數字 timestamp 與字串序列化之間的差異。執行提供的重現,以查看 URL 的變更。

由索引模型根據 Issue 內容生成。

評估

領域
frontend
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。