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 reload changes in default props #350

Closed
7 tasks done
chawes13 opened this issue Jul 17, 2024 · 2 comments
Closed
7 tasks done

HMR does not reload changes in default props #350

chawes13 opened this issue Jul 17, 2024 · 2 comments

Comments

@chawes13
Copy link

chawes13 commented Jul 17, 2024

Describe the bug

I am changing the value of a default prop and seeing subsequent "hmr update" logs in the terminal. The new value of the prop does not show up in the component when no value is passed for the prop to the component (i.e., the default is used).

Reproduction

https://stackblitz.com/edit/vitejs-vite-velxyz?file=src%2FApp.jsx

Steps to reproduce

  1. Update the value of title in defaultProps
  2. Save
  3. New value of title is not shown in the <h1>

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    vite: ^5.3.4 => 5.3.4

Used Package Manager

npm

Logs

No response

Validations

@ArnaudBarre
Copy link
Member

This is something that should be handled at the Fast Refresh level, but it's not and probably never will be because fast refresh was released in 2019, 4 years after default parameters have been a thing in the language. I'm quite impressed that this as not been deprecated yet.

You should rewrite your code like this

function App({ title = 'Vite + React (test)!' }) {

and also consider using TS:

function App({ title = 'Vite + React (test)!' }: { title?: string }) {

@ArnaudBarre ArnaudBarre closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2024
@chawes13
Copy link
Author

Company constraints 🤷 . It works with Webpack, so it's a bit annoying to introduce this regression when switching build tools. Given that defaultProps are getting deprecated in v19, I'll move over to default parameters.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants