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

func name with uppercase letter cause hot reload failure? #6885

Closed
7 tasks done
yukilzw opened this issue Feb 12, 2022 · 9 comments · Fixed by #10239
Closed
7 tasks done

func name with uppercase letter cause hot reload failure? #6885

yukilzw opened this issue Feb 12, 2022 · 9 comments · Fixed by #10239

Comments

@yukilzw
Copy link

yukilzw commented Feb 12, 2022

Describe the bug

Use react template. When a function name that starts with an uppercase letter in a component, hot reload was fail, It only can refreshed browser unless the function is changed to lowercase:

// hot reload fail
const Func = () => null;
export default () => 123;

// hot reload success
const func = () => null;
export default () => 123;

Reproduction

issue-mini-project

System Info

System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.0.0 
    npm: 7.10.0
  Browsers:
    Chrome: 98.0.4758.80
  npmPackages:
    @vitejs/plugin-react: ^1.0.7 => 1.2.0 
    vite: ^2.7.2 => 2.8.1

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Feb 13, 2022

I can't reproduce the behaviour you described. Please create a minimal reproduction, e.g. GitHub repo or stackblitz to help show the bug.

@github-actions
Copy link

Hello @yukilzw. 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.

@yukilzw
Copy link
Author

yukilzw commented Feb 14, 2022

I can't reproduce the behaviour you described. Please create a minimal reproduction, e.g. GitHub repo or stackblitz to help show the bug.

https://github.com/yukilzw/issue-vite-project

Easy to reproduce, I used vite npm command to create a new repository and just split the original template code into Comp.jsx.Please have a look.

@GregBorrelly
Copy link

GregBorrelly commented Feb 14, 2022

I was able to reproduce as well by cloning the repo above on Node v16. When updating the content in the Comp component, the following log appears on the terminal but the page does not update unless I refresh.

2:51:27 PM [vite] hmr update /src/Comp.jsx (x4)

However when I created a new vite project and created a component by the same name. HMR worked as expected.

@yukilzw
Copy link
Author

yukilzw commented Feb 15, 2022

I was able to reproduce as well by cloning the repo above on Node v16. When updating the content in the Comp component, the following log appears on the terminal but the page does not update unless I refresh.

2:51:27 PM [vite] hmr update /src/Comp.jsx (x4)

However when I created a new vite project and created a component by the same name. HMR worked as expected.

It is related to the reference path of the component. According to my test, If you put all the components and function in root file, there is no problem. So you can find what's the different from mine.I just changed reference path of the default vite project template.

@maietta
Copy link

maietta commented Mar 16, 2022

Turns out, this seems to be the same problem when naming fileNames with a capital letter in the name but not the first letter. As a result, HMR function fails to work for those files. Took me nearly two days to figure this out.

@qbunia
Copy link

qbunia commented Apr 15, 2022

Got same problem as above

@ZYSzys
Copy link
Contributor

ZYSzys commented Jun 28, 2022

I dig into this problem, and found it's the intentional behavior of react-refresh/babel, named your component then the fast refresh could be work.

https://github.com/facebook/react/blob/a4bed469697a1e23c398fe80228df31ef6d4b612/packages/react-refresh/src/ReactFreshBabelPlugin.js#L437

// Anonymous direct exports like export default function() {}
// are currently ignored.

https://github.com/facebook/react/blob/a4bed469697a1e23c398fe80228df31ef6d4b612/packages/react-refresh/src/ReactFreshBabelPlugin.js#L526

// We don't currently handle anonymous default exports.

@maietta
Copy link

maietta commented Jun 28, 2022

@ZYSzys Holy moly, thank you for digging into this and identifying the root cause. I was fairly new to Vue + Vite when i ran into this problem and wasn't sure how to find the root cause. I had issues digging into it.

My solution was to begin lowercasing everything as much as I didn't want to.

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

Successfully merging a pull request may close this issue.

6 participants