Next.js links don't work inside toasts
See original GitHub issue🐛 Bug report
In my project I’ve created a Link
component that wraps Chakra’s link component with Next.js’ as recommended. This component works fine when I use it in regular places inside my app, but breaks when used inside toasts. On click I get thrown the error “TypeError: can’t access property “push”, router is null”. I think it might have to do with the fact that toasts are placed inside a portal?
💥 Steps to reproduce
- Go to the sandbox provided below
- Explore implementation of
Link
component - Test the instances of
Link
within pages and confirm that they work - Trigger the toast and test that instance of
Link
- Observe error thrown by Next.js
💻 Link to reproduction
CodeSandbox reproduction: https://codesandbox.io/s/purple-wood-q6ug6
🧐 Expected behavior
I expect this link component pattern to work inside toasts too.
🌍 System information
Software | Version(s) |
---|---|
Chakra UI | 1.4.1 |
Browser | N/A |
Operating System | N/A |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:14 (4 by maintainers)
Top Results From Across the Web
toast doesn't show correct style - nextjs - Stack Overflow
Here goes my first answer on SO! Ran into a similar situation while trying out React-Toastify as well. Basically you need to state...
Read more >ToasterContainer breaks Next.js SSR #3430 - GitHub
ToasterContainer breaks server side rendering with Next.js, causing it to show a white page that will only render with JavaScript enabled.
Read more >Advanced Features: Error Handling - Next.js
Error Handling. This documentation explains how you can handle development, server-side, and client-side errors. Handling Errors in Development.
Read more >Next.js - Alert (Toaster) Notifications | Jason Watmore's Blog
This tutorial shows how to implement a simple reusable alert component in a Next.js front-end app using React and RxJS.
Read more >Handling Bootstrap integration with Next.js - LogRocket Blog
js bootstrap 'document is not defined' error. This article will explain how to fix this error as well as how to effectively use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a todo comment in
toast.class
I think once it’s todo-ed, it might solve this issue@kfranqueiro You can simply avoid this issue using
toastOptions.portalProps.containerRef
. I think this way is not as complicated as being called “workaround” and this issue can be closed.sandbox: https://codesandbox.io/s/next-js-links-dont-work-inside-toasts-forked-k0m1o2