-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Storybook Issues with v2 #757
Comments
It seems to me that nuqs expects the app router to be used, but it's actually the page router. If i add
from https://storybook.js.org/docs/get-started/frameworks/nextjs#storybooknextjsnavigationmock, to the page and actually use the app router, the adapter If i remove the |
Honestly, support for Next.js APIs in Storybook looks like monkeypatching and hacks to mock the right behaviours, if your components work in Storybook with the React adapter, I'd say feel free to use that one. |
I understand that, and I appreciate your work, but is there a downside to using the React adapter over the isomorphic next adapter? The storybook docs state that Since pages Adapter is using |
I gave your reproduction a try locally, and the app router adapter (combined with the When using the pages router adapter (with or without the When using the React adapter, the local state updated correctly. In none of these cases the local state reflects in the URL. Edit: I just understood that Storybook runs pages in an iframe, so the URL being updated is that of the iframe, and not the top-level host window. |
Since Storybook has updated to Next 15 storybookjs/storybook#29587 in 8.4.3, I have updated the codesandbox to the new version and also tried Next15, still the same problems occur. Maybe we should open an issue on their site? |
I'm wondering if a dedicated Storybook adapter might be beneficial. It would signal a bit better what to do, rather than trying to retrofit the "production" ones, and it could be made to escape the iframe to update the host's URL, as inevitably the issue will come up that "the URL doesn't update in Storybook". |
Personally, I would not benefit from a storybook adapter, because useQueryState is firmly integrated into components such as Pagination and I would like to integrate this adapter into my provider, which already provides themes and other things. I also don't find it confusing for developers that the URL doesn't adapt with Storybook, because I think it's well communicated that the view is in an iFrame. Only for end users of Storybook this could be misleading, but I think the likelihood of an end user testing this is very low. |
In my environment, I was able to display Storybook using Usage ExamplenuqsDecorator.tsx import { Preview } from '@storybook/react';
import { NuqsTestingAdapter } from 'nuqs/adapters/testing';
export const nuqsDecorator: Exclude<Exclude<Preview['decorators'], undefined>, any[]> = (
Story,
{ parameters }
) => {
const { nuqs } = parameters;
return (
<NuqsTestingAdapter searchParams={nuqs?.searchParams}>
<Story />
</NuqsTestingAdapter>
);
}; preview.ts import type { Preview } from '@storybook/react';
import { nuqsDecorator } from './nuqsDecorator';
const preview: Preview = {
decorators: [nuqsDecorator],
}
export default preview; example.stories.tsx /* others...*/
export const All: Story = {
args: {},
parameters: {
nuqs: {
searchParams: {
filter: 'public',
},
},
},
}; There is a possibility that some problems may occur, but it seems to be sufficient for just testing the display. |
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
If i try to use nuqs in Storybook i get following errors:
import { NuqsAdapter } from "nuqs/adapters/next";
import { NuqsAdapter } from "nuqs/adapters/next/pages";
I have not specified app router. If i use
import { NuqsAdapter } from "nuqs/adapters/react";
everything works fine.I use the adapter inside a decorator in the preview.js file.
My main.js includes
Reproduction
Codesandbox: https://codesandbox.io/p/github/BhagirathiRohidas/storybook-nextjs/csb-w7fl7v/draft/quirky-andras
npm run storybook
The text was updated successfully, but these errors were encountered: