From 13cd4a4714109ba6bcae32d8b131462a0d72b298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Sat, 18 Feb 2023 03:05:04 +0100 Subject: [PATCH] fix: throw when refresh runtime is loaded twice (fix #101) --- packages/plugin-react/src/refreshUtils.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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