Skip to content

Commit 87d0433

Browse files
committed
Boolean props should coerce consistently between HostHoistable and HostComponent and Fizz equivalents
1 parent 5dd90c5 commit 87d0433

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
@@ -1028,7 +1028,12 @@ export function isHydratableType(type: string, props: Props): boolean {
10281028
if (enableFloat) {
10291029
if (type === 'script') {
10301030
const {async, onLoad, onError} = (props: any);
1031-
return !(async && (onLoad || onError));
1031+
return !(
1032+
async &&
1033+
(onLoad || onError) &&
1034+
typeof async !== 'function' &&
1035+
typeof async !== 'symbol'
1036+
);
10321037
}
10331038
return true;
10341039
} else {
@@ -2480,9 +2485,15 @@ export function getResource(
24802485
return null;
24812486
}
24822487
case 'script': {
2483-
if (typeof pendingProps.src === 'string' && pendingProps.async === true) {
2484-
const scriptProps: ScriptProps = pendingProps;
2485-
const key = getScriptKey(scriptProps.src);
2488+
const async = pendingProps.async;
2489+
const src = pendingProps.src;
2490+
if (
2491+
typeof src === 'string' &&
2492+
async &&
2493+
typeof async !== 'function' &&
2494+
typeof async !== 'symbol'
2495+
) {
2496+
const key = getScriptKey(src);
24862497
const scripts = getResourcesFromRoot(resourceRoot).hoistableScripts;
24872498
24882499
let resource = scripts.get(key);
@@ -3127,16 +3138,20 @@ export function isHostHoistableType(
31273138
}
31283139
}
31293140
case 'script': {
3141+
const isAsync =
3142+
props.async &&
3143+
typeof props.async !== 'function' &&
3144+
typeof props.async !== 'symbol';
31303145
if (
3131-
props.async !== true ||
3146+
!isAsync ||
31323147
props.onLoad ||
31333148
props.onError ||
3134-
typeof props.src !== 'string' ||
3135-
!props.src
3149+
!props.src ||
3150+
typeof props.src !== 'string'
31363151
) {
31373152
if (__DEV__) {
31383153
if (outsideHostContainerContext) {
3139-
if (props.async !== true) {
3154+
if (!isAsync) {
31403155
console.error(
31413156
'Cannot render a sync or defer <script> outside the main document without knowing its order.' +
31423157
' 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
@@ -2675,7 +2675,13 @@ function pushScript(
26752675

26762676
const src = props.src;
26772677
const key = getResourceKey('script', src);
2678-
if (props.async !== true || props.onLoad || props.onError) {
2678+
2679+
const isAsync =
2680+
props.async &&
2681+
typeof props.async !== 'function' &&
2682+
typeof props.async !== 'symbol';
2683+
2684+
if (!isAsync || props.onLoad || props.onError) {
26792685
// we don't want to preload nomodule scripts
26802686
if (props.noModule !== true) {
26812687
// We can't resourcify scripts with load listeners. To avoid ambiguity with
@@ -2700,7 +2706,7 @@ function pushScript(
27002706
}
27012707
}
27022708

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

0 commit comments

Comments
 (0)