You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using @rspack/plugin-preact-refresh with Preact in development mode, I encountered an issue where both $RefreshSig$ and $RefreshReg$ become undefined during hot reload. This causes a runtime error: TypeError: $RefreshSig$ is not a function.
Root Cause
In node_modules/@rspack/plugin-preact-refresh/client/intercept.js, the code captures previous values of these functions and restores them in a finally block:
try{originalFactory.call(this,moduleObject,moduleExports,webpackRequire);}finally{self.$RefreshReg$=prevRefreshReg;self.$RefreshSig$=prevRefreshSig;// This can set it to undefined}
When the first module (@prefresh/core/src/index.js) is loaded, prevRefreshSig and prevRefreshReg are both undefined. After the finally block executes, it sets the global functions back to undefined, breaking the hot reload functionality.
Steps to Reproduce
Create a Preact application with Rspack
Configure @rspack/plugin-preact-refresh and @prefresh/babel-plugin
Run the application in development mode
Check the browser console for errors during component updates
Observe the error: TypeError: $RefreshSig$ is not a function
Solution
The issue can be fixed by adding a null check before restoring the previous functions:
try{originalFactory.call(this,moduleObject,moduleExports,webpackRequire);}finally{// Only restore if previous values are definedif(prevRefreshReg!==undefined){self.$RefreshReg$=prevRefreshReg;}if(prevRefreshSig!==undefined){self.$RefreshSig$=prevRefreshSig;}}
Environment
Rspack version: 1.2.8
@rspack/plugin-preact-refresh version: 1.1.2
@prefresh/babel-plugin version: 0.5.1
The text was updated successfully, but these errors were encountered:
Issue Description
When using
@rspack/plugin-preact-refresh
with Preact in development mode, I encountered an issue where both$RefreshSig$
and$RefreshReg$
becomeundefined
during hot reload. This causes a runtime error:TypeError: $RefreshSig$ is not a function
.Root Cause
In
node_modules/@rspack/plugin-preact-refresh/client/intercept.js
, the code captures previous values of these functions and restores them in afinally
block:When the first module (
@prefresh/core/src/index.js
) is loaded,prevRefreshSig
andprevRefreshReg
are bothundefined
. After thefinally
block executes, it sets the global functions back toundefined
, breaking the hot reload functionality.Steps to Reproduce
@rspack/plugin-preact-refresh
and@prefresh/babel-plugin
TypeError: $RefreshSig$ is not a function
Solution
The issue can be fixed by adding a null check before restoring the previous functions:
Environment
The text was updated successfully, but these errors were encountered: