Skip to content

Commit fea1d99

Browse files
committed
Boolean props should coerce consistently between HostHoistable and HostComponent and Fizz equivalents
1 parent 8ea96ef commit fea1d99

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,12 @@ export function isHydratableType(type: string, props: Props): boolean {
10271027
if (enableFloat) {
10281028
if (type === 'script') {
10291029
const {async, onLoad, onError} = (props: any);
1030-
return !(async && (onLoad || onError));
1030+
return !(
1031+
async &&
1032+
(onLoad || onError) &&
1033+
typeof async !== 'function' &&
1034+
typeof async !== 'symbol'
1035+
);
10311036
}
10321037
return true;
10331038
} else {
@@ -2455,9 +2460,15 @@ export function getResource(
24552460
return null;
24562461
}
24572462
case 'script': {
2458-
if (typeof pendingProps.src === 'string' && pendingProps.async === true) {
2459-
const scriptProps: ScriptProps = pendingProps;
2460-
const key = getScriptKey(scriptProps.src);
2463+
const async = pendingProps.async;
2464+
const src = pendingProps.src;
2465+
if (
2466+
typeof src === 'string' &&
2467+
async &&
2468+
typeof async !== 'function' &&
2469+
typeof async !== 'symbol'
2470+
) {
2471+
const key = getScriptKey(src);
24612472
const scripts = getResourcesFromRoot(resourceRoot).hoistableScripts;
24622473
24632474
let resource = scripts.get(key);
@@ -3102,16 +3113,20 @@ export function isHostHoistableType(
31023113
}
31033114
}
31043115
case 'script': {
3116+
const isAsync =
3117+
props.async &&
3118+
typeof props.async !== 'function' &&
3119+
typeof props.async !== 'symbol';
31053120
if (
3106-
props.async !== true ||
3121+
!isAsync ||
31073122
props.onLoad ||
31083123
props.onError ||
3109-
typeof props.src !== 'string' ||
3110-
!props.src
3124+
!props.src ||
3125+
typeof props.src !== 'string'
31113126
) {
31123127
if (__DEV__) {
31133128
if (outsideHostContainerContext) {
3114-
if (props.async !== true) {
3129+
if (!isAsync) {
31153130
console.error(
31163131
'Cannot render a sync or defer <script> outside the main document without knowing its order.' +
31173132
' Try adding async="" or moving it into the root <head> tag.',

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,13 @@ function pushScript(
25752575

25762576
const src = props.src;
25772577
const key = getResourceKey('script', src);
2578-
if (props.async !== true || props.onLoad || props.onError) {
2578+
2579+
const isAsync =
2580+
props.async &&
2581+
typeof props.async !== 'function' &&
2582+
typeof props.async !== 'symbol';
2583+
2584+
if (!isAsync || props.onLoad || props.onError) {
25792585
// we don't want to preload nomodule scripts
25802586
if (props.noModule !== true) {
25812587
// We can't resourcify scripts with load listeners. To avoid ambiguity with
@@ -2600,7 +2606,7 @@ function pushScript(
26002606
}
26012607
}
26022608

2603-
if (props.async !== true) {
2609+
if (!isAsync) {
26042610
// This is not an async script, we can preloaded it but it still needs to
26052611
// be emitted in place since it needs to hydrate on the client
26062612
pushScriptImpl(target, props);

0 commit comments

Comments
 (0)