vitejs / vite-plugin-vue

Vite Vue Plugins
MIT License
472 stars 151 forks source link

`undef` error in `<script setup>` breaks HMR #5

Open abitwhy opened 2 years ago

abitwhy commented 2 years ago

Describe the bug

Any undef error in the <script setup> will break the HMR. If auto save file is on, then entering any incomplete code will cause an error and break the HMR.

Break means it no longer working, even if correct the code. And only fresh the page will make HMR work. This happened only recently, and only happened in <script setup> .

Reproduction

https://vite.new/vue

Reproduce Steps

  1. Open a new Vite-Vue project (click the reproduction link above)
  2. Open src/App.vue
  3. Write an undef error in <script setup> (For example, write some characters in a new line)

System Info

N/A

Used Package Manager

npm

Logs

No response

Validations

github-actions[bot] commented 2 years ago

Hello @abitwhy. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

sapphi-red commented 2 years ago

I tested with https://vite.new/vue but didn't happen.

Would you write the steps to reproduce?

abitwhy commented 2 years ago

@sapphi-red The reproduce steps were added in the top comment.

sapphi-red commented 2 years ago

Please write more concrete steps. I'm still not able to reproduce. I edited HelloWorld.vue in the following steps.

  1. <script setup>
    import { ref } from 'vue'
    
    defineProps({
      msg: String
    })
    
    const count = ref(0)
    </script>
  2. <script setup>
    import { ref } from 'vue'
    
    defineProps({
      msg: String
    })
    
    const count = ref(0)
    
    console.log(
    </script>
  3. <script setup>
    import { ref } from 'vue'
    
    defineProps({
      msg: String
    })
    
    const count = ref(0)
    
    console.log()
    </script>
abitwhy commented 2 years ago

Check this:

vite-HMR-bug-with-script-setup

abitwhy commented 2 years ago

After more testing, I found that only no-undef error will case this bug.

sapphi-red commented 2 years ago

I was able to reproduce 👍