Issue with next/link in Next 12.2.0
See original GitHub issueHello!
I’ve noticed that after upgrade to newest version of Next 12.2.0 (released 3 days ago) there is an issue with tests utilising Next Link.
import Link from "next/link"
...
jest.mock("next/router", () => require("next-router-mock"));
jest.mock("next/dist/client/router", () => require("next-router-mock"));
...
it("", () => {
const { getByText } = render(<div><Link href={"/foo"}>Foo</Link></div>);
const foo = getByText("Foo");
fireEvent.click(foo);
});
...
test fails with following error:
TypeError: Cannot read properties of null (reading ‘push’) 57 | fireEvent.click(foo);
After Next downgrade to previous stable version (12.1.6) everything works fine.
I am on the latest version of next-router-mock
I suspected that there may be some changes in the paths or refactor of Link component in the 12.2.0 release but didn’t found anything like that in the PR. Do you have any clue what’s going on?
Best!
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Blog - Next.js 12.2
Next.js 12.2 introduces stable Middleware and On-Demand ISR, experimental Edge SSR and API Routes, and more!
Read more >NextJS v12.2.0 causing Router null reference issues when ...
It's a problem within next-router-mock; this package has broken due to significant changes in how routing is managed in NextJS.
Read more >Report Trouble
Having trouble? Want to report a service issue? Nextlink makes it easy to raise a support ticket and get the help you need....
Read more >next - NPM Package Overview
Start using Socket to analyze next and its 19 dependencies to secure your app from supply chain ... [Doc] Update inline documentation for...
Read more >Next.js 12.2: Middleware, On-Demand ISR, Experimental ...
The problem with Next.js is the examples are soooooo base that they never give a clear use-case or problem domains all these new...
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 Free
Top 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
Thanks for the input.
Just to note, the above code resolves most of the issue but it still seems like you need both of the following:
Not having line one continues to break the tests but keeping line one passes them all.
I’ve started work on this
router-context
concept, but it’s not quite complete, and I’m not sure if it’s a long-term solution. I’ll post here as I update.I’m attempting to get in contact with Vercel directly, so that I can make some headway on a long-term solution.