Skip to content

Commit d28a9d0

Browse files
authored
fix(react-refresh): lazily access module.exports to prevent unexpected/potential TDZ error (#2714)
* fix(react-refresh): lazily access module.exports to prevent unexpected/potential TDZ error * comment * Changeset
1 parent 9822cef commit d28a9d0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/pretty-rocks-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rspack/binding": patch
3+
---
4+
5+
fix(react-refresh): lazily access module.exports to prevent unexpected/potential TDZ error

crates/rspack_plugin_javascript/src/visitors/swc_visitor/react.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ var $RefreshReg$ = function (type, id) {
6868
}
6969
var $RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;"#;
7070

71-
static HMR_FOOTER: &str =
72-
r#"__webpack_modules__.$ReactRefreshRuntime$.refresh(__webpack_module__.id, module.hot);"#;
71+
// See https://github.com/web-infra-dev/rspack/pull/2714 why we have a promise here
72+
static HMR_FOOTER: &str = r#"Promise.resolve().then(function(){
73+
__webpack_modules__.$ReactRefreshRuntime$.refresh(__webpack_module__.id, module.hot);
74+
})"#;
7375

7476
static HMR_HEADER_AST: Lazy<Program> =
7577
Lazy::new(|| parse_js_code(HMR_HEADER.to_string(), &ModuleType::Js).expect("TODO:"));

0 commit comments

Comments
 (0)