vue2 tsx (class component) hmr exception
See original GitHub issueDescribe the bug
vite@3 + vue2 + class component + tsx
When use lang="tsx"
and class component, the vite hmr error.
See below about “Steps to reproduce” for details.
Reproduction
–
Steps to reproduce
dependencies
{
"@vitejs/plugin-vue2": "^2.0.1",
"@vitejs/plugin-vue2-jsx": "^1.0.3",
"vite": "^3.2.3",
"vue": "^2.7.14",
"vue-class-component": "^7.2.6",
"vue-property-decorator": "^9.1.2"
}
set lang="tsx"
<template>
<el-form
ref="form"
:mode="value"
size="mini"
@submit.native.prevent
>
<el-form-item label="Test">
<!-- e.g.: changed "v-model" to test1, -->
<el-input type="input" v-model="test" clearable />
</el-form-item>
</el-form>
</template>
<script lang="tsx">
import Vue from 'vue';
import { Component, Prop, Watch } from 'vue-property-decorator';
import type { TestProps } from '../types';
@Component({
name: 'Test',
})
export default class Test extends Vue {
@Prop()
readonly value!: TestProps;
// e.g.: changed "get test" to test1
get test() {
return this.value.test;
}
}
</script>
an error occurred when changed the get property, e.g.:
-
changed
v-model
andget test
totest1
-
vite hmr
-
we can find two requests in the network
-
.../form/index.vue?t=1668996911179
It‘s right, the content is as follows
-
.../form/index.vue?t=1668996911179&vue&type=script&lang.tsx
Here is error, the content is still
test
-
Everything works fine when not using tsx (set lang="ts"
), because only one hmr request (.../form/index.vue?t=1668996911179
).
And, if I continue to add the set test1() {}
, even if I add a new line, sometimes, the hmr request content is fine.
System Info
Chrome 107.0.5304.62 (arm64)
Used Package Manager
yarn
Logs
The error logs:
[Vue warn]: Property or method "test1" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
HMR does not work with class-components loaded in the router
In the 'App.vue' I created a class component in which HMR does work, try changing the text and you see it updated on...
Read more >Vue Typescript @Component throwing compile error. with vue ...
I am using vue-class-component and vue-property-decorator. I have followed almost every setup I could find and still cannot resolve this.
Read more >@vue/compat | Yarn - Package Manager
Dependencies that rely on Vue 2 internal APIs or undocumented behavior. The most common case is usage of private properties on VNodes ....
Read more >JS-0239 · Consider using `let` or `const` instead of `var`
1064 // exception: calling readonly() on a reactive object 1065 if ... 1786 console.warn(`[HMR] Something went wrong during Vue component hot-reload.
Read more >Encore, Symfony & API Platform > The Delightful World of Vue
In this tutorial, we'll be using Vue version 2. But even as I'm saying this, Vue version 3 is nearing release and might...
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
I’d love to, I will give a try
The
handleHotUpdate
betweenplugin-vue2
andplugin-vue
looks the same.https://github.com/vitejs/vite-plugin-vue2/blob/eaa7886b2a0359af2589d4d31412c5136f60c3b9/src/handleHotUpdate.ts#L54-L68
Plus, I can ensure this happens in
plugin-vue
too.See https://stackblitz.com/edit/vitejs-vite-r6uw9g?file=vite.config.js,index.html,src%2Fmain.ts,src%2Fhelloworld.vue,src%2FApp.vue,src%2Fassets%2Fbase.css,src%2Fassets%2Fmain.css,src%2Fassets%2Flogo.svg,package.json
I will give a try to offer a PR, let’s discuss there. @sapphi-red