Skip to content

Commit c493666

Browse files
gnoffUmeshmalik
authored andcommitted
react-dom/server-rendering-stub: restore experimental prefix for useFormState and useFormStatus (facebook#27470)
in facebook#27461 the experimental prefix was added back for `useFormState` and `useFormStatus` in react-dom. However these functions are also exported from the server rendering stub too and when using the stub with experimental prefixes their absence causes unexpected errors. This change adds back the experimental prefix for these two hooks to match the experimental build of react-dom.
1 parent 16619f1 commit c493666

File tree

15 files changed

+476
-382
lines changed

15 files changed

+476
-382
lines changed

fixtures/concurrent/time-slicing/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
npm-debug.log*
2020
yarn-debug.log*
2121
yarn-error.log*
22+
yarn.lock
+15-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
{
22
"name": "cpu-demo",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"private": true,
55
"dependencies": {
6-
"glamor": "^2.20.40",
76
"react": "0.0.0-experimental-269dd6ec5",
87
"react-dom": "0.0.0-experimental-269dd6ec5",
9-
"react-markdown": "^3.2.0",
10-
"react-scripts": "^1.1.4",
11-
"victory": "^0.25.6"
8+
"react-scripts": "^5.0.1",
9+
"victory": "^36.0.0"
1210
},
1311
"scripts": {
1412
"copy-source": "cp -r ../../../build/oss-experimental/* ./node_modules/",
1513
"dev": "react-scripts start",
1614
"build": "react-scripts build",
1715
"test": "react-scripts test --env=jsdom",
1816
"eject": "react-scripts eject"
17+
},
18+
"browserslist": {
19+
"production": [
20+
">0.2%",
21+
"not dead",
22+
"not op_mini all"
23+
],
24+
"development": [
25+
"last 1 chrome version",
26+
"last 1 firefox version",
27+
"last 1 safari version"
28+
]
1929
}
2030
}

fixtures/concurrent/time-slicing/public/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
66
<meta name="theme-color" content="#000000">
7+
<meta name="description" content="Shows use of sync, debounce, async computation in react">
78
<!--
89
manifest.json provides metadata used when your web app is added to the
910
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import React, { useEffect, useState, useTransition } from "react";
2+
3+
import _map from "lodash/map";
4+
import _debounce from "lodash/debounce";
5+
6+
import { Charts, Clock, Options } from "./components";
7+
8+
import { getStreamData } from "./utils";
9+
import { OPTIONS, INITIAL_STATE, STRATEGY, QUESTION_MARK } from "./constants";
10+
11+
import "./index.css";
12+
13+
let _ignoreClick = null;
14+
15+
const App = () => {
16+
const [showDemo, setShowDemo] = useState(INITIAL_STATE.showDemo);
17+
const [strategy, setStrategy] = useState(INITIAL_STATE.strategy);
18+
const [value, setValue] = useState(INITIAL_STATE.value);
19+
const [showClock, setShowClock] = useState(INITIAL_STATE.showClock);
20+
const [isPending, startTransition] = useTransition();
21+
22+
useEffect(() => {
23+
window.addEventListener("keydown", showClockEventHandler);
24+
return () => {
25+
window.removeEventListener("keydown", showClockEventHandler);
26+
};
27+
}, []);
28+
29+
const showClockEventHandler = (e) => {
30+
if (e.key.toLowerCase() === QUESTION_MARK) {
31+
e.preventDefault();
32+
setShowClock((prev) => !prev);
33+
}
34+
};
35+
36+
const handleChartClick = (e) => {
37+
if (showDemo) {
38+
if (e.shiftKey) {
39+
setShowDemo(false);
40+
}
41+
return;
42+
}
43+
if (strategy !== STRATEGY.ASYNC) {
44+
setShowDemo((prev) => !prev);
45+
return;
46+
}
47+
if (_ignoreClick) {
48+
return;
49+
}
50+
_ignoreClick = true;
51+
52+
startTransition(() => {
53+
setShowDemo(true);
54+
_ignoreClick = false;
55+
});
56+
};
57+
58+
const handleChange = (e) => {
59+
const val = e.target.value;
60+
switch (strategy) {
61+
case STRATEGY.SYNC:
62+
setValue(val);
63+
break;
64+
case STRATEGY.DEBOUNCED:
65+
debouncedHandleChange(val);
66+
break;
67+
case STRATEGY.ASYNC:
68+
startTransition(() => {
69+
setValue(val);
70+
});
71+
break;
72+
default:
73+
break;
74+
}
75+
};
76+
77+
const debouncedHandleChange = _debounce((val) => {
78+
if (strategy === STRATEGY.DEBOUNCED) {
79+
setValue(val);
80+
}
81+
}, 1000);
82+
83+
return (
84+
<div className="container">
85+
<div className="rendering">
86+
{_map(OPTIONS, (option) => (
87+
<Options
88+
{...option}
89+
key={option.strategy}
90+
setStrategy={setStrategy}
91+
currentStrategy={strategy}
92+
/>
93+
))}
94+
</div>
95+
<input
96+
className={"input " + strategy}
97+
id="input"
98+
placeholder="longer input → more components and DOM nodes"
99+
defaultValue={value}
100+
onChange={handleChange}
101+
/>
102+
<div className="demo" onClick={handleChartClick}>
103+
{showDemo && (
104+
<Charts data={getStreamData(value)} isPending={isPending} />
105+
)}
106+
{showClock && <Clock />}
107+
</div>
108+
</div>
109+
);
110+
};
111+
112+
export default App;

fixtures/concurrent/time-slicing/src/Charts.js

-126
This file was deleted.

fixtures/concurrent/time-slicing/src/Clock.js

-105
This file was deleted.

0 commit comments

Comments
 (0)