-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
fix(plugin-vue): use __vccOpts for vue-class-component #5374
Conversation
…render function bug fix
This is highly desired. |
@sodatea, please take it as a friendly enquiry. When could you take a quick look at this little PR? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use __vccOpts
as in https://github.com/vuejs/vue-loader/pull/1897/files
More context:
https://github.com/vuejs/vue-class-component/blob/70680d78ed61ac57f27ed193fc69c80d90faf4fe/src/vue.ts#L90-L95
https://github.com/vuejs/vue-next/blob/9e3d7731c7839638f49157123c6b372fec9e4d46/packages/runtime-core/src/hmr.ts#L74-L76
Hi, thanks for the fix, will it take long to be deployed to npm? |
It's already in 2.7 beta. |
I meant the package plugin-vue, or these changes can be imported from vite directly as well? |
Oh sorry, I didn't realize that. It shall be available soon in the coming releases. |
Description
We use Vite with Vue 3 and Vue Class Component in class-style syntax.
Since vitejs/plugin-vue 1.8.1 version our apps broke with empty screen showing the following warning on the console:
Component is missing template or render function.
The problem is linked to the
_sfc_main
variable located inpackages/plugin-vue/src/main.ts
.Since class-style components utilize
export default class {...}
so that the value of the _sfc_main variable becomes the exported class itself, while using regular Vue component syntax it should be an object.The freshly introduced helper function in
packages/plugin-vue/src/helper.ts
tries to set values on the_sfc_main
variable (assuming it's an object, althougt in this case it's a class) declared inattachedProps
like this:Since
_sfc_main
passed as an argument is a js class, properties are not set corrently. As render function is not present on_sfc_main
,__VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)
leads to HMR error causing an empty page.This little PR modifies the helper function and checks if
_sfc_main
is a class and if so, it sets its value to and empty object, thus render function is set correctly.Fixing this Vue Class Component related issue would be highly desired and appreciated by merging this PR or by other solution since most of our mid-sized projects rely on class based Vue.
Thank you!
Additional context
none
Reproduction
The malfunction can be easily reproduced from the following issue: #5352
or https://github.com/borkeszmate/vite-vue-plugin-bug (navigate to about)
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).