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

Link elements do not follow anchors when these are accentuated #23690

Closed
kuworking opened this issue May 1, 2020 · 6 comments
Closed

Link elements do not follow anchors when these are accentuated #23690

kuworking opened this issue May 1, 2020 · 6 comments
Assignees
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@kuworking
Copy link

If in a mdx file I have something like

# This is my áccentuated title

and later I grab the tableOfContents through graphQL, I can see that tableOfContents.items[].node.url and the id property passed to the h1 node has the accent

id="This-is-my-áccentuated-title"

The link you can recreate with "to="mywebpage#This-is-my-áccentuated-title" doesn't go to the anchor because of the accent (at least what I'm seeing in Chrome)

One easy workaround would be to just remove accents when creating the id names, but AFAIK it cannot be done by the user (?)

@kuworking kuworking added the type: bug An issue or pull request relating to a bug in Gatsby label May 1, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 1, 2020
@TylerBarnes TylerBarnes added topic: MDX and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels May 1, 2020
@kuworking
Copy link
Author

Closed in favour of remarkjs/remark-slug#12

@kuworking kuworking changed the title TableOfContents in gatsby-mdx creates anchors with accents, which do not work Link elements do not follow anchors when these are accentuated May 2, 2020
@kuworking
Copy link
Author

Reopened again, from remarkjs/remark-slug#12

Here there is a minimal repo

https://github.com/kuworking/link_anchors_accents

The <Link> element doesn't seem to work with an accentuated anchor (or at least that's what I see)

    <h1 id="test">no accent</h1>
    <h1 id="tést">yes accent</h1>
    <p>
      <Link to="/page-2#test">Go to page 2, no accent, works</Link>
    </p>
    <p>
      <Link to="/page-2#tést">Go to page 2, yes accent, doesn't follow the anchor</Link>
    </p>

@kuworking kuworking reopened this May 2, 2020
@blainekasten
Copy link
Contributor

@kuworking Thanks for reporting. I spent some time yesterday looking into this and have absolutely reproduced it.

To document my findings here is a few things:

In a native HTML page

  • Clicking an accented id scrolled to the matching id
  • Reloading restored previous pages scroll position (meaning it did not care about the #id match)

In Gatsby

  • Clicking an accented id within a page scrolls to it properly
  • Navigating to a new page with the accented id does not scroll to it, we jump to the top of the page

I haven't identified yet if this is a Gatsby problem, or with @reach/router, but there is definitely an inconsistency here and we'd like to align with the platform.

@blainekasten blainekasten added the status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. label May 8, 2020
@blainekasten
Copy link
Contributor

I figured out what the problem is, the browser encodes the hash, so when we try to compare the hash to the id in the page they do not match. Browsers must internally decode that hash, but we currently don't.

I know how to fix this now, just need to figure out if we should fix this in gatsby, or if it should be fixed in @reach/router. But making progress!

@kuworking
Copy link
Author

What can I say, apart from thanks a lot 👏👏👏👏👏

@blainekasten
Copy link
Contributor

Fixed in latest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

5 participants