47ng / nuqs

Type-safe search params state manager for React frameworks - Like useState, but stored in the URL query string.
https://nuqs.47ng.com
MIT License
5.02k stars 109 forks source link

global variable `next` does not exist in storybook #464

Closed bestLessons closed 10 months ago

bestLessons commented 10 months ago

Context

What's your version of nuqs?

"nuqs": "^1.15.3",

next@13.5.6

Are you using:

Description

While running storybook useQueryState has a line window.next.version !== '14.0.3' -> which assumes that there is a global next variable inside storybook. But it doesn't exist.

I think it'd be better to add something like window.next?.version just to make it work by default

Reproduction

Steps to reproduce the behavior:

  1. Setup any storybook with a component that uses import { useQueryState } from 'nuqs'; and it will fail to render
Meemaw commented 10 months ago

Facing this as well -> true in test environments.

I recommend you update your types to make next optional on the window to avoid such errors in future: https://github.com/47ng/nuqs/blob/f9c89d34101945a9fc7f34acbe121ab756545549/packages/nuqs/src/update-queue.ts#L122

franky47 commented 10 months ago

Thanks, I had fixed it in a previous place but this one slipped through. Types updated, marked as optional, and release baking in the oven.

github-actions[bot] commented 10 months ago

:tada: This issue has been resolved in version 1.15.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket: