Skip to content

Commit

Permalink
[react-refresh] add plugin error message if setup script not run (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Sep 25, 2020
1 parent e0a2ecb commit f2dad02
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions plugins/plugin-react-refresh/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ function transformJs(contents, id) {
return `
/** React Refresh: Setup **/
if (import.meta.hot) {
var prevRefreshReg = window.$RefreshReg$;
var prevRefreshSig = window.$RefreshSig$;
window.$RefreshReg$ = (type, id) => {
window.$RefreshRuntime$.register(type, ${JSON.stringify(id)} + " " + id);
if (!window.$RefreshReg$ || !window.$RefreshSig$ || !window.$RefreshRuntime$) {
console.warn('@snowpack/plugin-react-refresh: HTML setup script not run. React Fast Refresh only works when Snowpack serves your HTML routes. You many want to remove this plugin.');
} else {
var prevRefreshReg = window.$RefreshReg$;
var prevRefreshSig = window.$RefreshSig$;
window.$RefreshReg$ = (type, id) => {
window.$RefreshRuntime$.register(type, ${JSON.stringify(id)} + " " + id);
}
window.$RefreshSig$ = window.$RefreshRuntime$.createSignatureFunctionForTransform;
}
window.$RefreshSig$ = window.$RefreshRuntime$.createSignatureFunctionForTransform;
}
${contents}
Expand Down

1 comment on commit f2dad02

@vercel
Copy link

@vercel vercel bot commented on f2dad02 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.