lit-element props configured by TS decorators do not cause a re-render of the component
See original GitHub issueDescribe the bug With Lit-element, using controls to update the element’s properties, storybook does not cause a render of the component when the component’s properties are defined by TypeScript decorators.
To Reproduce https://github.com/steveworkman/sb6-ts-decorators-bug
- In that repo - run the storybook
- In the non-decorators story, change the “kind” to be “secondary” - see that the component re-renders and the colour changtes
- Do the same in the decorators story
Expected behavior The component should re-render the same as the non-decorator one
Code snippets Repo: https://github.com/steveworkman/sb6-ts-decorators-bug
System:
Environment Info:
System:
OS: macOS 10.15.6
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
npm: 6.14.7 - ~/.nvm/versions/node/v12.16.1/bin/npm
Browsers:
Chrome: 85.0.4183.83
Safari: 13.1.2
npmPackages:
@storybook/addon-actions: ^6.0.21 => 6.0.21
@storybook/addon-essentials: ^6.0.21 => 6.0.21
@storybook/addon-links: ^6.0.21 => 6.0.21
@storybook/web-components: ^6.0.21 => 6.0.21
Additional context I think it’s to do with how the TS decorators are transpiled, but I can’t be sure. This was working in SB 5 with a webcomponents setup.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Properties
A property change can trigger an asynchronous update cycle, which causes the component to re-render its template. When a property changes, the following ......
Read more >lit-element not changing view after property value change
This may be why a change to selName is not getting you a re-render of simple-el with an updated user property, because you...
Read more >How to Observe Property Changes with LitElement and ...
Also, I explained how LitElement manages the declared properties and when it triggers an update cycle, causing the component to re-render ...
Read more >Args - Storybook - JS.ORG
Args can be used to dynamically change props, slots, styles, inputs, etc. It allows Storybook and its addons to live edit components. You...
Read more >Lit for React Developers
Components & Props; State & Lifecycle; Hooks; Children; Refs; Mediating State. What you'll build. At the end of this codelab will be ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The proposed fix by @emilio-martinez works for me. I added a
babel.config.js
into the.storybook/
directory with the plugins. Thanks!I’m not able to fully dig in now, but this does sounds familiar. I believe this is a Babel-related issue when applying the following combination of options within the Babel config:
TL;DR, use these options instead
LitElement has two decorator implementations, attempting to support two different stages of decorator proposals. The Typescript compiler (
tsc
) uses the older proposal, while Babel’s@babel/plugin-proposal-decorators
by default will use the newer one. However,@babel/plugin-proposal-decorators
optionally allows for alegacy
flag, which instead switches to support the same proposal used withtsc
.However, that
legacy
option from Babel doesn’t work well with LitElement decorators + Typescript. Instead, when using Babel you should target the non-legacy variant and enable thedecoratorsBeforeExport
option as shown above. I do rememberuseDefineForClassFields
being an issue in some cases, as Justin mentioned, but I don’t remember that being related to this particular issue. Incidentally, Babel applies that behavior via@babel/plugin-proposal-class-properties
.