-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix local react usage in DOM fixture (#32080)
The DOM fixture hasn't worked on local builds since the UMD support was removed in #28735 Here we update the fixture to set the local experimental builds to window. Some of the pages are still broken, such as hydration. But these bugs exist on other versions as well and can be cleaned up separately.
- Loading branch information
Showing
5 changed files
with
2,150 additions
and
1,538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
import './polyfills'; | ||
import loadReact from './react-loader'; | ||
import loadReact, {isLocal} from './react-loader'; | ||
|
||
loadReact() | ||
.then(() => import('./components/App')) | ||
.then(App => { | ||
const {React, ReactDOM} = window; | ||
|
||
if (typeof window.ReactDOMClient !== 'undefined') { | ||
// we are in a React that only supports modern roots | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
React.createElement(App.default) | ||
if (isLocal()) { | ||
Promise.all([import('react'), import('react-dom/client')]) | ||
.then(([React, ReactDOMClient]) => { | ||
if (React === undefined || ReactDOMClient === undefined) { | ||
throw new Error( | ||
'Unable to load React. Build experimental and then run `yarn dev` again' | ||
); | ||
} | ||
window.React = React; | ||
window.ReactDOMClient = ReactDOMClient; | ||
}) | ||
.then(() => import('./components/App')) | ||
.then(App => { | ||
window.ReactDOMClient.createRoot(document.getElementById('root')).render( | ||
window.React.createElement(App.default) | ||
); | ||
} else { | ||
ReactDOM.render( | ||
React.createElement(App.default), | ||
document.getElementById('root') | ||
); | ||
} | ||
}); | ||
}); | ||
} else { | ||
loadReact() | ||
.then(() => import('./components/App')) | ||
.then(App => { | ||
const {React, ReactDOM} = window; | ||
if ( | ||
typeof window.ReactDOMClient !== 'undefined' && | ||
typeof window.ReactDOMClient.createRoot !== 'undefined' | ||
) { | ||
// we are in a React that only supports modern roots | ||
|
||
window.ReactDOMClient.createRoot( | ||
document.getElementById('root') | ||
).render(React.createElement(App.default)); | ||
} else { | ||
ReactDOM.render( | ||
React.createElement(App.default), | ||
document.getElementById('root') | ||
); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.