Skip to content
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

HMR does not work with certain code in Vue #8224

Closed
7 tasks done
sxzz opened this issue May 18, 2022 · 8 comments
Closed
7 tasks done

HMR does not work with certain code in Vue #8224

sxzz opened this issue May 18, 2022 · 8 comments
Labels
bug: upstream Bug in a dependency of Vite feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@sxzz
Copy link
Member

sxzz commented May 18, 2022

Describe the bug

When using slot, the prop is not updated after modifying the prop of the child component.

<template>
  <!-- Simple example -->
  <Form>
    <!--              ⬇️ changed it but not updated -->
    <FormItem label="second" />
  </Form>
</template>
// form.js
import { renderSlot as _renderSlot } from 'vue'

// https://vue-next-template-explorer.netlify.app/#eyJzcmMiOiI8c2xvdCAvPiIsInNzciI6ZmFsc2UsIm9wdGlvbnMiOnsiaW5saW5lIjp0cnVlfX0=
// <slot />
export default (_ctx, _cache) => {
  return _renderSlot(_ctx.$slots, 'default')
}
// form-item.js
import { toDisplayString as _toDisplayString } from 'vue'

export default {
  props: { label: String },
  setup(props) {
    // https://vue-next-template-explorer.netlify.app/#eyJzcmMiOiJ7eyBsYWJlbCB9fSIsInNzciI6ZmFsc2UsIm9wdGlvbnMiOnsiaW5saW5lIjp0cnVlfX0=
    // {{ label }}

    // Generated code:
    return (_ctx, _cache) => {
      return _toDisplayString(_ctx.label)
    }
  },
}

Reproduction

Online: https://stackblitz.com/edit/vitejs-vite-z9guvb?file=App.vue&terminal=dev

Repo: https://github.com/sxzz/vite-hmr-issue

  • pnpm run dev for Vite example
  • pnpm run serve for Webpack example

Webpack works normally, but vite didn't update prop.

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.40 GB / 32.00 GB
    Shell: 3.4.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 16.15.0 - ~/Library/Caches/fnm_multishells/70638_1652903045156/bin/node
    Yarn: 1.22.18 - ~/.pnpm/bin/yarn
    npm: 8.5.5 - ~/Library/Caches/fnm_multishells/70638_1652903045156/bin/npm
  Browsers:
    Chrome: 101.0.4951.64
    Edge: 101.0.1210.47
    Firefox: 99.0
    Safari: 15.4
    Safari Technology Preview: 15.4
  npmPackages:
    @vitejs/plugin-vue: ^3.0.0-alpha.0 => 3.0.0-alpha.0 
    vite: ^3.0.0-alpha.1 => 3.0.0-alpha.1

Used Package Manager

pnpm

Logs

No response

Validations

@sxzz
Copy link
Member Author

sxzz commented May 18, 2022

Kapture.2022-05-19.at.03.46.12.mp4

Vite and Webpack

@sapphi-red
Copy link
Member

Looks similar to #7839. But it is interesting that this does not reproduce with webpack.
Maybe vuejs/core#5781 work for this too?

@thonymg
Copy link

thonymg commented Jun 2, 2022

Same issue, in my case i must restart the server to see change on certain file. But on other files it's work perfectly

@BSlaven
Copy link

BSlaven commented Jun 9, 2022

I have the same issue in react app. Change in one component triggers hrm as well as changes in its module.css file, but in the other component it does not.

@crystalfp
Copy link

Same problem when upgrading vite from 2.9.9 to 2.9.12
I'm working on vue 3 on Windows.

@daniloribeiro00
Copy link

Tried with Vite 3.0.0 but it still doesn't work properly

@oski646
Copy link

oski646 commented Jul 18, 2022

I've tried to remove everything in a single page to the moment that HMR works fine, and I found that...

HMR works:

<template>
  <Container class="mt-12">test</Container>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import Container from '@/components/app/Container.vue'

const route = useRoute()
const player = computed(() => route.params.player)
</script>

HMR doesn't work:

<template>
  <Container class="mt-12">test</Container>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import Container from '@/components/app/Container.vue'
import { useCookies } from 'vue3-cookies'

const route = useRoute()
const player = computed(() => route.params.player)
</script>

The only difference is single import: import { useCookies } from 'vue3-cookies'.
Maybe it will be helpful for someone who will be creating a fix.

vue3-cookies (1.0.6): https://github.com/KanHarI/vue3-cookies

@sapphi-red
Copy link
Member

Closing as I confirmed this worked after upgrading Vue to 3.2.38.

@sapphi-red sapphi-red added the bug: upstream Bug in a dependency of Vite label Oct 23, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

7 participants