-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Bug]: useParameter
API is not working on initial load.
#28592
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
Comments
@ndelangen Any ideas? |
Unfortunately, no. This is due to the fact that parameters are dynamic, and stories are loaded async; the manager can only know about the parameters on a story, after it's been loaded. |
@ndelangen Is there any API to know if a parameter has been loaded? |
No, there's currently no way to distinguish between those scenarios. |
@valentinpalkovic this issue is what we were discussing. #22119 also relates to the same topic so this is an 'old' bug. Sirrine-Jonathan/storybook-source-link#21 can be used as a repro repository as it is visible: the first time you load a story in that SB instance, two addons disappear from the toolbar and the source-link addon fails to load its data. You discussed a potential fix within useChannel(
{
[STORY_PREPARED]: () => {
setStory(api.getCurrentStoryData());
},
},
[]
); |
Does it not eventually work when the parameters come over the wire? In my original issue it was just about a flash of "unparameterized" content, not the addon getting stuck without parameters. |
Yes and no. The add-ons don't get reloaded with all the parameters when the story loads. They're missing parameters until the second time the story is displayed (as, by then, the manager has loaded it). |
Huh, I would have guessed |
Just want to confirm that this is a regression (either SB 8 or SB 9). If I browse SB on https://github.com/Sidnioulz/storybook-source-link/tree/ee910f644134d43edc03963ab0d15b9d21133002 (which is version 7) and https://github.com/Sidnioulz/storybook-source-link/tree/main (version 9), I can see on v7 that the toolbar flickers the first time a story is rendered (but does not flicker in subsequent renders), demonstrating that it reloads once parameters become available. On the SB 9 branch, the toolbar no longer updates. |
Hi @Sidnioulz Could you please try out this canary and let me know whether it fixes the reactivity issue? |
@valentinpalkovic congrats, it's working! 👏 |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
The
useParameter
API is not working on initial load.I'm implementing and managing a
storybook-addon-cookie
.My addon uses
useParameter
to read the cookie values entered by the user inside the story and display them in the panel.However, since migrating to storybook version 8, when I access the parameter via
useParameter
, I get an empty value on initial load.When I use
console.log
topreview
andPanel
, it appears to be getting an empty value untilpreview
is called.Is there any way to ensure that
preview.js
is called beforemanager.js
?Reproduction link
https://github.com/hwookim/storybook-addon-cookie
Reproduction steps
No response
System
The package pretty much follows the settings in addon-kit.
Additional context
No response
The text was updated successfully, but these errors were encountered: