-
Notifications
You must be signed in to change notification settings - Fork 17
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
[addon-knobs] Seeing knobs from previously selected story #19
Comments
Okay I did find that And the result: still not fixed 😥 |
Please try |
I know, but addon-controls requires a HUGE amount of refactoring, and tbh the syntax doesn't quite make a lot of sense to me yet. I think the documentation needs more love. Anyhow, I want to keep using addon-knobs for now, and migrate to addon-controls at a later stage. The upgrade itself is already big enough as it is. On top of that, since addon-knobs was upgraded to 6.0 as well, I'd expect it to at least work correctly. Even if it's deprecated. In the mean time I've got a workaround. In module.exports = {
stories: ['../../src/**/*.stories.@(jsx|mdx)'],
addons: [
'@storybook/addon-knobs/register',
'@storybook/addon-a11y',
'@storybook/addon-docs',
],
}; So, using the register-behaviour instead of the preset. And then in my import { withKnobs } from '@storybook/addon-knobs';
// Some other guff here
export const decorators = [
// Some others
withKnobs,
// Some others more
]; Works great now. But the question is, why is the preset now working? |
@thany that comment was as much for anybody else who stumbles onto this issue as it was for you. we're all in addon-controls with stabilizations in 6.1 and a bunch of new features coming in 6.2. |
Alright, fair enough. So, should I keep using the register-behaviour or should we try and find the actual cause of why the preset-behaviour is causing this weird behaviour where knobs are sort of persisted? /edit /edit2 import React, { Fragment } from 'react';
import track from 'react-tracking';
const withTracking = storyFunc => {
const TrackedStoryWrapper = track({ event: 'event' }, {
dispatch: data => {
console.log('%cTracking event', 'color:#1ea7fd;font-style:italic', data);
},
})(storyFunc);
return (
<Fragment>
<TrackedStoryWrapper />
</Fragment>
);
};
export default withTracking; It seems to be the |
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! |
The workaround (to specifiy On top of that, changing the value in a knob has no effect on the story that uses it. @shilman Would you happen to know another trick to get knobs to work again? |
As a temporary fix, you can run some code in an interval to reset the knobs every time a new story has changed. In the below code, all I am doing is waiting for the URL query string 'path' to change and once it does, it will reset the knobs to its original state. This seems to fix the problem. in your main.js ensure that knobs is your first add-on tab addons: [
'@storybook/addon-knobs',
...
] In your preview.js, add this code to the bottom of the file let currentPath
if (window.parent) {
const parentWindow = window.parent
parentWindow.setInterval(function(){
const urlParams = new URLSearchParams(parentWindow.location.search);
const path = urlParams.get('path');
if (path && path !== currentPath) {
currentPath = path
const knobButtons = parentWindow.document.querySelectorAll('#panel-tab-content button')
if (knobButtons) {
const resetButton = knobButtons[knobButtons.length - 1]
resetButton.click()
}
}
}, 100);
} |
Awesome workaround, works very good for me.
|
Hi everyone, I've created PR with the fix. |
Works for me the fix!! thanks @mgameover |
I haven't got a chance to take a look at those numbers, but I'll try to take a look at that. That PR is fixing just one issue - "adding knobs from other stories". |
I also encountered this bug when knobs are not cleared between stories, if using the |
I had an issue with knobs for the wrong component (always the same wrong component) being shown on first load, which takes longer to render than switching between components. I modified @rohanrp's solution slightly to allow longer on the first render, and to check for length of the array to avoid console error.
|
#45 was merged with the fix for this. It is included in the 7.0.2 release |
Describe the bug
When I select the first story after starting storybook, I see its knobs just fine. Then when I select another story, its knobs are added to the knobs that were there from the previously selected knobs.
Worse even, if the previously selected story had knobs in categories (tabs), the non-categorized knobs from the newly selected story are now tucked away in a "Other" tab.
To Reproduce
Upgrading/migrating from storybook 5.3 to 6.0, I suppose. That's the only thing that happened that made this break. I am already using the knobs preset in
main.js
, rather than its "register" notation inaddons.js
. And of course, everything is at the same 6.0.28 version.Expected behavior
Knobs panel should only ever display knobs from the currently selected story.
Screenshots
1 - These are from the previously selected story and do not belong here. They never go away, even after having selected a docs-only story where the side panel goes away entirely.
2 - This is from the currently selected story, and should not be a tab. The currently selected does not have its knobs in categories, so I expect no tabs at all.
Code snippets
Relevant part of
main.js
:Relevant part of
manager.js
:I don't know what else. There's no reference to knobs in
preview.jsx
, nor intheme.js
.System
Results of
npx sb@next info
:It doesn't see my actual browser, Firefox 82.
The text was updated successfully, but these errors were encountered: