-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Component is not re-rendered when its iternal state is updated. #12578
Comments
Do you have a repro repo you can share? |
@daKmoR @LarsDenBakker any idea why this might work in the open-wc version but fail in storybook proper? |
Not at the moment unfortunately, the code is part of a larger project that is not open source, but I will try and create a repro repo on Monday. |
I created a repro repo: https://github.com/adarean5/storybook-web-components-repro |
I also realize this issue might have occurred due to user error, but I was unable to find any resources on how to properly configure storybook for lit-element based web components. |
Thanks so much for creating a repro -- hopefully we can get to the bottom of this! 🙏 |
This might be related to https://github.com/Polymer/lit-element/issues/1030 When using typescript decorators, we need to make sure class fields also get compiled correctly. The new standard based class fields use "define" semantics for class fields, while typescript decorators rely on "set" semantics class fields. So we need to make sure the class fields are compiled by TS/babel using this logic. I'm not 100% up to date with what happens where in the pipeline of storybook. You could try setting target to es2020 or es2019 in your tsconfig. Separately it might be helpful in storybook to configure it to compile class fields this way when people use typescript, since that's what a lot of typescript users rely on. |
@adarean5 any chance you can investigate these suggestions and report back? i'm open to changing Storbyook's TS config if it doesn't break anything else. |
Firstly, @LarsDenBakker thank you for the suggestion! |
@shilman luckily I did manage to find some time to look at what @LarsDenBakker suggested.
However I didn't want to modify my component just for Storybook, and I was also worried about this quote from the issue that @LarsDenBakker linked:
So I decided to extend my component in the .story file and overload it there instead. You can see the changes that were required in this commit (excuse the unnecessary .idea files, forgot to update the gitignore I didn't have the chance to test it thoroughly, but on the surface it seems to do the trick. |
Awesome you found a workaround! @LarsDenBakker Any idea what the proper storybook fix might look like? |
I dug into this a bit, it looks like class properties are compiled correctly using "loose" mode:
But unfortunately babel decorators don't work quite the same as typescript, and in this case the lit-element decorators don't work with babel legacy decorators: lit/lit-element#205. They do work with typescript decorators, and non-legacy babel decorators. Quite a messy situation with all these competing implementations of non-standard syntax :) In my opinion if you rely on typescript semantics other than types, you should compile with TSC before doing anything with the code. Otherwise you'll always be chasing tools to get the same behavior. You may also be able to overwrite the babel configuration of storybook, for example to use the non-legacy decorator plugin. |
To have TS Lit components working in our Storybook we set plugin-proposal-decorators to this (which also keeps the legacy option to false by default): |
Our full Storybook babel config if that's helpful:
|
Unfortunately SB's built-in typescript support is based on babel. We currently don't have a tsc option, tho we'll probably add a "disable built in" option at some point. |
Hello guys. I think I'm facing the same issue using the project pwa-webpack-starter-kit. If you run the project using |
I think it would be useful to make this a bit more configurable in storybook. I understand the desire to make things easy for users by default, but having plugins enabled for non-standard features can be problematic for people when proposals change over time and browsers start to implement the final standardized version. Just a suggestion of course :) |
@LarsDenBakker I agree. In general we'd try to give users three options:
Hopefully Coming Soon (TM) |
Thank you for sharing the config that solved the problem for you @Niznikr , it allowed me to come up with my own solution that uses the babel option in .storybook/main.js. Here is the code snippet that I added to module.exports in .storybook/main.js: babel: async (options) => {
Object.assign(options.plugins.find((plugin) => plugin[0].includes('plugin-proposal-decorators'))[1], {
decoratorsBeforeExport: true,
legacy: false
})
return options;
} It finds the existing config for '@babel/proposal-decorators' and modifies the properties, so they work with lit-element's decorators. You can find the full solution in this commit in the main.js file. I'm sure the solution could be improved upon and I would be thankful for any suggestions, but it seems to work well enough for now and unlike my previous solution it does not require any special boilerplate in the .story files. I would also like to thank everyone for their help and suggestions! |
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! |
this worked for me (2021-10-06) if youre coming here trying to get this to work |
This is work for too, thank you! |
Hi! I have the same issue using the new storybook 7 with vite-builder. On a static build the story does not re-render when updating the model. Any idea if the solution could be similar? env: |
Describe the bug
I am working on a Storybook project that uses lit-element based components.
While creating the Storybook project with the
sb init
script I selected the Web Components option.I imported one of my components, that is using lit-element and got it working for the most part.
The component updates when I change the controls in the storybook UI Storybook and so on.
The component doesn't re-render if its props change internally.
For instance: I have a counter component that is composed of a button and a text element.
The component has a prop count, which is updated every time the button is clicked via a component's function called increment which just increases the count by one.
As far as I could tell, the button click will trigger the increment function properly, the count prop will increase, but the component won't be re-rendered with the new value of the count prop.
This also happened when I modified the original Button component that came with the Web Components storybook, which only uses lit-html.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The number next to the button should update.
Screenshots
This is how the component should look in the UI
Code snippets
The lit element component:
I define the custom element in .storybook/preview.js like so:
And this is how the storybook file is defined:
System:
Additional context
I am using version 6.0.21 of Storybook.
Before switching to standard Storybook I was using the
@open-wc/demoing-storybook
(https://www.npmjs.com/package/@open-wc/demoing-storybook) package for demoing my lit-element based components, and the component updated as expected.The component also behaves as expected when used inside a Vue 3 project.
The text was updated successfully, but these errors were encountered: