From 649225e0f24646d2e9515ab7353cc36744b08972 Mon Sep 17 00:00:00 2001 From: Rudi van Hierden Date: Wed, 16 Oct 2024 09:56:07 +0200 Subject: [PATCH] fix: react and react dom can load multiple times --- apps/api-server/src/util/react-check.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/api-server/src/util/react-check.js b/apps/api-server/src/util/react-check.js index 1e69454f5..35067a37a 100644 --- a/apps/api-server/src/util/react-check.js +++ b/apps/api-server/src/util/react-check.js @@ -11,7 +11,7 @@ module.exports = ` } function checkReactDom() { - if (!hasReactDom && !reactDomLoaded) { + if (!hasReactDom && !window.OpenStadReactLoaded) { if (!reactVersion) { reactVersion = React.version; @@ -34,24 +34,24 @@ module.exports = ` triggerEvent(); } document.body.appendChild(script); + window.OpenStadReactDOMLoaded = true; } else if ( typeof ReactDOM !== 'undefined' && ReactDOM.version.substr(0, 2) !== '18' ) { throw new Error('ReactDOM version 18 is required'); } else { + window.OpenStadReactDOMLoaded = true; document.addEventListener('OpenStadReactLoaded', renderWidget); triggerEvent(); } } const hasReact = typeof React !== 'undefined'; - const reactLoaded = window.OpenStadReactLoaded; const hasReactDom = typeof ReactDOM !== 'undefined'; - const reactDomLoaded = window.OSReactDomLoaded; let reactVersion = hasReact ? React.version : ''; - if (!hasReact && !reactLoaded) { + if (!hasReact && !window.OpenStadReactLoaded) { const script = document.createElement('script'); script.src = '${reactJs}'; script.onload = (e) => {