-
-
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
Controls Addon - Web Components - Update property without re-rendering story #15488
Comments
As far as I know there's no As for a controls event, the closest thing is the |
I'm not sure what use-case this is trying to solve, but if the issue is the one described in #9128 then I suspect the issue is resolved in 6.3 and this workaround isn't needed any more. |
About this issue, I am using version 6.3.3 but components are always reloaded when changing args, so we are unable to test transition. I am missing something? Or is just solved for knobs addon and for control addon the behaviour is always rerender? |
@rtrap95 - can you provide a bit more detail -- are you using web components? Components should not be remounted when changing args. If they do it is a bug. |
When a component property changes, the component might have different logic depending if it is mounted or not. Currently we can only test the unmounted branch.
I am using 6.2 due to
|
The correct behaviour for args is that when args change, the component should not remount. This the way knobs (was supposed to) work, too. If that's not the case, then I suspect the issue here is a bug in the web components framework addon. So I am still unsure about what #9447 is for exactly. |
Any updates on this? I'm also experiencing an issue with seeing transition animations since the component just re-renders after changing args |
I think this is an open issue that someone might be able to fix in the
|
Disclaimer: I have only spent 5 minutes looking into this, so the following might be incorrect.
Looking at this history of the file it looks like It looks to me that the problem is
The catch is if someone doesn't have a "reactive" web component, they would probably want the current behavior to rerender the canvas to reflect the new arg. The new |
I have a workaround. In my case the problem described above is due to how I setup my components story to rely on the default render. For example: // my-component.stories.js
import './my-component.js';
export default {
component: 'my-component'
}
export const MyStory = {
args: {
foo: 'bar'
}
} The above code will always remount The workaroundI don't see the problem if I define my own custom render function. For example: // my-component.stories.js
import { html } from 'lit';
import './my-component.js';
export default {
component: 'my-component',
render: args => html`<my-component foo=${args.foo}></my-component>`
}
export const MyStory = {
args: {
foo: 'bar'
}
} I use // my-component.stories.js
import { html } from 'lit';
import { spreadProps } from '@open-wc/lit-helpers';
import './my-component.js';
export default {
component: 'my-component',
render: args => html`<my-component ${spreadProps(args)}></my-component>`
}
export const MyStory = {
args: {
foo: 'bar'
}
} |
I'm using Vue 3 and this solution works for Vue Transitions (with a Vue render function of course), but it only works if I have the default export as in your example. Problem is, Storybook's Meta needs to be the default export if I want to use that. And I can't find another way to set Meta data without it being the default export. edit |
I am not clear on the issue you are hitting, but let me provide another example of the workaround that doesn't change the import { html } from 'lit';
import { spreadProps } from '@open-wc/lit-helpers';
import './my-component.js';
export default {
component: 'my-component',
}
export const MyStory = {
args: {
foo: 'bar'
}
render: args => html`<my-component ${spreadProps(args)}></my-component>`
} The only thing I changed was to move the |
The Knobs addon has a
disableForceUpdate
option which stops the story re-rendering after a knob value has changed. There is also an event emitted when the knobs change,storybookjs/knobs/change
.The Controls addon allows the getting and setting of the control state but I don't think there's a hook point for when the value changes, like described in #9447.
Is such a pattern possible with Controls?
The text was updated successfully, but these errors were encountered: