trimPathRegex is quadratic on a long run of slashes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 77/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js, typescript
- Domain
- frontend, performance
Research direction
Start by locating trimPathRegex and normalizePath in the router source, then reproduce the reported timing in Node with the supplied long-slash input. Change the trimming approach so runtime grows linearly, and confirm that trimming preserves the expected path behavior while the 100,000-slash case completes quickly.
Written by the indexing model from the issue text.
Description
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
- 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");
- It prints about 2650 ms.
- In an app using the router, navigate client-side (link or
history.pushState) to/streamsfollowed by 100,000 slashes andx: 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.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 193
- Avg merge
- 8h 48m
- Merged PRs (30d)
- 21
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs/solid-router
-
[2.0.1] Internal links do a full page load on a custom scheme (Electron app://)Possibly taken @saudademjj claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 20/100
solidjs/solid-router#755 · 1 comment ·
Maintainers usually reply within 1 day
-
[2.0.1] diagnostics: a request for // crashes the dev server (Invalid URL in describeInitial)Possibly taken @bryanlundberg claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
solidjs/solid-router#752 ·
Maintainers usually reply within 1 day
-
liveQuery SSR: the producer of a `live()` server function is never finalized after the response ends (the `return()` queues behind a read-ahead `next()`)Possibly taken @clean99 claimed this 2 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
solidjs/solid-router#751 ·
Maintainers usually reply within 1 day
-
[2.0.1] hashHistory: link claims and useLinkState ignore the hash, so aria-current/data-active are wrong on every linkPossibly taken @clean99 claimed this 9 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 72/100
solidjs/solid-router#746 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
solidjs/solid-router#736 · 1 comment ·
Maintainers usually reply within 1 day
All issues in solidjs/solid-router
Similar issues
-
area:api bug good first issue priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Doezer/Questarr#1486 · 1 comment ·
Maintainers usually reply within 1 day
-
area:import difficulty:good-first good first issue help wanted priority:P1 roadmap size:S type:test
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Sergey-Bar/Penny#245 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mihazs/lazysh#3377 · 2 comments ·
Maintainers usually reply within 1 day
-
Approve the Cloudflare agent plugin for harness sessionsPossibly taken @joshtsch claimed this today. Openenhancement ready-for-agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day