router icon indicating copy to clipboard operation
router copied to clipboard

Automatic URL unescaping on first load causes match failure

Open djrenren opened this issue 1 year ago • 0 comments

Describe the bug

On initial page load, tanstack router will unescape the url, which causes problems when reserved characters (such as #) were escaped and are no longer.

For example /foo%23/test will match /$id/test, but on first load it becomes /foo#/test which matches /$id but not /$id/test.

Your Example Website or App

https://stackblitz.com/edit/github-jaqhfz?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

This example won't work in the embedded browser on stackblitz so be sure to use the popout button near the top right.

  1. Go to: /
  2. Click on the link te#st/test which will take you to /te%23st/test (displaying "Hello /$id/test")
  3. Refresh your browser tab
  4. Notice that your URL is now /te#st/test and the page displays ("Hello /$id")

Expected behavior

I would expect that refreshing would keep us at /te%23st/test and display "Hello /$id/test" because we would still be matching the /$id/test route.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 127.0.6533.120

Additional context

We found this bug by updating from 1.17.4 to 1.48.3. Obviously that's a huge bisect, but clearly this changed somewhere in there.

djrenren avatar Aug 20 '24 17:08 djrenren