Minification bug in production build that does not exist when using dev server
See original GitHub issueDescribe the bug
I tracked down the bug to a return statement that the minifier resolved to return null/nothing, but the dev server returned a component as expected.
Environment
CRA not ejected react-scripts 3.4.1
bug seen in Firefox, Safari and Chrome on Mac and PC
Steps to reproduce
class arrow function:
renderOption = (option)=>{
const { wi } = this.props
let sourceWi = wi
return (
// myVar1,
// myVar2,
// myVar3
<MyComponent
title={ sourceWi.title }
revIndex={ option.revIndex }
sourceWi={ sourceWi }
/>
)
}
After npm run build, this code no longer returns a component.
Expected behavior
Arrow function should return MyComponent (which works fine using dev server)
Actual behavior
After running npm run build, it appears the minifier returns nothing. Even though the return statement wraps its content in parentheses (). Perhaps it is confused by the commented variables //
I corrected the bug by creating a variable and then returning it:
renderOption = (option)=>{
const { wi } = this.props
let sourceWi = wi
const res = (
// myVar1,
// myVar2,
// myVar3
<MyComponent
title={ sourceWi.title }
revIndex={ option.revIndex }
sourceWi={ sourceWi }
/>
)
return res // NOTE returning the const res instead of the parentheses builds and runs fine
}
To reproduce the behaviour of the bug I simply return nothing instead of res. This is why I think it is a minification problem that ignores the contents inside the parentheses.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10
See also #8687
Update: see my comment here https://github.com/facebook/create-react-app/issues/8687#issuecomment-646764708