Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: react and react dom can load multiple times #643

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/api-server/src/util/react-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = `
}

function checkReactDom() {
if (!hasReactDom && !reactDomLoaded) {
if (!hasReactDom && !window.OpenStadReactLoaded) {

if (!reactVersion) {
reactVersion = React.version;
Expand All @@ -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) => {
Expand Down
Loading