Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')

Đang mở Phù hợp với người mới
#8,928 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@hassanabrar202 đang làm issue này rồi.

Từ ngày 14/11/2026.

  • #8931 của @hassanabrar202 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Lỗi nằm ở commitLocation, nơi __tempLocation được tạo từ vị trí logic mà không có # ở đầu, và ở parseLocation, nơi nó được đọc lại bằng hash.slice(1). Hãy bắt đầu bằng cách tái hiện lỗi với script độc lập trong issue (lịch sử trong bộ nhớ, điều hướng được che với hash) và xác nhận rằng hash bị ngắn đi một ký tự sau mỗi lần điều hướng. Công việc hoàn thành khi hash logic vẫn là "anchor" qua nhiều lần điều hướng, kèm một bài kiểm thử hồi quy bao phủ điều hướng được che có mang hash.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Which project does this relate to? Router

Describe the bug
A navigation with mask stores the real (logical) location in history.state.__tempLocation. commitLocation spreads the built location into it, whose hash has no leading # (buildLocation returns hash: hash ?? ""). parseLocation then reads __tempLocation back with decodePath(hash.slice(1)), so the logical hash loses its first character. An app that carries the current hash forward loses one more character per navigation: anchor -> nchor -> chor -> hor.

Your Example Website or App
Standalone script below (Node 22, @tanstack/react-router 1.169.2; same code in router-core 1.171.39).

Steps to Reproduce the Bug or Issue

import { createRouter, createRootRoute, createRoute, createMemoryHistory } from "@tanstack/react-router"
const root = createRootRoute()
const home = createRoute({ getParentRoute: () => root, path: "/" })
const chat = createRoute({ getParentRoute: () => root, path: "/chats/$chatId" })
const router = createRouter({ routeTree: root.addChildren([home, chat]), history: createMemoryHistory({ initialEntries: ["/"] }) })
await router.load()
let hash = "anchor"
for (let i = 1; i <= 3; i++) {
  void router.navigate({ to: "/", hash, mask: { to: "/chats/$chatId", params: { chatId: "c1" }, hash } })
  await new Promise((r) => setTimeout(r, 50))
  hash = router.parseLocation(router.history.location).hash
  console.log(i, JSON.stringify(hash))
}
// 1 "nchor"   2 "chor"   3 "hor"

Expected behavior
The logical location parsed back from a masked entry keeps its hash: "anchor" every time.

Suggested fix
In commitLocation, store the hash with its # in __tempLocation, as parse expects (it already does for history.location):

 __tempLocation: {
   ...nextHistory,
   search: nextHistory.searchStr,
+  hash: nextHistory.hash ? `#${nextHistory.hash}` : "",
Ngôn ngữ chính
TypeScript
Star
15.3k
Fork
1.9k
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
46

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/router

Tất cả issue của TanStack/router

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.