diff --git a/.prettierrc.js b/.prettierrc.js index 7109a6fe8c57b..4f7ef193130c9 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -8,7 +8,7 @@ module.exports = { jsxBracketSameLine: true, trailingComma: 'es5', printWidth: 80, - parser: 'babel', + parser: 'flow', arrowParens: 'avoid', overrides: [ { diff --git a/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js b/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js index 73b18a3aff76c..10c44364c5b60 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js +++ b/packages/react-dom-bindings/src/client/ReactDOMFloatClient.js @@ -16,13 +16,6 @@ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals.js'; const {Dispatcher} = ReactDOMSharedInternals; import {DOCUMENT_NODE} from '../shared/HTMLNodeType'; import { - warnOnMissingHrefAndRel, - validatePreloadResourceDifference, - validateURLKeyedUpdatedProps, - validateStyleResourceDifference, - validateScriptResourceDifference, - validateLinkPropsForStyleResource, - validateLinkPropsForPreloadResource, validatePreloadArguments, validatePreinitArguments, } from '../shared/ReactDOMResourceValidation'; @@ -178,9 +171,8 @@ function preload(href: string, options: PreloadOptions) { ownerDocument ) { const as = options.as; - const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes( - href, - ); + const limitedEscapedHref = + escapeSelectorAttributeValueInsideDoubleQuotes(href); const preloadKey = `link[rel="preload"][as="${as}"][href="${limitedEscapedHref}"]`; let key = preloadKey; switch (as) { @@ -256,9 +248,8 @@ function preinit(href: string, options: PreinitOptions) { // matching preload with this href const preloadDocument = getDocumentForPreloads(); if (preloadDocument) { - const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes( - href, - ); + const limitedEscapedHref = + escapeSelectorAttributeValueInsideDoubleQuotes(href); const preloadKey = `link[rel="preload"][as="${as}"][href="${limitedEscapedHref}"]`; let key = preloadKey; switch (as) { @@ -476,8 +467,6 @@ export function getResource( const styles = getResourcesFromRoot(resourceRoot).hoistableStyles; let resource = styles.get(key); if (!resource) { - // We asserted this above but Flow can't figure out that the type satisfies - const ownerDocument = getDocumentFromRoot(resourceRoot); resource = { type: 'style', instance: null, @@ -570,9 +559,8 @@ function styleTagPropsFromRawProps( } function getStyleKey(href: string) { - const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes( - href, - ); + const limitedEscapedHref = + escapeSelectorAttributeValueInsideDoubleQuotes(href); return `href="${limitedEscapedHref}"`; } @@ -609,9 +597,6 @@ function preloadStylesheet( // There is no matching stylesheet instance in the Document. // We will insert a preload now to kick off loading because // we expect this stylesheet to commit - const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes( - preloadProps.href, - ); if ( null === ownerDocument.querySelector(getPreloadStylesheetSelectorFromKey(key)) diff --git a/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js b/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js index dfcd38e561fba..baf2275a8050b 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js +++ b/packages/react-dom-bindings/src/client/ReactDOMHostConfig.js @@ -463,10 +463,7 @@ export const scheduleMicrotask: any = ? queueMicrotask : typeof localPromise !== 'undefined' ? callback => - localPromise - .resolve(null) - .then(callback) - .catch(handleErrorInNextTick) + localPromise.resolve(null).then(callback).catch(handleErrorInNextTick) : scheduleTimeout; // TODO: Determine the best fallback here. function handleErrorInNextTick(error: any) { @@ -1591,8 +1588,8 @@ export function isHostHoistableType( if (__DEV__) { const hostContextDev: HostContextDev = (hostContext: any); // We can only render resources when we are not within the host container context - outsideHostContainerContext = !hostContextDev.ancestorInfo - .containerTagInScope; + outsideHostContainerContext = + !hostContextDev.ancestorInfo.containerTagInScope; namespace = hostContextDev.namespace; } else { const hostContextProd: HostContextProd = (hostContext: any); @@ -1623,8 +1620,15 @@ export function isHostHoistableType( ); } case 'link': { - const {onLoad, onError} = props; - if (onLoad || onError) { + const {onLoad, onError, rel, href} = props; + if ( + namespace === SVG_NAMESPACE || + rel !== 'string' || + href !== 'string' || + href === '' || + onLoad || + onError + ) { if (__DEV__) { if (outsideHostContainerContext) { console.error( @@ -1638,7 +1642,7 @@ export function isHostHoistableType( } switch (props.rel) { case 'stylesheet': { - const {href, precedence, disabled} = props; + const {precedence, disabled} = props; if (__DEV__) { validateLinkPropsForStyleResource(props); if (typeof precedence !== 'string') { @@ -1650,12 +1654,7 @@ export function isHostHoistableType( } } } - return ( - namespace !== SVG_NAMESPACE && - typeof href === 'string' && - typeof precedence === 'string' && - disabled == null - ); + return typeof precedence === 'string' && disabled == null; } default: { return true; diff --git a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js index 1152782e83d9a..cc1029c92d811 100644 --- a/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom-bindings/src/server/ReactDOMServerFormatConfig.js @@ -892,7 +892,7 @@ function flattenOptionChildren(children: mixed): string { let content = ''; // Flatten children and warn if they aren't strings or numbers; // invalid types are ignored. - Children.forEach((children: any), function(child) { + Children.forEach((children: any), function (child) { if (child == null) { return; } @@ -1355,8 +1355,8 @@ function pushLink( // This stylesheet refers to a Resource and we create a new one if necessary let resource = resources.stylesMap.get(key); if (__DEV__) { - if (resource) { - const devResource: ResourceDEV = (resource: any); + const devResource = getAsResourceDEV(resource); + if (devResource) { switch (devResource.__provenance) { case 'rendered': { const differentProps = compareResourcePropsForWarning( @@ -1365,9 +1365,8 @@ function pushLink( devResource.__originalProps, ); if (differentProps) { - const differenceDescription = describeDifferencesForStylesheets( - differentProps, - ); + const differenceDescription = + describeDifferencesForStylesheets(differentProps); if (differenceDescription) { console.error( 'React encountered a with a `precedence` prop that has props that conflict' + @@ -1388,9 +1387,10 @@ function pushLink( devResource.__propsEquivalent, ); if (differentProps) { - const differenceDescription = describeDifferencesForStylesheetOverPreinit( - differentProps, - ); + const differenceDescription = + describeDifferencesForStylesheetOverPreinit( + differentProps, + ); if (differenceDescription) { console.error( 'React encountered a with props that conflict' + @@ -1725,22 +1725,40 @@ function pushTitle( : null : children; - if ( - typeof child === 'function' || - typeof child === 'symbol' || - Array.isArray(child) - ) { + if (Array.isArray(children) && children.length > 1) { + console.error( + 'React expects the `children` prop of