-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: useParameter() returns nothing for a docs page #21798
Comments
This is an intentional breaking change. I couldn't find it in MIGRATION.md, but maybe I just missed it. I realize that doesn't solve your problem though. @tmeasday can you please weigh in on this? |
Hey @probablyup, thanks for calling this out. We've taken another look at this. The root of the problem is that with the new docs architecture, when you view docs there isn't an underlying story. In 6.5 there always was (although it was a bit of a kludge in the case of .mdx files). What that meant in 6.5 was that you could always get parameters when visiting a docs page, because there'd always be a story to read them off. In the case of .mdx files, that was just the project-level parameters (preview.js), which happened to work great for this addon. In any case, we did look at this problem when migrated some of our own addons but ultimately decided in the cases where they needed useParameter() it didn't really make sense to even do that on docs pages, and so we thought the changed behaviour was probably the best way forward. Having seen this example, it does seem like there are/will be other addons that do need the project-level parameters to be available all the time. So we'll look at making it work again on docs pages. As we are super late in the 7.0 release cycle, we need to be a bit careful about how we do this. We'll likely release the new mechanism in a 7.1 alpha in the near future, test it a little, and backport it as a bug fix in 7.0.x patch release. |
@tmeasday Cheers for calling this one out. We also noticed the missing parameters when calling |
Sibling story within the same component? @tmeasday Would know best here |
@shilman Aye. Interestingly once I browse the other sibling story it gets the parameters and the label is displayed for both. |
That's a limitation of the "on demand" nature of the store. We can't know the parameters of a story until it has been rendered |
Can’t you use what’s provided in preview.js as a global default? |
@probablyup yes, in fact as of #22071 we'd supply the component's parameters (ie. what's defined in the default export of the CSF file + the project's parameters defined in Would that be a good or a bad thing for your use case @raphaelokon? So your call of
The inconsistency doesn't sit super well with me but maybe it's better than nothing as @probablyup implies. As an aside the issue of not getting a sibling story's parameters is an issue in the v7 (on demand) store prior to 7.0, IIUC, whereas this bug specifically talks about a regression in docs pages in 7.0 (just to be clear for anyone following along). |
@probablyup I’ll check it out. It was just working before inside @tmeasday Yeah, that would totally work for me, cheers.
@tmeasday Sorry, I do not wanted to spam your |
@raphaelokon no problem at all, in fact it was helpful to think about this use case! I was just noting it because the focus here is to fix the regression in 7.0, rather than necessarily solve every problem with |
We actually have the perfect mechanism for this, tags. It's not a properly released feature yet, but we already use it for autodocs: https://storybook.js.org/docs/react/writing-docs/autodocs#setup-automated-documentation Tags are different from parameters as they are static and part of the index, so they are available immediately as soon as the menu is rendered. I think the tags are available on the |
Oh wow! @tmeasday cheers for the link! It seems like this is exactly what we want. |
@tmeasday We tested it using |
@raphaelokon would it make sense to use a field in addons: [{ name: 'your addon', options: { x: 'y' } }] I don't believe it's currently simply to get those options in the manager, but we could make it so. Or do you even use the configuration in the preview? If not it'd make sense to configure your addon in |
We do not use the add-on in the preview—solely to display/enhance the sidebar view items (story names) in Storybook with Cheers for all your help @tmeasday |
Oh, what kind of per story data would you use? |
In our case it was just an object literal containing meta information for the status → // MyComponent.stories.js
export default {
title: 'Components/MyComponent',
component: MyComponent,
parameters: {
status: {
type: 'deprecated',
since: '2.0.0',
altText: 'Additional accessible information about what the `deprecated` tag means',
// → This could contain even more related data to this specific status.
},
},
} This data cannot be expressed through |
Would this specific information be relevant to the component/story in question? |
¡Ay Caramba!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.8 containing PR #22154 that references this issue. Upgrade today to the
|
Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.7 containing PR #22120 that references this issue. Upgrade today to the
|
@tmeasday Tested this out and nothing appears to have changed for 7.0.7. Is the |
@probablyup I don't believe any changes should be necessary. I tried it out on my repro repo with 7.0.7 and the v6 store, and it appears to work as I expected. What am I missing? https://github.com/tmeasday/test-dark-mode/tree/dark-mode-7-ssv6 |
Sigh, I don’t know what the deal is then. I’ve been very on top of upgrading these libraries and honestly it’s been a misery. |
What (mis-) behaviour are you seeing? |
I upgraded to 7.0.7 and ran yarn dedupe to ensure everything is on the proper version, verified the lockfile etc. dark mode addon still is showing empty for the useParameter hook on a docs page. I’m specifically providing darkClass and lightClass which should be present and currently are not… |
Will try that and report back thanks! |
I think something's gone wrong with the deployment script @shilman as this PR is listed in the changelog both for 7.0.7 and 7.0.8: https://github.com/storybookjs/storybook/blob/main/CHANGELOG.md#707-april-24-2023 |
@tmeasday my bad. Will fix by hand and hopefully the new release workflow helps |
Hard to follow how to get this fix. I am at v7.0.11 and still seeing the issue. Do I have to wait till 7.1.0 gets released? |
@nareshbhatia the fix should be in 7.0.7. What is the behaviour you are (not) seeing? |
@tmeasday, I am using If I look at the markup in chrome debugger, the |
@nareshbhatia hmm, that sounds like a different issue than what this ticket is about [1]. I'm not sure about the behaviour you are seeing. If you can post a reproduction that shows it working 6.5 and broken in 7.0 I can take a look, but maybe in a new ticket? [1] this ticket is about (a) docs entries and (b) the manager side, ie. the sidebar etc. |
Sounds good, @tmeasday. I will create a reproduction and a new issue. |
@nareshbhatia, did you find any resolution for this? |
@shubhamdhingra007, it's still on my TODO list. Haven't gotten to it yet. |
Describe the bug
I'm attempting to upgrade a storybook 6 project to storybook 7 and am running into an issue where the
storybook-dark-mode
doesn't work for docs pages.I've narrowed down the issue to
@storybook/api
useParameter('darkMode')
returning an empty object inside the addon, but only for rendering docs pages.To Reproduce
I don't have a reproduction at the moment, but a basic storybook v7 project with
storybook-dark-mode
added should exhibit the behavior. In chrome devtools I looked up themanager.js
file from storybook-dark-mode and added a breakpoint where it uses theuseParameter
hook.My guess is the parameters store isn't getting initialized for docs pages for some reason?
System
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: