fix(react-swc): don't apply React Refresh wrapper for non JSX files#1226
fix(react-swc): don't apply React Refresh wrapper for non JSX files#1226ArnaudBarre wants to merge 1 commit into
Conversation
|
@sapphi-red I'm wondering if for the rolldown builtin refresh wrapper you access the ast and do something like: let only_react_comp =
!has_refresh &&
// pseudo JS code
ast.body.statements.some(
(s) =>
s.kind === 'ClassDeclaration' &&
s.extends.name.match(/^(?:React\.)?(?:Pure)?Component$/),
) |
|
I guess we can also fix the error by changing this |
It doesn't have access to the AST here since the |
For the past years I've found benefits to keep using window there because it allowed to find cases with bad configuration or people over bundling files in their workers. The idea was also that if one day we figure out HMR for workers, it will not be a breaking change currently the client can't run there. But maybe the chance is so low that we get there that we should make it no-op to load the HMR client in a worker |
|
Fixes #1225
Given that SWC already enable fast refresh only for
jsx: trueand that since this plugin was not running on.js, this feel a good and safe change. This could be a breaking change in this unlikely set of circumstances:jsx_dev()parserConfigto(id) => id.endsWith(".ext") ? ({ syntax: 'ecmascript', jsx: false }) : nullIn that case hmr will go back to page reload. Changing to
jsx: truewill give back the previous behaviour