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

Vitest storybook tests erroring since 1.13.2 #454

Closed
sunwrobert opened this issue Jan 15, 2024 · 6 comments · Fixed by #456
Closed

Vitest storybook tests erroring since 1.13.2 #454

sunwrobert opened this issue Jan 15, 2024 · 6 comments · Fixed by #456
Labels
bug Something isn't working released

Comments

@sunwrobert
Copy link

sunwrobert commented Jan 15, 2024

Context

What's your version of nuqs?
1.13.2

-> Paste result from `cat package.json | grep -e nuqs -e next-usequerystate` here

Next.js information (obtained by running next info):

-> Paste result from `next info` here

Are you using:

  • ✅ The app router
  • ❌ The pages router
  • ❌ The basePath option in your Next.js config
  • ❌ The experimental windowHistorySupport flag in your Next.js config

Description

Ever since I upgraded to nuqs 1.13.2, I get the following error in my vitest tests that use nuqs through Storybook.
1.13.1 works perfectly fine

Error: [next-usequerystate] URL update rate-limited by the browser. Consider increasing `throttleMs` for keys %s. %O
web:test:unit:   See https://err.47ng.com/NUQS-429 market TypeError: Cannot read properties of undefined (reading 'router')

Reproduction

  1. Clone this repo: https://github.com/sunwrobert/nuqs-issue-demo
  2. npm install -> npm run test

The relevant test is nuqs-demo.test.tsx

Notice that the error above throws.

If I downgrade to 1.13.1, it doesn't throw.

@sunwrobert sunwrobert added the bug Something isn't working label Jan 15, 2024
@franky47
Copy link
Member

Thanks for the report. The only change between 1.13.1 and 1.13.2 concerns the pages router, but you mention using the app router.

Could you fill up the context section of the issue template please, so I can try and reproduce? Including your storybook/vitest setup would also be very useful, thanks.

This "router is undefined" error (ignore the rate-limit message, that is a try-catch being placed too wide) could indicate that Storybook doesn't run in a Next.js context, which is needed for nuqs to function.

@sunwrobert
Copy link
Author

Sure, will get a repro

@sunwrobert
Copy link
Author

@franky47 Added repro steps. I am using a custom mock router to get this to work, so the thing is that just that the error above throws in tests. I could try ignoring the error, but issue still stands that it'll cause my tests to fail in 1.13.2 but not 1.13.1

Copy link

🎉 This issue has been resolved in version 1.15.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47
Copy link
Member

franky47 commented Jan 15, 2024

Thanks to your reproduction, I found the issue: nuqs tries to detect whether it's running in the pages router vs app router with a check that was introduced in 1.13.2, but this check always assumed we were running in Next.js and could access its internals, which are not set in test/mock environments.

Let me know if 1.15.2 works for you.

@sunwrobert
Copy link
Author

Yup, it works. Thanks @franky47

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

Successfully merging a pull request may close this issue.

2 participants