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

next/link links with hash not working #65

Closed
iAdramelk opened this issue Dec 2, 2020 · 12 comments
Closed

next/link links with hash not working #65

iAdramelk opened this issue Dec 2, 2020 · 12 comments
Labels
bug Something isn't working

Comments

@iAdramelk
Copy link

I'm trying to render markdown docs using mdx and next-mdx-remote. I replaced standard <a> tags in docs with next/link for smoother navigation. It works, but if the link has fragment link, e. g. docs/page#about, then navigation to anchor on page load didn't work. If I just render renderOutput to dangerouslySetInnerHTML={{ __html: mdx.renderedOutput }}, then everything works correctly.

My guess is that bug happens because navigation to hash hapens at the time then hydrate is replacing the page content and there are no actual anchor on the page.

@iAdramelk
Copy link
Author

P. S. Wrapping setResult call in additional requestIdleCallback fixed problem for me, but I'm not sure that it will work in 100% of cases:

window.requestIdleCallback(() => setResult(wrappedWithMdxProvider))

@helloworld
Copy link

@iAdramelk where did you include that snippet?

@jescalan jescalan changed the title Hash navigation not working next/link links with hash not working Dec 5, 2020
@iAdramelk
Copy link
Author

@helloworld sorry for the late answer. At the line 60 of hydrate.js, I'm wrapping setResult(wrappedWithMdxProvider) in it.

@brandonpittman
Copy link

Same issue here.

@jescalan jescalan added the bug Something isn't working label Dec 22, 2020
@maximousblk
Copy link

maximousblk commented Dec 23, 2020

I'm having the same problem.

I have pages/[slug].tsx which fetches mdx and renders the page. links in which [slug] is defined by me work correctly, example: on example.com/page1 if there is a link to [Section on Page 2](/page2#section-id) it works fine. but if the link only has the "hash link" like [Section on This Page](#section-id) the I get the following error:

Uncaught (in promise) Error: The provided `href` (/[slug]#section-id) value is missing query values (slug) to be interpolated properly. Read more: https://err.sh/vercel/next.js/href-interpolation-failed
    at Router._callee$ (router.ts?35b8:810)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)
    at Generator.eval [as next] (runtime.js?96cf:118)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)

@josephgeis
Copy link

I'm trying to render markdown docs using mdx and next-mdx-remote. I replaced standard <a> tags in docs with next/link for smoother navigation.

Just curious: did you do this by setting the renderToString parameter on components or hydrate?

@josephgeis
Copy link

I'm trying to render markdown docs using mdx and next-mdx-remote. I replaced standard <a> tags in docs with next/link for smoother navigation.

Just curious: did you do this by setting the renderToString parameter on components or hydrate?

nevermind. turns out it's both. I digress. :)

@jescalan
Copy link
Contributor

jescalan commented May 24, 2021

This should be resolved as of v3. Has anyone had a chance to check and confirm?

@brandonpittman
Copy link

This should be resolved as of v3. Has anyone had a chance to check and confirm?

Didn't see it mentioned in the release notes but I'll try it out! Thanks.

@jescalan
Copy link
Contributor

@brandonpittman just wanted to check if you could confirm here?

@brandonpittman
Copy link

@jescalan I can confirm this works! Also, first time using the new API and it's lovely. ❤️

@jescalan
Copy link
Contributor

wonderful! thanks so much. will close this one out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants