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

[plugin-react-refresh] auto page reloading is broken when a jsx file contain multi-components #11

Closed
7 tasks done
kljzndx opened this issue Sep 14, 2021 · 6 comments · Fixed by #79
Closed
7 tasks done
Labels
feat: hmr p3-minor-bug 🔨 An edge case that only affects very specific usage (priority)

Comments

@kljzndx
Copy link

kljzndx commented Sep 14, 2021

Describe the bug

For details. Please view the video

video

Reproduction

https://github.com/kljzndx/Test-Demos/tree/vite-react-bug

System Info

System:
    OS: Linux 5.10 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (4) arm64 unknown
    Memory: 1.52 GB / 3.71 GB
    Container: Yes
    Shell: 5.7.1 - /usr/bin/zsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 7.23.0 - /usr/local/bin/npm
  Browsers:
    Chromium: 89.0.4389.114 # Raspberry pi
    Edge: 93.0.961.47 # local PC

Used Package Manager

yarn

Logs

No response

Validations

@IanVS
Copy link

IanVS commented Sep 15, 2021

React fast refresh does not work with class components, only functional components. There's an issue vitejs/vite-plugin-react#8 open to include class components.

@kljzndx
Copy link
Author

kljzndx commented Sep 16, 2021

好吧,看来是我误解了。但是为什么文档里面只字未提这件事?
--------------Google Translate------------
Well, it seems I misunderstood. But why is it not mentioned in the document?

@JonathanSoszka
Copy link

I was having the same issue using functional style components. I was able to fix this by not using export default

Chainging this code

export default function() {
  return (
    <div className={"grid"}>
      <div className={"col-12"}>
        <ProfileHeader/>
      </div>
      <div className={"col-12 lg:col-6"}>
        <ProfileInfoCard/>
      </div>
      <div className={"col-12 lg:col-6"}>
        <ProfileGamesCard/>
      </div>
    </div>
  );
}


function ProfileInfoCard() {
  return (
    <Card title={"Info"}></Card>
  )
}


function ProfileGamesCard() {
  return (
    <Card title={"Games"}></Card>
  )
}

To This, fixed it for me

export function Profile() {
  return (
    <div className={"grid"}>
      <div className={"col-12"}>
        <ProfileHeader/>
      </div>
      <div className={"col-12 lg:col-6"}>
        <ProfileInfoCard/>
      </div>
      <div className={"col-12 lg:col-6"}>
        <ProfileGamesCard/>
      </div>
    </div>
  );
}


function ProfileInfoCard() {
  return (
    <Card title={"Info"}></Card>
  )
}


function ProfileGamesCard() {
  return (
    <Card title={"Games"}></Card>
  )
}

@patak-dev patak-dev transferred this issue from vitejs/vite Dec 3, 2022
@sapphi-red
Copy link
Member

I confirmed this still does not work. (Vite 4.0.2 + plugin-react 3.0.0)
https://stackblitz.com/edit/github-vnvsys?file=src%2FTest2%20-%20component.jsx

HMR not happening is expected due to the limitation of react refresh, but the full reload should happen.

@sapphi-red sapphi-red added feat: hmr p3-minor-bug 🔨 An edge case that only affects very specific usage (priority) labels Dec 19, 2022
@Carseason

This comment was marked as duplicate.

@ArnaudBarre
Copy link
Member

This issue will be fixed by #79. Waiting for Vite 4.1 to enable this change

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: hmr p3-minor-bug 🔨 An edge case that only affects very specific usage (priority)
Projects
None yet
6 participants