vite-plugin-vue icon indicating copy to clipboard operation
vite-plugin-vue copied to clipboard

preserve state on HMR when multiple components exists in a single file

Open wxs77577 opened this issue 2 years ago • 5 comments

Related plugins

Describe the bug

import { defineComponent } from "vue";

export const Test = defineComponent({
  render() {
    return <b>Then change me...</b>;
  },
});

export default defineComponent({
  render() {
    return (
      <div>
        <div>
          <input type="text" placeholder="Type fist..." />
        </div>
        <Test></Test>
      </div>
    );
  },
});

Reproduction

https://stackblitz.com/edit/vitejs-vite-uda5gz?file=src/main.ts

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 125.39 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.18.0 - /opt/homebrew/bin/npm
  Browsers:
    Safari: 16.2
  npmPackages:
    @vitejs/plugin-vue: ^4.0.0 => 4.0.0 
    @vitejs/plugin-vue-jsx: ^3.0.0 => 3.0.0 
    vite: ^4.0.0 => 4.1.1

Used Package Manager

npm

Logs

No response

Validations

wxs77577 avatar Feb 16 '23 06:02 wxs77577

I wasn't able to reproduce. Would you write a more detailed steps?

sapphi-red avatar Mar 07 '23 05:03 sapphi-red

I wasn't able to reproduce. Would you write a more detailed steps?

The problem is when I change the jsx template of Test component and save the App.tsx, the msg in the default component has been reseted.

I've made some changes in App.tsx:

https://stackblitz.com/edit/vitejs-vite-uda5gz?file=src%2FApp.tsx,src%2Fstyle.css,src%2Fmain.ts

wxs77577 avatar Mar 10 '23 02:03 wxs77577

I see.

To achieve that, we somehow need to skip calling __VUE_HMR_RUNTIME__.reload for the default component. I'm not sure how we can do that though.

sapphi-red avatar Mar 10 '23 06:03 sapphi-red

it should call __VUE_HMR_RUNTIME__.rerender instead of reload.

edison1105 avatar Sep 24 '24 08:09 edison1105