Description
Version
3.2.8
Reproduction link
Steps to reproduce
- See in the example how the css classes on a simple button component are updated with a computed property when its props change. This can be viewed with
npm run serve
. (Sometimes the sandbox throws errors about module import locations, but a refresh fixes that) - Run the included
build:lib
command to build that component as a library. Will probably have to be done outside of CodeSandbox - Import that built component into some other Vue application
- The CSS classes should no longer update, because the computed property is no longer being recalculated when its dependencies change.
What is expected?
After days of debugging this behavior I noticed that VS Code had automatically imported computed
for me as:
import { computed } from "@vue/reactivity";
rather than:
import { computed } from "vue";
This import works in development mode, and everything behaves how it should. However, my computed properties were not updating when the props they depended on were updated when I used the vue cli command to build them as a library.
I realize that I was not importing things as documented, but I would rather one of two things happen:
- See a console warning that I'm importing
compute
incorrectly - VS Code not suggest the incorrect import from
vue
What is actually happening?
Computed properties are transpiled differently based on which way you import computed
when you're build target is a library. When using the components build as a library the computed properties are only ever calculated once and basically cause components to fail silently.
Ran into this bug while I was developing components for a UI library. VS Code tried to be helpful and import computed
for me, but it used the wrong import statement and sent me down a rabbit hole for days. It would be really great if there were some guard rails in place so no one else gets stuck the same way I did!
I can supply more verbose examples of the transpiling differences I'm talking about if that would be helpful.