-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Ability to pass URL parameters to stories #6133
Comments
This was an oversight in the v5 URL handling and I think we should add it back. I think the trick will be to figure out an appropriate API to get this into the stories. @tmeasday @ndelangen opinions? It would be a straightforward change here: https://github.com/storybooks/storybook/blob/next/lib/client-api/src/story_store.js#L68 |
Did we use to pass the URL from the manager to the preview unmodified? @vitalybe I am curious about the use case here. I assume your components read from the URL directly? How do you go about setting the URL? Do you have to manually change it when you look at certain stories? Perhaps we could have an addon that sets the preview URL query parameters based on a story parameter? Maybe that is a nicer solution? .add(‘story’, () => ..., { query: { foo: “bar” } }) |
Some of the components perform AJAX calls to the backend when mounted, however, this behavior is disabled and mocks are used if In most cases when working with storybook, I like to work without any backend, so I would like to be able to add
I set it manually or via bookmark. I do have a "debug" floating window that I use to set the URL as well... So I guess it would be nice if I could also affect the URL storybook from the story as well, but that's just a nice to have.
Yes. If I want to choose to use or not to use backend. |
I wonder if there could be an addon which replicates the old functionality easily. It sounds like you want a bit more flexibility than the parameter based approach would provide (although maybe the parameters is a nice bonus that the addon could support) |
cc @ndelangen |
i second @vitalybe, one of our components relies on a redirect from a payment result, and we would like to have that showcased in storybook. |
@vitalybe an option for an alternative would be addon-context, and reading the mock boolean from there. You'd be able to switch mocking on and off from the storybook UI. I understand if that's not really feasible. I second @tmeasday's suggestion of an queryParameters addon that would read parameters.query and change the url accordingly before calling the storyFn. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
Also a duplicate of #4506 which was also auto-closed by stale bot 😞 |
@mkay581 Have you tried |
I've tried using for what it's worth, I agree with @vitalybe with the following statement in original post:
|
@mkay581 here's the code where we set the query params in the preview: storybook/lib/core/src/client/preview/url.ts Lines 21 to 31 in c1ff295
As you can see we keep all existing queryparams whenever we navigate in the preview. I do not see how we:
AFAICS we don't. if 1 story sets a query param, it should be preserved indefinitely, unless the iframe is refreshed for some reason.. |
Yes but I believe that is happening after the params have already been reset. I'm trying it out right now and can reproduce without failure. When I switch stories, somehow the query params I've set previously are removed. |
cc @tmeasday |
@mkay581 maybe can we open a new ticket with a reproduction that demonstrates the problem? This one is kind of old and the code involved has changed a bit since then so it would probably be easier for everyone to start fresh. |
Sure @tmeasday but it'll just be the same content as the original request 🙂. Dont have much time to create a whole repo that reproduces the issue but reproducing is simple:
Actual Behavior: Expected Behavior: |
How are you doing this exactly? |
@ndelangen I'm setting a param by doing the following: const params = new URLSearchParams(location.search);
params.set('test', 'foo')
history.pushState(null, null, `?${params.toString()}`); If I did this after a story loads, I would expect for the |
@mkay581 is that code running inside one of your stories or in |
Inside a story. I'm attempting to do it using the |
I found this really helpful: #769 |
We have a recommended way to do this in Storybook 6.2: #13803 This brings URL sync to Storybook Args which can also be be controlled in the UI. We'll be building on this more in future versions of Storybook. @allison-palum |
Is your feature request related to a problem? Please describe.
We're using URL parameters in many of our components, e.g
?mock=true
. However, storybook (v5.0.2) discards all the additional URL parameters I am giving to it.Describe the solution you'd like
The best solution would be if the user-defined URL parameters of the storybook would be automatically added to the iframe of the story. For example, it could be something like
?user-mock=true
. Which would be added to the iframe of the story as?mock=true
.If that's not possible, it would be nice if storybook at least wouldn't delete the unknown url parameters, as it does now. Then I could perhaps access from the story via
parent.window.location
or something like that.Describe alternatives you've considered
Without URL option, I would have to use cookies or something along these lines :(
Are you able to assist bring the feature to reality?
Maybe...
The text was updated successfully, but these errors were encountered: