-
-
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]: Components lose reactivity when using Decorators (7.0.0-RC9 Vue3) #21812
Comments
I believe this is being addressed in #21273 @chakAs3 @kasperpeulen can you please confirm? |
@shilman Yes, this would be solved by that PR (assuming we can fix all cases in the PR, but that is at least the goal). |
I tried the recipe and ran into the same issue. I replaced the render function with a component and story controls started working fine: import type { Decorator } from '@storybook/vue3';
import StoryWrapper from './StoryWrapper.vue'; //https://github.com/Integrayshaun/vue3-vuetify-storybook-recipe-example/blob/main/.storybook/StoryWrapper.vue
export const DEFAULT_THEME = 'light';
export const withVuetifyTheme: Decorator = (story, context) => {
const themeName = context.globals.theme || DEFAULT_THEME;
return {
components: { StoryWrapper, story },
setup() {
return {
themeName,
}
},
template: `
<story-wrapper :theme-name="themeName">
<template #story>
<story />
</template>
</story-wrapper>
`
}
}; But the story for HelloWorld lose its reactivity for theme switching. |
Hi @Jman we are aware of this issue there is already a PR that fixes this #21273 |
Yes @shilman it covers all cases including global decorators, that use function or template,i will added this case to e2e tests and merge next. to have it ready and avoid any merge conflict |
hi @Jman @JorisAerts , you can check out this repo i have created some stories using Vuetify, i think it is a minimal way to implement latest Vuetify, pretty simple similar to what was in receipt with some minors changes. There is also other stories with different type of decorators (global, story decorator, function decorator , and template decorator). CSF2 format is there as well, let me know if that seems ok for you
i'm really impressed by the quality of your bug report as you really pointed all the issues even you could detect when it works as expected by removing { theme } actually in my latest PR i fixed all this with one caveat here which you spotted { theme } in oder to have it reactive in Vue way you just need to pass a reactive props , these props can be updated by the globals or any other effect like this // .storybook/withVuetifyTheme.decorator.js
import { h , shallowReactive} from 'vue';
import StoryWrapper from './VuetifyAppWrapper.vue';
export const DEFAULT_THEME = 'light';
const theme = shallowReactive({themeName:DEFAULT_THEME});
export const withVuetifyTheme = (storyFn, context) => {
// Pull our global theme variable, fallback to DEFAULT_THEME
theme.themeName = context.globals.theme || DEFAULT_THEME;
const story = storyFn();
return () => {
return h(
StoryWrapper,
// pass a reactive props contains themeName to StoryWrapper
// make sure you don't destruct this 👍 if you like to keep reactivity
theme,
{
story: () => h(story, { ...context.args }),
}
);
};
}; |
@shilman @kasperpeulen |
Yippee!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.7 containing PR #21954 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
I ran into a similar issue while observing the global variable 'theme' in version 7.5.2 with [email protected]. (story, ctx) => {
const { theme = 'light' } = ctx.globals
let template = '<story />'
watchEffect(() => {
if (theme === 'light') {
template = '<story />'
}
if (theme === 'dark') {
template = '<div class="dark-mode"><story /></div>'
}
if (theme === 'side-by-side') {
template = `<div style="display: flex"><div style="flex: 1"><story /></div><div style="flex: 1" class="dark-mode"><story /></div></div>`
}
})
return {
components: { story },
template
}
} Do you have any suggestions on how to resolve this? |
@Joey-J3 We only fixed this for Vue3, and have deprecated the Vue2 framework in 8. |
Describe the bug
After upgrading from 6.5 to 7 RC9, the component in the story doesn't adapt anymore when I change the controls in the Controls tab. The reactivity is just gone. I'm using @storybook/vue3 & @storybook/vue3-vite.
After some investigation, I found some workarounds, but this seems like a bug.
To Reproduce
Scenario 1 (using a global decorator)
The following code results in components losing reactivity, when changing props from within the Controls panel:
🛠️ WORKAROUND: By just removing the parameters-object from the top-level component in the render-function, reactivity is enabled back again:
This is kind of annoying, because it forces me to use a "global variable" as a Vue-ref to which I can write the current theme, and have it picked up by the vuetifyDecorator. 😕
Scenario 2 (using a story-decorator)
When using a decorator on a story, like below, the decorator makes the control to lose reactivity:
The decorator looks like this:
🛠️ WORKAROUND: Pass
story
as an argument and render the component usingh
makes reactivity come back:(I had to use
any
because I don't know the type ofstory
).System
Additional context
For global decorators, when I add a
console.log
statement in the decorator's render-function, it's only logged once, but not after I update the control.Without the
{ theme }
props object, the console.log is triggered upon every change and works as expected:Adding a
console.log
in the render-function within the story itself, DOES log the changes, but does not affect the rendered component itself. Theargs
DO seem to change, but are not applied:The text was updated successfully, but these errors were encountered: