diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
index e8e7dffee5..080bc04734 100644
--- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
@@ -11,7 +11,6 @@ let React;
let ReactDOMClient;
let ReactDOMServer;
let act;
-let usingPartialRenderer;
const util = require('util');
const realConsoleError = console.error;
@@ -26,8 +25,6 @@ describe('ReactDOMServerHydration', () => {
ReactDOMServer = require('react-dom/server');
act = require('react-dom/test-utils').act;
- usingPartialRenderer = global.__WWW__ && !__EXPERIMENTAL__;
-
console.error = jest.fn();
container = document.createElement('div');
document.body.appendChild(container);
@@ -731,15 +728,13 @@ describe('ReactDOMServerHydration', () => {
);
}
- // @TODO FB bundles use a different renderer that does not serialize errors to the client
- const mismatchEl = usingPartialRenderer ? '
' : '';
// @TODO changes made to sending Fizz errors to client led to the insertion of templates in client rendered
// suspense boundaries. This leaks in this test becuase the client rendered suspense boundary appears like
// unhydrated tail nodes and this template is the first match. When we add special case handling for client
// rendered suspense boundaries this test will likely change again
expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
- "Warning: Did not expect server HTML to contain a ${mismatchEl} in
.
+ "Warning: Did not expect server HTML to contain a in
.
in div (at **)
in Mismatch (at **)",
"Warning: An error occurred during hydration. The server HTML was replaced with client content in
);
}
- // We gate this assertion becuase fb-classic uses PartialRenderer for renderToString and it does not
- // serialize server errors and send to client
- if (usingPartialRenderer) {
- expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
- Array [
- "Caught [The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.]",
- ]
- `);
- } else {
- expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
+
+ expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
- }
});
// @gate __DEV__
@@ -854,21 +840,12 @@ describe('ReactDOMServerHydration', () => {
);
}
- // We gate this assertion becuase fb-classic uses PartialRenderer for renderToString and it does not
- // serialize server errors and send to client
- if (usingPartialRenderer) {
- expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
- Array [
- "Caught [The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.]",
- ]
- `);
- } else {
- expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
+
+ expect(testMismatch(Mismatch)).toMatchInlineSnapshot(`
Array [
"Caught [The server did not finish this Suspense boundary: The server used \\"renderToString\\" which does not support Suspense. If you intended for this Suspense boundary to render the fallback content on the server consider throwing an Error somewhere within the Suspense boundary. If you intended to have the server wait for the suspended component please switch to \\"renderToPipeableStream\\" which supports Suspense on the server]",
]
`);
- }
});
});
diff --git a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
index e086448d69..c8a44764d7 100644
--- a/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
+++ b/packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js
@@ -19,7 +19,6 @@ let Suspense;
let SuspenseList;
let act;
let IdleEventPriority;
-let usingPartialRenderer;
function normalizeCodeLocInfo(strOrErr) {
if (strOrErr && strOrErr.replace) {
@@ -111,8 +110,6 @@ describe('ReactDOMServerPartialHydration', () => {
SuspenseList = React.SuspenseList;
}
- usingPartialRenderer = global.__WWW__ && !__EXPERIMENTAL__;
-
IdleEventPriority = require('react-reconciler/constants').IdleEventPriority;
});
@@ -1671,8 +1668,7 @@ describe('ReactDOMServerPartialHydration', () => {
Scheduler.unstable_yieldValue(error.message);
},
});
- // we exclude fb bundles with partial renderer
- if (__DEV__ && !usingPartialRenderer) {
+ if (__DEV__) {
expect(Scheduler).toFlushAndYield([
'The server did not finish this Suspense boundary: The server used' +
' "renderToString" which does not support Suspense. If you intended' +
@@ -1745,8 +1741,7 @@ describe('ReactDOMServerPartialHydration', () => {
Scheduler.unstable_yieldValue(error.message);
},
});
- // we exclude fb bundles with partial renderer
- if (__DEV__ && !usingPartialRenderer) {
+ if (__DEV__) {
expect(Scheduler).toFlushAndYield([
'The server did not finish this Suspense boundary: The server used' +
' "renderToString" which does not support Suspense. If you intended' +
@@ -1824,8 +1819,7 @@ describe('ReactDOMServerPartialHydration', () => {
Scheduler.unstable_yieldValue(error.message);
},
});
- // we exclude fb bundles with partial renderer
- if (__DEV__ && !usingPartialRenderer) {
+ if (__DEV__) {
expect(Scheduler).toFlushAndYield([
'The server did not finish this Suspense boundary: The server used' +
' "renderToString" which does not support Suspense. If you intended' +
@@ -2154,8 +2148,7 @@ describe('ReactDOMServerPartialHydration', () => {
});
suspend = true;
- // we exclude fb bundles with partial renderer
- if (__DEV__ && !usingPartialRenderer) {
+ if (__DEV__) {
expect(Scheduler).toFlushAndYield([
'The server did not finish this Suspense boundary: The server used' +
' "renderToString" which does not support Suspense. If you intended' +
@@ -2229,8 +2222,7 @@ describe('ReactDOMServerPartialHydration', () => {
Scheduler.unstable_yieldValue(error.message);
},
});
- // we exclude fb bundles with partial renderer
- if (__DEV__ && !usingPartialRenderer) {
+ if (__DEV__) {
expect(Scheduler).toFlushAndYield([
'The server did not finish this Suspense boundary: The server used' +
' "renderToString" which does not support Suspense. If you intended' +
diff --git a/packages/react-dom/src/__tests__/ReactServerRendering-test.js b/packages/react-dom/src/__tests__/ReactServerRendering-test.js
index fed6988077..c22846fa63 100644
--- a/packages/react-dom/src/__tests__/ReactServerRendering-test.js
+++ b/packages/react-dom/src/__tests__/ReactServerRendering-test.js
@@ -14,7 +14,6 @@ let React;
let ReactDOMServer;
let PropTypes;
let ReactCurrentDispatcher;
-let useingPartialRenderer;
describe('ReactDOMServer', () => {
beforeEach(() => {
@@ -25,8 +24,6 @@ describe('ReactDOMServer', () => {
ReactCurrentDispatcher =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.ReactCurrentDispatcher;
-
- useingPartialRenderer = global.__WWW__ && !__EXPERIMENTAL__;
});
describe('renderToString', () => {
@@ -576,11 +573,7 @@ describe('ReactDOMServer', () => {
,
);
- if (useingPartialRenderer) {
- expect(response).toEqual('fallback');
- } else {
- expect(response).toEqual('fallback');
- }
+ expect(response).toEqual('fallback');
});
});
diff --git a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
index 4cf2b7336e..663cce63c5 100644
--- a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
+++ b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
@@ -603,7 +603,6 @@ describe('ReactDOMServerHydration', () => {
expect(customElement.obj).toBe(undefined);
});
- // @gate experimental || !www || !__DEV__
it('refers users to apis that support Suspense when something suspends', () => {
const theInfinitePromise = new Promise(() => {});
function InfiniteSuspend() {
@@ -649,7 +648,6 @@ describe('ReactDOMServerHydration', () => {
}
});
- // @gate experimental || !www || !__DEV__
it('refers users to apis that support Suspense when something suspends (browser)', () => {
const theInfinitePromise = new Promise(() => {});
function InfiniteSuspend() {
diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.classic.fb.js b/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.classic.fb.js
deleted file mode 100644
index 26ade81441..0000000000
--- a/packages/react-dom/src/server/ReactDOMLegacyServerBrowser.classic.fb.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @flow
- */
-
-export {
- renderToString,
- renderToStaticMarkup,
- renderToNodeStream,
- renderToStaticNodeStream,
- version,
-} from './ReactDOMServerLegacyPartialRendererBrowser';
diff --git a/packages/react-dom/src/server/ReactDOMLegacyServerNode.classic.fb.js b/packages/react-dom/src/server/ReactDOMLegacyServerNode.classic.fb.js
deleted file mode 100644
index f542d77e29..0000000000
--- a/packages/react-dom/src/server/ReactDOMLegacyServerNode.classic.fb.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @flow
- */
-
-export {
- renderToString,
- renderToStaticMarkup,
- version,
-} from './ReactDOMServerLegacyPartialRendererBrowser';
-
-export {
- renderToNodeStream,
- renderToStaticNodeStream,
-} from './ReactDOMLegacyServerNodeStream';
diff --git a/packages/react-dom/src/server/ReactDOMServerLegacyPartialRendererBrowser.js b/packages/react-dom/src/server/ReactDOMServerLegacyPartialRendererBrowser.js
deleted file mode 100644
index f810d7472b..0000000000
--- a/packages/react-dom/src/server/ReactDOMServerLegacyPartialRendererBrowser.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-import ReactVersion from 'shared/ReactVersion';
-
-import {renderToString, renderToStaticMarkup} from './ReactDOMStringRenderer';
-
-function renderToNodeStream() {
- throw new Error(
- 'ReactDOMServer.renderToNodeStream(): The streaming API is not available ' +
- 'in the browser. Use ReactDOMServer.renderToString() instead.',
- );
-}
-
-function renderToStaticNodeStream() {
- throw new Error(
- 'ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available ' +
- 'in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.',
- );
-}
-
-export {
- renderToString,
- renderToStaticMarkup,
- renderToNodeStream,
- renderToStaticNodeStream,
- ReactVersion as version,
-};
diff --git a/packages/react-dom/src/server/ReactDOMStringRenderer.js b/packages/react-dom/src/server/ReactDOMStringRenderer.js
deleted file mode 100644
index f2dbb68648..0000000000
--- a/packages/react-dom/src/server/ReactDOMStringRenderer.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-import type {ServerOptions} from './ReactPartialRenderer';
-import ReactPartialRenderer from './ReactPartialRenderer';
-
-/**
- * Render a ReactElement to its initial HTML. This should only be used on the
- * server.
- * See https://reactjs.org/docs/react-dom-server.html#rendertostring
- */
-export function renderToString(element, options?: ServerOptions) {
- const renderer = new ReactPartialRenderer(element, false, options);
- try {
- const markup = renderer.read(Infinity);
- return markup;
- } finally {
- renderer.destroy();
- }
-}
-
-/**
- * Similar to renderToString, except this doesn't create extra DOM attributes
- * such as data-react-id that React uses internally.
- * See https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup
- */
-export function renderToStaticMarkup(element, options?: ServerOptions) {
- const renderer = new ReactPartialRenderer(element, true, options);
- try {
- const markup = renderer.read(Infinity);
- return markup;
- } finally {
- renderer.destroy();
- }
-}
diff --git a/packages/react-dom/src/server/ReactPartialRenderer.js b/packages/react-dom/src/server/ReactPartialRenderer.js
deleted file mode 100644
index 03f5355ef0..0000000000
--- a/packages/react-dom/src/server/ReactPartialRenderer.js
+++ /dev/null
@@ -1,1646 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @flow
- */
-
-import type {ThreadID} from './ReactThreadIDAllocator';
-import type {ReactElement} from 'shared/ReactElementType';
-import type {LazyComponent} from 'react/src/ReactLazy';
-import type {ReactProvider, ReactContext} from 'shared/ReactTypes';
-
-import * as React from 'react';
-import isArray from 'shared/isArray';
-import getComponentNameFromType from 'shared/getComponentNameFromType';
-import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
-import ReactSharedInternals from 'shared/ReactSharedInternals';
-import {
- warnAboutDeprecatedLifecycles,
- disableLegacyContext,
- disableModulePatternComponents,
- enableScopeAPI,
-} from 'shared/ReactFeatureFlags';
-import {
- checkPropStringCoercion,
- checkFormFieldValueStringCoercion,
-} from 'shared/CheckStringCoercion';
-
-import {
- REACT_DEBUG_TRACING_MODE_TYPE,
- REACT_FORWARD_REF_TYPE,
- REACT_FRAGMENT_TYPE,
- REACT_STRICT_MODE_TYPE,
- REACT_SUSPENSE_TYPE,
- REACT_SUSPENSE_LIST_TYPE,
- REACT_PORTAL_TYPE,
- REACT_PROFILER_TYPE,
- REACT_PROVIDER_TYPE,
- REACT_CONTEXT_TYPE,
- REACT_LAZY_TYPE,
- REACT_MEMO_TYPE,
- REACT_SCOPE_TYPE,
- REACT_LEGACY_HIDDEN_TYPE,
-} from 'shared/ReactSymbols';
-
-import {
- emptyObject,
- processContext,
- validateContextBounds,
-} from './ReactPartialRendererContext';
-import {allocThreadID, freeThreadID} from './ReactThreadIDAllocator';
-import {
- createMarkupForCustomAttribute,
- createMarkupForProperty,
-} from './DOMMarkupOperations';
-import escapeTextForBrowser from './escapeTextForBrowser';
-import {
- prepareToUseHooks,
- finishHooks,
- resetHooksState,
- Dispatcher,
- currentPartialRenderer,
- setCurrentPartialRenderer,
-} from './ReactPartialRendererHooks';
-import {
- HTML_NAMESPACE,
- getIntrinsicNamespace,
- getChildNamespace,
-} from '../shared/DOMNamespaces';
-import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
-import assertValidProps from '../shared/assertValidProps';
-import dangerousStyleValue from '../shared/dangerousStyleValue';
-import hyphenateStyleName from '../shared/hyphenateStyleName';
-import isCustomComponentFn from '../shared/isCustomComponent';
-import omittedCloseTags from '../shared/omittedCloseTags';
-import warnValidStyle from '../shared/warnValidStyle';
-import {validateProperties as validateARIAProperties} from '../shared/ReactDOMInvalidARIAHook';
-import {validateProperties as validateInputProperties} from '../shared/ReactDOMNullInputValuePropHook';
-import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';
-import assign from 'shared/assign';
-import hasOwnProperty from 'shared/hasOwnProperty';
-
-// Based on reading the React.Children implementation. TODO: type this somewhere?
-type ReactNode = string | number | ReactElement;
-type FlatReactChildren = Array;
-type toArrayType = (children: mixed) => FlatReactChildren;
-const toArray = ((React.Children.toArray: any): toArrayType);
-
-// This is only used in DEV.
-// Each entry is `this.stack` from a currently executing renderer instance.
-// (There may be more than one because ReactDOMServer is reentrant).
-// Each stack is an array of frames which may contain nested stacks of elements.
-const currentDebugStacks = [];
-
-const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
-let ReactDebugCurrentFrame;
-let prevGetCurrentStackImpl = null;
-let getCurrentServerStackImpl = () => '';
-let describeStackFrame = element => '';
-
-let validatePropertiesInDevelopment = (type, props) => {};
-let pushCurrentDebugStack = (stack: Array) => {};
-let pushElementToDebugStack = (element: ReactElement) => {};
-let popCurrentDebugStack = () => {};
-let hasWarnedAboutUsingContextAsConsumer = false;
-
-if (__DEV__) {
- ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
-
- validatePropertiesInDevelopment = function(type, props) {
- validateARIAProperties(type, props);
- validateInputProperties(type, props);
- validateUnknownProperties(type, props, null);
- };
-
- describeStackFrame = function(element): string {
- return describeUnknownElementTypeFrameInDEV(
- element.type,
- element._source,
- null,
- );
- };
-
- pushCurrentDebugStack = function(stack: Array) {
- currentDebugStacks.push(stack);
-
- if (currentDebugStacks.length === 1) {
- // We are entering a server renderer.
- // Remember the previous (e.g. client) global stack implementation.
- prevGetCurrentStackImpl = ReactDebugCurrentFrame.getCurrentStack;
- ReactDebugCurrentFrame.getCurrentStack = getCurrentServerStackImpl;
- }
- };
-
- pushElementToDebugStack = function(element: ReactElement) {
- // For the innermost executing ReactDOMServer call,
- const stack = currentDebugStacks[currentDebugStacks.length - 1];
- // Take the innermost executing frame (e.g. ),
- const frame: Frame = stack[stack.length - 1];
- // and record that it has one more element associated with it.
- ((frame: any): FrameDev).debugElementStack.push(element);
- // We only need this because we tail-optimize single-element
- // children and directly handle them in an inner loop instead of
- // creating separate frames for them.
- };
-
- popCurrentDebugStack = function() {
- currentDebugStacks.pop();
-
- if (currentDebugStacks.length === 0) {
- // We are exiting the server renderer.
- // Restore the previous (e.g. client) global stack implementation.
- ReactDebugCurrentFrame.getCurrentStack = prevGetCurrentStackImpl;
- prevGetCurrentStackImpl = null;
- }
- };
-
- getCurrentServerStackImpl = function(): string {
- if (currentDebugStacks.length === 0) {
- // Nothing is currently rendering.
- return '';
- }
- // ReactDOMServer is reentrant so there may be multiple calls at the same time.
- // Take the frames from the innermost call which is the last in the array.
- const frames = currentDebugStacks[currentDebugStacks.length - 1];
- let stack = '';
- // Go through every frame in the stack from the innermost one.
- for (let i = frames.length - 1; i >= 0; i--) {
- const frame: Frame = frames[i];
- // Every frame might have more than one debug element stack entry associated with it.
- // This is because single-child nesting doesn't create materialized frames.
- // Instead it would push them through `pushElementToDebugStack()`.
- const debugElementStack = ((frame: any): FrameDev).debugElementStack;
- for (let ii = debugElementStack.length - 1; ii >= 0; ii--) {
- stack += describeStackFrame(debugElementStack[ii]);
- }
- }
- return stack;
- };
-}
-
-let didWarnDefaultInputValue = false;
-let didWarnDefaultChecked = false;
-let didWarnDefaultSelectValue = false;
-let didWarnDefaultTextareaValue = false;
-let didWarnInvalidOptionChildren = false;
-let didWarnInvalidOptionInnerHTML = false;
-const didWarnAboutNoopUpdateForComponent = {};
-const didWarnAboutBadClass = {};
-const didWarnAboutModulePatternComponent = {};
-const didWarnAboutDeprecatedWillMount = {};
-const didWarnAboutUndefinedDerivedState = {};
-const didWarnAboutUninitializedState = {};
-const didWarnAboutLegacyLifecyclesAndDerivedState = {};
-const valuePropNames = ['value', 'defaultValue'];
-const newlineEatingTags = {
- listing: true,
- pre: true,
- textarea: true,
-};
-
-// We accept any tag to be rendered but since this gets injected into arbitrary
-// HTML, we want to make sure that it's a safe tag.
-// http://www.w3.org/TR/REC-xml/#NT-Name
-const VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset
-const validatedTagCache = {};
-function validateDangerousTag(tag) {
- if (!validatedTagCache.hasOwnProperty(tag)) {
- if (!VALID_TAG_REGEX.test(tag)) {
- throw new Error(`Invalid tag: ${tag}`);
- }
-
- validatedTagCache[tag] = true;
- }
-}
-
-const styleNameCache = {};
-const processStyleName = function(styleName) {
- if (styleNameCache.hasOwnProperty(styleName)) {
- return styleNameCache[styleName];
- }
- const result = hyphenateStyleName(styleName);
- styleNameCache[styleName] = result;
- return result;
-};
-
-function createMarkupForStyles(styles): string | null {
- let serialized = '';
- let delimiter = '';
- for (const styleName in styles) {
- if (!styles.hasOwnProperty(styleName)) {
- continue;
- }
- const isCustomProperty = styleName.indexOf('--') === 0;
- const styleValue = styles[styleName];
- if (__DEV__) {
- if (!isCustomProperty) {
- warnValidStyle(styleName, styleValue);
- }
- }
- if (styleValue != null) {
- serialized +=
- delimiter +
- (isCustomProperty ? styleName : processStyleName(styleName)) +
- ':';
- serialized += dangerousStyleValue(
- styleName,
- styleValue,
- isCustomProperty,
- );
-
- delimiter = ';';
- }
- }
- return serialized || null;
-}
-
-function warnNoop(
- publicInstance: React$Component,
- callerName: string,
-) {
- if (__DEV__) {
- const constructor = publicInstance.constructor;
- const componentName =
- (constructor && getComponentNameFromType(constructor)) || 'ReactClass';
- const warningKey = componentName + '.' + callerName;
- if (didWarnAboutNoopUpdateForComponent[warningKey]) {
- return;
- }
-
- console.error(
- '%s(...): Can only update a mounting component. ' +
- 'This usually means you called %s() outside componentWillMount() on the server. ' +
- 'This is a no-op.\n\nPlease check the code for the %s component.',
- callerName,
- callerName,
- componentName,
- );
- didWarnAboutNoopUpdateForComponent[warningKey] = true;
- }
-}
-
-function shouldConstruct(Component) {
- return Component.prototype && Component.prototype.isReactComponent;
-}
-
-function getNonChildrenInnerMarkup(props) {
- const innerHTML = props.dangerouslySetInnerHTML;
- if (innerHTML != null) {
- if (innerHTML.__html != null) {
- return innerHTML.__html;
- }
- } else {
- const content = props.children;
- if (typeof content === 'string' || typeof content === 'number') {
- return escapeTextForBrowser(content);
- }
- }
- return null;
-}
-
-function flattenTopLevelChildren(children: mixed): FlatReactChildren {
- if (!React.isValidElement(children)) {
- return toArray(children);
- }
- const element = ((children: any): ReactElement);
- if (element.type !== REACT_FRAGMENT_TYPE) {
- return [element];
- }
- const fragmentChildren = element.props.children;
- if (!React.isValidElement(fragmentChildren)) {
- return toArray(fragmentChildren);
- }
- const fragmentChildElement = ((fragmentChildren: any): ReactElement);
- return [fragmentChildElement];
-}
-
-function flattenOptionChildren(children: mixed): ?string {
- if (children === undefined || children === null) {
- return children;
- }
- let content = '';
- // Flatten children and warn if they aren't strings or numbers;
- // invalid types are ignored.
- React.Children.forEach((children: any), function(child) {
- if (child == null) {
- return;
- }
- content += (child: any);
- if (__DEV__) {
- if (
- !didWarnInvalidOptionChildren &&
- typeof child !== 'string' &&
- typeof child !== 'number'
- ) {
- didWarnInvalidOptionChildren = true;
- console.error(
- 'Cannot infer the option value of complex children. ' +
- 'Pass a `value` prop or use a plain string as children to