Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Wrong id is used when trying to scroll to anchor if id contains %20 #10641

Closed
istarkov opened this issue Jun 26, 2023 · 3 comments · Fixed by #10682
Closed

[Bug]: Wrong id is used when trying to scroll to anchor if id contains %20 #10641

istarkov opened this issue Jun 26, 2023 · 3 comments · Fixed by #10682
Labels

Comments

@istarkov
Copy link
Contributor

What version of React Router are you using?

6.10.0

Steps to Reproduce

Example app.
https://codesandbox.io/s/crimson-cdn-n3gpdq?file=/src/App.js

Create broserRouter and following route

import { Link } from "react-router-dom";
import { ScrollRestoration } from "react-router-dom";

export default function App() {
  return (
    <>
      <ScrollRestoration />
      <div className="App">
        <Link to="/#hello%2520%20world">
          MUST WORK AND SCROLL TO BOTTOM, BUT WORKS ONLY WITH JS DISABLED OR ON
          REFRESH. CLICK ME AND REFRESH.
        </Link>
        <div style={{ height: "3000px" }}></div>
        <Link id={"hello%20 world"}>Link</Link>
      </div>
    </>
  );
}

With disabled js first links work, and scrolls to bottom. With refresh too.
With enabled js not.

The issue is here

let el = document.getElementById(location.hash.slice(1));

Must be

decodeURIComponent(location.hash.slice(1))

Expected Behavior

Should work even with js enabled

Actual Behavior

Work only if js disabled.

@brophdawg11
Copy link
Contributor

This is fixed by #10682 and should be available in the next release.

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 6.14.2-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 6.14.2 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 removed the awaiting release This issue have been fixed and will be released soon label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants