Skip to content

Commit

Permalink
[Float] use common float types (facebook#26938)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gnoff authored and AndyPengc12 committed Apr 15, 2024
1 parent 6af7037 commit acc8609
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 42 deletions.
27 changes: 9 additions & 18 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {HostDispatcher} from 'react-dom/src/ReactDOMDispatcher';
import type {HostDispatcher} from 'react-dom/src/shared/ReactDOMTypes';
import type {EventPriority} from 'react-reconciler/src/ReactEventPriorities';
import type {DOMEventName} from '../events/DOMEventNames';
import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
Expand All @@ -19,6 +19,12 @@ import type {
import type {ReactScopeInstance} from 'shared/ReactTypes';
import type {AncestorInfoDev} from './validateDOMNesting';
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
import type {
PrefetchDNSOptions,
PreconnectOptions,
PreloadOptions,
PreinitOptions,
} from 'react-dom/src/shared/ReactDOMTypes';

import {NotPending} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostContext';
Expand Down Expand Up @@ -2095,7 +2101,7 @@ function preconnectAs(
}
}

function prefetchDNS(href: string, options?: mixed) {
function prefetchDNS(href: string, options?: ?PrefetchDNSOptions) {
if (!enableFloat) {
return;
}
Expand Down Expand Up @@ -2125,7 +2131,7 @@ function prefetchDNS(href: string, options?: mixed) {
preconnectAs('dns-prefetch', null, href);
}

function preconnect(href: string, options: ?{crossOrigin?: string}) {
function preconnect(href: string, options?: ?PreconnectOptions) {
if (!enableFloat) {
return;
}
Expand Down Expand Up @@ -2156,13 +2162,6 @@ function preconnect(href: string, options: ?{crossOrigin?: string}) {
preconnectAs('preconnect', crossOrigin, href);
}

type PreloadOptions = {
as: string,
crossOrigin?: string,
integrity?: string,
type?: string,
fetchPriority?: 'high' | 'low' | 'auto',
};
function preload(href: string, options: PreloadOptions) {
if (!enableFloat) {
return;
Expand Down Expand Up @@ -2238,14 +2237,6 @@ function preloadPropsFromPreloadOptions(
};
}

type PreinitOptions = {
as: string,
precedence?: string,
crossOrigin?: string,
integrity?: string,
nonce?: string,
fetchPriority?: 'high' | 'low' | 'auto',
};
function preinit(href: string, options: PreinitOptions) {
if (!enableFloat) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
PreconnectOptions,
PreloadOptions,
PreinitOptions,
} from 'react-dom/src/ReactDOMDispatcher';
} from 'react-dom/src/shared/ReactDOMTypes';

import {enableFloat} from 'shared/ReactFeatureFlags';

Expand Down Expand Up @@ -52,7 +52,7 @@ function prefetchDNS(href: string, options?: ?PrefetchDNSOptions) {
}
}

function preconnect(href: string, options: ?PreconnectOptions) {
function preconnect(href: string, options?: ?PreconnectOptions) {
if (enableFloat) {
if (typeof href === 'string') {
const request = resolveRequest();
Expand Down
25 changes: 8 additions & 17 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
*/

import type {ReactNodeList, ReactCustomFormAction} from 'shared/ReactTypes';
import type {
PrefetchDNSOptions,
PreconnectOptions,
PreloadOptions,
PreinitOptions,
} from 'react-dom/src/shared/ReactDOMTypes';

import {
checkHtmlStringCoercion,
Expand Down Expand Up @@ -4920,7 +4926,7 @@ function getResourceKey(as: string, href: string): string {
return `[${as}]${href}`;
}

export function prefetchDNS(href: string, options?: mixed) {
export function prefetchDNS(href: string, options?: ?PrefetchDNSOptions) {
if (!enableFloat) {
return;
}
Expand Down Expand Up @@ -4979,7 +4985,7 @@ export function prefetchDNS(href: string, options?: mixed) {
}
}

export function preconnect(href: string, options?: ?{crossOrigin?: string}) {
export function preconnect(href: string, options?: ?PreconnectOptions) {
if (!enableFloat) {
return;
}
Expand Down Expand Up @@ -5042,13 +5048,6 @@ export function preconnect(href: string, options?: ?{crossOrigin?: string}) {
}
}

type PreloadOptions = {
as: string,
crossOrigin?: string,
integrity?: string,
type?: string,
fetchPriority?: 'high' | 'low' | 'auto',
};
export function preload(href: string, options: PreloadOptions) {
if (!enableFloat) {
return;
Expand Down Expand Up @@ -5187,14 +5186,6 @@ export function preload(href: string, options: PreloadOptions) {
}
}

type PreinitOptions = {
as: string,
precedence?: string,
crossOrigin?: string,
integrity?: string,
nonce?: string,
fetchPriority?: 'high' | 'low' | 'auto',
};
function preinit(href: string, options: PreinitOptions): void {
if (!enableFloat) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
PreconnectOptions,
PreloadOptions,
PreinitOptions,
} from 'react-dom/src/ReactDOMDispatcher';
} from 'react-dom/src/shared/ReactDOMTypes';

import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
const ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/ReactDOMSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {HostDispatcher} from './ReactDOMDispatcher';
import type {HostDispatcher} from './shared/ReactDOMTypes';

type InternalsType = {
usingClientEntryPoint: boolean,
Expand Down
7 changes: 6 additions & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ import {
} from 'react-dom-bindings/src/events/ReactDOMControlledComponent';
import Internals from '../ReactDOMSharedInternals';

export {prefetchDNS, preconnect, preload, preinit} from '../ReactDOMFloat';
export {
prefetchDNS,
preconnect,
preload,
preinit,
} from '../shared/ReactDOMFloat';
export {useFormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';

if (__DEV__) {
Expand Down
7 changes: 6 additions & 1 deletion packages/react-dom/src/server/ReactDOMServerRenderingStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
* @flow
*/

export {preinit, preload, preconnect, prefetchDNS} from '../ReactDOMFloat';
export {
preinit,
preload,
preconnect,
prefetchDNS,
} from '../shared/ReactDOMFloat';
export {useFormStatus as experimental_useFormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';

export function createPortal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
PreconnectOptions,
PreloadOptions,
PreinitOptions,
} from './ReactDOMDispatcher';
} from './ReactDOMTypes';

import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
const Dispatcher = ReactDOMSharedInternals.Dispatcher;
Expand Down

0 comments on commit acc8609

Please sign in to comment.