diff --git a/packages/plugin-react/src/refreshUtils.js b/packages/plugin-react/src/refreshUtils.js index 65e4d5af..11340c81 100644 --- a/packages/plugin-react/src/refreshUtils.js +++ b/packages/plugin-react/src/refreshUtils.js @@ -1,3 +1,13 @@ +/* eslint-disable no-undef */ +if (typeof window !== 'undefined') { + if (window.__vite_plugin_react_runtime_loaded__) { + throw new Error( + 'React refresh runtime was loaded twice. Maybe you forgot the base path?', + ) + } + window.__vite_plugin_react_runtime_loaded__ = true +} + function debounce(fn, delay) { let handle return () => { @@ -6,7 +16,6 @@ function debounce(fn, delay) { } } -/* eslint-disable no-undef */ const enqueueUpdate = debounce(exports.performReactRefresh, 16) // Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141