Skip to content

Commit 0e8255f

Browse files
committed
cleanup
1 parent 0b46ee6 commit 0e8255f

28 files changed

+520
-355
lines changed

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
jsxBracketSameLine: true,
99
trailingComma: 'es5',
1010
printWidth: 80,
11-
parser: 'babel',
11+
parser: 'flow',
1212
arrowParens: 'avoid',
1313
overrides: [
1414
{

packages/react-dom-bindings/src/client/ReactDOMFloatClient.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals.js';
1616
const {Dispatcher} = ReactDOMSharedInternals;
1717
import {DOCUMENT_NODE} from '../shared/HTMLNodeType';
1818
import {
19-
warnOnMissingHrefAndRel,
20-
validatePreloadResourceDifference,
21-
validateURLKeyedUpdatedProps,
22-
validateStyleResourceDifference,
23-
validateScriptResourceDifference,
24-
validateLinkPropsForStyleResource,
25-
validateLinkPropsForPreloadResource,
2619
validatePreloadArguments,
2720
validatePreinitArguments,
2821
} from '../shared/ReactDOMResourceValidation';
@@ -178,9 +171,8 @@ function preload(href: string, options: PreloadOptions) {
178171
ownerDocument
179172
) {
180173
const as = options.as;
181-
const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes(
182-
href,
183-
);
174+
const limitedEscapedHref =
175+
escapeSelectorAttributeValueInsideDoubleQuotes(href);
184176
const preloadKey = `link[rel="preload"][as="${as}"][href="${limitedEscapedHref}"]`;
185177
let key = preloadKey;
186178
switch (as) {
@@ -256,9 +248,8 @@ function preinit(href: string, options: PreinitOptions) {
256248
// matching preload with this href
257249
const preloadDocument = getDocumentForPreloads();
258250
if (preloadDocument) {
259-
const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes(
260-
href,
261-
);
251+
const limitedEscapedHref =
252+
escapeSelectorAttributeValueInsideDoubleQuotes(href);
262253
const preloadKey = `link[rel="preload"][as="${as}"][href="${limitedEscapedHref}"]`;
263254
let key = preloadKey;
264255
switch (as) {
@@ -476,8 +467,6 @@ export function getResource(
476467
const styles = getResourcesFromRoot(resourceRoot).hoistableStyles;
477468
let resource = styles.get(key);
478469
if (!resource) {
479-
// We asserted this above but Flow can't figure out that the type satisfies
480-
const ownerDocument = getDocumentFromRoot(resourceRoot);
481470
resource = {
482471
type: 'style',
483472
instance: null,
@@ -570,9 +559,8 @@ function styleTagPropsFromRawProps(
570559
}
571560

572561
function getStyleKey(href: string) {
573-
const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes(
574-
href,
575-
);
562+
const limitedEscapedHref =
563+
escapeSelectorAttributeValueInsideDoubleQuotes(href);
576564
return `href="${limitedEscapedHref}"`;
577565
}
578566

@@ -609,9 +597,6 @@ function preloadStylesheet(
609597
// There is no matching stylesheet instance in the Document.
610598
// We will insert a preload now to kick off loading because
611599
// we expect this stylesheet to commit
612-
const limitedEscapedHref = escapeSelectorAttributeValueInsideDoubleQuotes(
613-
preloadProps.href,
614-
);
615600
if (
616601
null ===
617602
ownerDocument.querySelector(getPreloadStylesheetSelectorFromKey(key))

packages/react-dom-bindings/src/client/ReactDOMHostConfig.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,7 @@ export const scheduleMicrotask: any =
463463
? queueMicrotask
464464
: typeof localPromise !== 'undefined'
465465
? callback =>
466-
localPromise
467-
.resolve(null)
468-
.then(callback)
469-
.catch(handleErrorInNextTick)
466+
localPromise.resolve(null).then(callback).catch(handleErrorInNextTick)
470467
: scheduleTimeout; // TODO: Determine the best fallback here.
471468

472469
function handleErrorInNextTick(error: any) {
@@ -1591,8 +1588,8 @@ export function isHostHoistableType(
15911588
if (__DEV__) {
15921589
const hostContextDev: HostContextDev = (hostContext: any);
15931590
// We can only render resources when we are not within the host container context
1594-
outsideHostContainerContext = !hostContextDev.ancestorInfo
1595-
.containerTagInScope;
1591+
outsideHostContainerContext =
1592+
!hostContextDev.ancestorInfo.containerTagInScope;
15961593
namespace = hostContextDev.namespace;
15971594
} else {
15981595
const hostContextProd: HostContextProd = (hostContext: any);
@@ -1623,22 +1620,40 @@ export function isHostHoistableType(
16231620
);
16241621
}
16251622
case 'link': {
1626-
const {onLoad, onError} = props;
1627-
if (onLoad || onError) {
1623+
const {onLoad, onError, rel, href} = props;
1624+
if (
1625+
namespace === SVG_NAMESPACE ||
1626+
typeof rel !== 'string' ||
1627+
typeof href !== 'string' ||
1628+
href === '' ||
1629+
onLoad ||
1630+
onError
1631+
) {
16281632
if (__DEV__) {
16291633
if (outsideHostContainerContext) {
1630-
console.error(
1631-
'Cannot render a <link> with onLoad or onError listeners outside the main document.' +
1632-
' Try removing onLoad={...} and onError={...} or moving it into the root <head> tag or' +
1633-
' somewhere in the <body>.',
1634-
);
1634+
if (
1635+
typeof rel !== 'string' ||
1636+
typeof href !== 'string' ||
1637+
href === ''
1638+
) {
1639+
console.error(
1640+
'Cannot render a <link> outside the main document without a `rel` and `href` prop.' +
1641+
' Try adding a `rel` and/or `href` prop to this <link> or moving the link into the <head> tag',
1642+
);
1643+
} else if (onError || onLoad) {
1644+
console.error(
1645+
'Cannot render a <link> with onLoad or onError listeners outside the main document.' +
1646+
' Try removing onLoad={...} and onError={...} or moving it into the root <head> tag or' +
1647+
' somewhere in the <body>.',
1648+
);
1649+
}
16351650
}
16361651
}
16371652
return false;
16381653
}
16391654
switch (props.rel) {
16401655
case 'stylesheet': {
1641-
const {href, precedence, disabled} = props;
1656+
const {precedence, disabled} = props;
16421657
if (__DEV__) {
16431658
validateLinkPropsForStyleResource(props);
16441659
if (typeof precedence !== 'string') {
@@ -1650,12 +1665,7 @@ export function isHostHoistableType(
16501665
}
16511666
}
16521667
}
1653-
return (
1654-
namespace !== SVG_NAMESPACE &&
1655-
typeof href === 'string' &&
1656-
typeof precedence === 'string' &&
1657-
disabled == null
1658-
);
1668+
return typeof precedence === 'string' && disabled == null;
16591669
}
16601670
default: {
16611671
return true;

0 commit comments

Comments
 (0)