-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
Description
Describe the bug
Prior context:
- React Refresh locates React components to wrap them into special code
- When a component changes, React Refresh blocks the live reload and triggers a page re-render
- To detect whether something is a component, React Refresh will check the function name
- If it starts with an uppercase, it's a component (no static analysis check)
The problem is that SWC will mangle variable names by using the 26 lowercase alphabetical letters. If it goes past that, it'll start using uppercase letters. This will break React Refresh's naive heuristic and cause it to disable live reload in the file listing the value.
To account for that, SWC should check whether the value assigned to the variable is a function literal, and preserve the first character's casing so that the heuristic returns the same result before/after.
Input code
const test1 = () => {};
const test2 = () => {};
const test3 = () => {};
const test4 = () => {};
const test5 = () => {};
const test6 = () => {};
const test7 = () => {};
const test8 = () => {};
const test9 = () => {};
const test10 = () => {};
const test11 = () => {};
const test12 = () => {};
const test13 = () => {};
const test14 = () => {};
const test15 = () => {};
const test16 = () => {};
const test17 = () => {};
const test18 = () => {};
const test19 = () => {};
const test20 = () => {};
const test21 = () => {};
const test22 = () => {};
const test23 = () => {};
const test24 = () => {};
const test25 = () => {};
const test26 = () => {};
const test27 = () => {};
const test28 = () => {};
const test29 = () => {};
const test30 = () => {};
console.log([test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11, test12, test13, test14, test15, test16, test17, test18, test19, test20, test21, test22, test23, test24, test25, test26, test27, test28, test29, test30]);
console.log([test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11, test12, test13, test14, test15, test16, test17, test18, test19, test20, test21, test22, test23, test24, test25, test26, test27, test28, test29, test30]);Config
Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
The post-mangling variables should all start with a lowercase letter.
Actual behavior
Some variables now start with an uppercase letter.
Version
1.14.0
Additional context
No response