Skip to content

Commit 6093f18

Browse files
authored
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.
1 parent 89dbd48 commit 6093f18

File tree

5 files changed

+2150
-1538
lines changed

5 files changed

+2150
-1538
lines changed

.github/workflows/runtime_build_and_test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ jobs:
416416
- name: Ensure clean build directory
417417
run: rm -rf build
418418
- run: yarn install --frozen-lockfile
419-
- run: yarn install --frozen-lockfile --cache-folder ~/.cache/yarn
420419
working-directory: fixtures/dom
421420
- name: Restore archived build
422421
uses: actions/download-artifact@v4

fixtures/dom/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"jest-diff": "^29.4.1",
1515
"prop-types": "^15.6.0",
1616
"query-string": "^4.2.3",
17-
"react": "^15.4.1",
18-
"react-dom": "^15.4.1",
17+
"react": "^19.0.0",
18+
"react-dom": "^19.0.0",
1919
"semver": "^5.5.0"
2020
},
2121
"scripts": {
2222
"dev": "react-scripts start",
23-
"predev": "cp -a ../../build/oss-stable/. node_modules",
23+
"predev": "cp -a ../../build/oss-experimental/. node_modules",
2424
"build": "react-scripts build && cp build/index.html build/200.html",
2525
"test": "react-scripts test --env=jsdom",
2626
"eject": "react-scripts eject"

fixtures/dom/src/index.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
import './polyfills';
2-
import loadReact from './react-loader';
2+
import loadReact, {isLocal} from './react-loader';
33

4-
loadReact()
5-
.then(() => import('./components/App'))
6-
.then(App => {
7-
const {React, ReactDOM} = window;
8-
9-
if (typeof window.ReactDOMClient !== 'undefined') {
10-
// we are in a React that only supports modern roots
11-
12-
ReactDOM.createRoot(document.getElementById('root')).render(
13-
React.createElement(App.default)
4+
if (isLocal()) {
5+
Promise.all([import('react'), import('react-dom/client')])
6+
.then(([React, ReactDOMClient]) => {
7+
if (React === undefined || ReactDOMClient === undefined) {
8+
throw new Error(
9+
'Unable to load React. Build experimental and then run `yarn dev` again'
10+
);
11+
}
12+
window.React = React;
13+
window.ReactDOMClient = ReactDOMClient;
14+
})
15+
.then(() => import('./components/App'))
16+
.then(App => {
17+
window.ReactDOMClient.createRoot(document.getElementById('root')).render(
18+
window.React.createElement(App.default)
1419
);
15-
} else {
16-
ReactDOM.render(
17-
React.createElement(App.default),
18-
document.getElementById('root')
19-
);
20-
}
21-
});
20+
});
21+
} else {
22+
loadReact()
23+
.then(() => import('./components/App'))
24+
.then(App => {
25+
const {React, ReactDOM} = window;
26+
if (
27+
typeof window.ReactDOMClient !== 'undefined' &&
28+
typeof window.ReactDOMClient.createRoot !== 'undefined'
29+
) {
30+
// we are in a React that only supports modern roots
31+
32+
window.ReactDOMClient.createRoot(
33+
document.getElementById('root')
34+
).render(React.createElement(App.default));
35+
} else {
36+
ReactDOM.render(
37+
React.createElement(App.default),
38+
document.getElementById('root')
39+
);
40+
}
41+
});
42+
}

fixtures/dom/src/react-loader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function getVersion() {
6868
return query.version || 'local';
6969
}
7070

71+
export function isLocal() {
72+
return getVersion() === 'local';
73+
}
74+
7175
export function reactPaths(version = getVersion()) {
7276
let query = parseQuery(window.location.search);
7377
let isProduction = query.production === 'true';

0 commit comments

Comments
 (0)