trimPathRegex is quadratic on a long run of slashes

Đang mở Phù hợp với người mới
#757 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

Chưa có ai nhận issue này.

Đá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
77/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
frontend, performance

Hướng nghiên cứu

Trước tiên, hãy tìm trimPathRegex và normalizePath trong mã nguồn của router, sau đó tái hiện thời gian thực thi được báo cáo trong Node bằng đầu vào có nhiều dấu gạch chéo đã cung cấp. Thay đổi cách cắt để thời gian thực thi tăng tuyến tính, đồng thời xác nhận rằng việc cắt vẫn giữ nguyên hành vi đường dẫn như mong đợi và trường hợp có 100.000 dấu gạch chéo hoàn tất nhanh chóng.

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

Mô tả

Describe the bug

In @solidjs/router 2.0.1, trimPathRegex = /^\/+|(\/)\/+$/g (used by normalizePath) backtracks quadratically when a path has a long run of slashes followed by another character. The regex engine rescans the run from every start position, then fails at $. A client-side navigation to such a path blocks the main thread.

Your Example Website or App

No app needed; the regex alone reproduces it in Node (see steps).

Steps to Reproduce the Bug or Issue
  1. Run in Node:
const s = "/streams" + "/".repeat(100000) + "x";
const t = performance.now();
s.replace(/^\/+|(\/)\/+$/g, "$1");
console.log(Math.round(performance.now() - t), "ms");
  1. It prints about 2650 ms.
  2. In an app using the router, navigate client-side (link or history.pushState) to /streams followed by 100,000 slashes and x: the page freezes for about 0.9 s in Chromium and Firefox and 2.9 s in WebKit. With 1,000,000 slashes it does not return within 30 s.
Expected behavior

Trimming slashes takes linear time; a long path does not freeze the page. A loop over charCodeAt from the end (or a regex without the backtracking \/+$ alternative) does it in well under 1 ms for 100,000 slashes.

Screenshots or Videos

No response

Platform
  • @solidjs/router 2.0.1, solid-js 2.0.4
  • Node 26.13.1
  • Browsers: Chromium, Firefox and WebKit from Playwright 1.65.1
  • OS: Linux
Additional context

Servers usually reject such long URLs on a direct load (e.g. HTTP 431 near 20,000 characters), so the reach is client-side links and history.pushState.

Ngôn ngữ chính
TypeScript
Star
1.3k
Fork
193
Merge trung bình
8 giờ 48 phút
Pull request đã merge (30 ngày)
21

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

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 solidjs/solid-router

Tất cả issue của solidjs/solid-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.