[Float] use common float types (#26938)
Float types are currently spread out. this moves them to a single place to ensure we properly handle the public type interface in all three renderers. This is a step towards moving the public interface and validation to a common file shared by all three runtimes. Will also probably change the function interface to be flatter
Josh Story committed
Jun 13, 2023 at 13:30 UTC
7ed6084c39067e9a34a4d585e8dab2b75115cfa8
9 files changed
+34
-42
packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
+9
-18
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {HostDispatcher} from 'react-dom/src/ReactDOMDispatcher';
10
+import type {HostDispatcher} from 'react-dom/src/shared/ReactDOMTypes';
11
import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities';
12
import type {DOMEventName} from '../events/DOMEventNames';
13
import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
@@ -19,6 +19,12 @@ import type {
19
import type {ReactScopeInstance} from 'shared/ReactTypes';
20
import type {AncestorInfoDev} from './validateDOMNesting';
21
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
22
+import type {
23
+ PrefetchDNSOptions,
24
+ PreconnectOptions,
25
+ PreloadOptions,
26
+ PreinitOptions,
27
+} from 'react-dom/src/shared/ReactDOMTypes';
28
29
import {NotPending} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
30
import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostContext';
@@ -2095,7 +2101,7 @@ function preconnectAs(
2101
}
2102
}
2103
2098
-function prefetchDNS(href: string, options?: mixed) {
2104
+function prefetchDNS(href: string, options?: ?PrefetchDNSOptions) {
2105
if (!enableFloat) {
2106
return;
2107
}
@@ -2125,7 +2131,7 @@ function prefetchDNS(href: string, options?: mixed) {
2131
preconnectAs('dns-prefetch', null, href);
2132
}
2133
2128
-function preconnect(href: string, options: ?{crossOrigin?: string}) {
2134
+function preconnect(href: string, options?: ?PreconnectOptions) {
2135
if (!enableFloat) {
2136
return;
2137
}
@@ -2156,13 +2162,6 @@ function preconnect(href: string, options: ?{crossOrigin?: string}) {
2162
preconnectAs('preconnect', crossOrigin, href);
2163
}
2164
2159
-type PreloadOptions = {
2160
- as: string,
2161
- crossOrigin?: string,
2162
- integrity?: string,
2163
- type?: string,
2164
- fetchPriority?: 'high' | 'low' | 'auto',
2165
-};
2165
function preload(href: string, options: PreloadOptions) {
2166
if (!enableFloat) {
2167
return;
@@ -2238,14 +2237,6 @@ function preloadPropsFromPreloadOptions(
2237
};
2238
}
2239
2241
-type PreinitOptions = {
2242
- as: string,
2243
- precedence?: string,
2244
- crossOrigin?: string,
2245
- integrity?: string,
2246
- nonce?: string,
2247
- fetchPriority?: 'high' | 'low' | 'auto',
2248
-};
2240
function preinit(href: string, options: PreinitOptions) {
2241
if (!enableFloat) {
2242
return;
packages/react-dom-bindings/src/server/ReactDOMFlightServerHostDispatcher.js
+2
-2
@@ -13,7 +13,7 @@ import type {
13
PreconnectOptions,
14
PreloadOptions,
15
PreinitOptions,
16
-} from 'react-dom/src/ReactDOMDispatcher';
16
+} from 'react-dom/src/shared/ReactDOMTypes';
17
18
import {enableFloat} from 'shared/ReactFeatureFlags';
19
@@ -52,7 +52,7 @@ function prefetchDNS(href: string, options?: ?PrefetchDNSOptions) {
52
}
53
}
54
55
-function preconnect(href: string, options: ?PreconnectOptions) {
55
+function preconnect(href: string, options?: ?PreconnectOptions) {
56
if (enableFloat) {
57
if (typeof href === 'string') {
58
const request = resolveRequest();
packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
+8
-17
@@ -8,6 +8,12 @@
8
*/
9
10
import type {ReactNodeList, ReactCustomFormAction} from 'shared/ReactTypes';
11
+import type {
12
+ PrefetchDNSOptions,
13
+ PreconnectOptions,
14
+ PreloadOptions,
15
+ PreinitOptions,
16
+} from 'react-dom/src/shared/ReactDOMTypes';
17
18
import {
19
checkHtmlStringCoercion,
@@ -4920,7 +4926,7 @@ function getResourceKey(as: string, href: string): string {
4926
return `[${as}]${href}`;
4927
}
4928
4923
-export function prefetchDNS(href: string, options?: mixed) {
4929
+export function prefetchDNS(href: string, options?: ?PrefetchDNSOptions) {
4930
if (!enableFloat) {
4931
return;
4932
}
@@ -4979,7 +4985,7 @@ export function prefetchDNS(href: string, options?: mixed) {
4985
}
4986
}
4987
4982
-export function preconnect(href: string, options?: ?{crossOrigin?: string}) {
4988
+export function preconnect(href: string, options?: ?PreconnectOptions) {
4989
if (!enableFloat) {
4990
return;
4991
}
@@ -5042,13 +5048,6 @@ export function preconnect(href: string, options?: ?{crossOrigin?: string}) {
5048
}
5049
}
5050
5045
-type PreloadOptions = {
5046
- as: string,
5047
- crossOrigin?: string,
5048
- integrity?: string,
5049
- type?: string,
5050
- fetchPriority?: 'high' | 'low' | 'auto',
5051
-};
5051
export function preload(href: string, options: PreloadOptions) {
5052
if (!enableFloat) {
5053
return;
@@ -5187,14 +5186,6 @@ export function preload(href: string, options: PreloadOptions) {
5186
}
5187
}
5188
5190
-type PreinitOptions = {
5191
- as: string,
5192
- precedence?: string,
5193
- crossOrigin?: string,
5194
- integrity?: string,
5195
- nonce?: string,
5196
- fetchPriority?: 'high' | 'low' | 'auto',
5197
-};
5189
function preinit(href: string, options: PreinitOptions): void {
5190
if (!enableFloat) {
5191
return;
packages/react-dom-bindings/src/server/ReactFlightServerConfigDOM.js
+1
-1
@@ -12,7 +12,7 @@ import type {
12
PreconnectOptions,
13
PreloadOptions,
14
PreinitOptions,
15
-} from 'react-dom/src/ReactDOMDispatcher';
15
+} from 'react-dom/src/shared/ReactDOMTypes';
16
17
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
18
const ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
packages/react-dom/src/ReactDOMSharedInternals.js
+1
-1
@@ -7,7 +7,7 @@
7
* @flow
8
*/
9
10
-import type {HostDispatcher} from './ReactDOMDispatcher';
10
+import type {HostDispatcher} from './shared/ReactDOMTypes';
11
12
type InternalsType = {
13
usingClientEntryPoint: boolean,
packages/react-dom/src/client/ReactDOM.js
+6
-1
@@ -55,7 +55,12 @@ import {
55
} from 'react-dom-bindings/src/events/ReactDOMControlledComponent';
56
import Internals from '../ReactDOMSharedInternals';
57
58
-export {prefetchDNS, preconnect, preload, preinit} from '../ReactDOMFloat';
58
+export {
59
+ prefetchDNS,
60
+ preconnect,
61
+ preload,
62
+ preinit,
63
+} from '../shared/ReactDOMFloat';
64
export {useFormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
65
66
if (__DEV__) {
packages/react-dom/src/server/ReactDOMServerRenderingStub.js
+6
-1
@@ -7,7 +7,12 @@
7
* @flow
8
*/
9
10
-export {preinit, preload, preconnect, prefetchDNS} from '../ReactDOMFloat';
10
+export {
11
+ preinit,
12
+ preload,
13
+ preconnect,
14
+ prefetchDNS,
15
+} from '../shared/ReactDOMFloat';
16
export {useFormStatus as experimental_useFormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
17
18
export function createPortal() {
packages/react-dom/src/shared/ReactDOMFloat.js
renamed
+1
-1
@@ -10,7 +10,7 @@ import type {
10
PreconnectOptions,
11
PreloadOptions,
12
PreinitOptions,
13
-} from './ReactDOMDispatcher';
13
+} from './ReactDOMTypes';
14
15
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
16
const Dispatcher = ReactDOMSharedInternals.Dispatcher;