Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b1cce0

Browse files
committed
[Fiber] retain scripts on clearContainer and clearSingleton (#26871)
clearContainer and clearSingleton both assumed scripts could be safely removed from the DOM because normally once a script has been inserted into the DOM it is executable and removing it, even synchronously, will not prevent it from running. However There is an edge case in a couple browsers (Chrome at least) where during HTML streaming if a script is opened and not yet closed the script will be inserted into the document but not yet executed. If the script is removed from the document before the end tag is parsed then the script will not run. This change causes clearContainer and clearSingleton to retain script elements. This is generally thought to be safe because if we are calling these methods we are no longer hydrating the container or the singleton and the scripts execution will happen regardless. DiffTrain build for [1cea384](1cea384)
1 parent abcb33d commit 0b1cce0

15 files changed

+100
-28
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0210f0b082c95f5aec08f356d796c512eab44fc4
1+
1cea384480a6dea80128e5e0ddb714df7bea1520

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-www-modern-c47d099f";
30+
var ReactVersion = "18.3.0-www-modern-1948588f";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-classic-70819ba2";
72+
var ReactVersion = "18.3.0-www-classic-ce251e44";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
6969
return self;
7070
}
7171

72-
var ReactVersion = "18.3.0-www-modern-c47d099f";
72+
var ReactVersion = "18.3.0-www-modern-1948588f";
7373

7474
var LegacyRoot = 0;
7575
var ConcurrentRoot = 1;

compiled/facebook-www/ReactART-prod.classic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10193,7 +10193,7 @@ var slice = Array.prototype.slice,
1019310193
return null;
1019410194
},
1019510195
bundleType: 0,
10196-
version: "18.3.0-www-classic-c0d8bc44",
10196+
version: "18.3.0-www-classic-8d78e420",
1019710197
rendererPackageName: "react-art"
1019810198
};
1019910199
var internals$jscomp$inline_1323 = {
@@ -10224,7 +10224,7 @@ var internals$jscomp$inline_1323 = {
1022410224
scheduleRoot: null,
1022510225
setRefreshHandler: null,
1022610226
getCurrentFiber: null,
10227-
reconcilerVersion: "18.3.0-www-classic-c0d8bc44"
10227+
reconcilerVersion: "18.3.0-www-classic-8d78e420"
1022810228
};
1022910229
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1023010230
var hook$jscomp$inline_1324 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled/facebook-www/ReactDOM-dev.classic.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34196,7 +34196,7 @@ function createFiberRoot(
3419634196
return root;
3419734197
}
3419834198

34199-
var ReactVersion = "18.3.0-www-classic-04ede6af";
34199+
var ReactVersion = "18.3.0-www-classic-b91cf5f1";
3420034200

3420134201
function createPortal$1(
3420234202
children,
@@ -42932,10 +42932,24 @@ function clearContainerSparingly(container) {
4293242932
detachDeletedInstance(element);
4293342933
continue;
4293442934
}
42935+
// Script tags are retained to avoid an edge case bug. Normally scripts will execute if they
42936+
// are ever inserted into the DOM. However when streaming if a script tag is opened but not
42937+
// yet closed some browsers create and insert the script DOM Node but the script cannot execute
42938+
// yet until the closing tag is parsed. If something causes React to call clearContainer while
42939+
// this DOM node is in the document but not yet executable the DOM node will be removed from the
42940+
// document and when the script closing tag comes in the script will not end up running. This seems
42941+
// to happen in Chrome/Firefox but not Safari at the moment though this is not necessarily specified
42942+
// behavior so it could change in future versions of browsers. While leaving all scripts is broader
42943+
// than strictly necessary this is the least amount of additional code to avoid this breaking
42944+
// edge case.
42945+
//
42946+
// Style tags are retained because they may likely come from 3rd party scripts and extensions
4293542947

42948+
case "SCRIPT":
4293642949
case "STYLE": {
4293742950
continue;
4293842951
}
42952+
// Stylesheet tags are retained because tehy may likely come from 3rd party scripts and extensions
4293942953

4294042954
case "LINK": {
4294142955
if (node.rel.toLowerCase() === "stylesheet") {
@@ -43612,6 +43626,7 @@ function clearSingleton(instance) {
4361243626
isMarkedHoistable(node) ||
4361343627
nodeName === "HEAD" ||
4361443628
nodeName === "BODY" ||
43629+
nodeName === "SCRIPT" ||
4361543630
nodeName === "STYLE" ||
4361643631
(nodeName === "LINK" && node.rel.toLowerCase() === "stylesheet")
4361743632
);

compiled/facebook-www/ReactDOM-dev.modern.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34041,7 +34041,7 @@ function createFiberRoot(
3404134041
return root;
3404234042
}
3404334043

34044-
var ReactVersion = "18.3.0-www-modern-27051227";
34044+
var ReactVersion = "18.3.0-www-modern-13e7cdbe";
3404534045

3404634046
function createPortal$1(
3404734047
children,
@@ -43442,10 +43442,24 @@ function clearContainerSparingly(container) {
4344243442
detachDeletedInstance(element);
4344343443
continue;
4344443444
}
43445+
// Script tags are retained to avoid an edge case bug. Normally scripts will execute if they
43446+
// are ever inserted into the DOM. However when streaming if a script tag is opened but not
43447+
// yet closed some browsers create and insert the script DOM Node but the script cannot execute
43448+
// yet until the closing tag is parsed. If something causes React to call clearContainer while
43449+
// this DOM node is in the document but not yet executable the DOM node will be removed from the
43450+
// document and when the script closing tag comes in the script will not end up running. This seems
43451+
// to happen in Chrome/Firefox but not Safari at the moment though this is not necessarily specified
43452+
// behavior so it could change in future versions of browsers. While leaving all scripts is broader
43453+
// than strictly necessary this is the least amount of additional code to avoid this breaking
43454+
// edge case.
43455+
//
43456+
// Style tags are retained because they may likely come from 3rd party scripts and extensions
4344543457

43458+
case "SCRIPT":
4344643459
case "STYLE": {
4344743460
continue;
4344843461
}
43462+
// Stylesheet tags are retained because tehy may likely come from 3rd party scripts and extensions
4344943463

4345043464
case "LINK": {
4345143465
if (node.rel.toLowerCase() === "stylesheet") {
@@ -44122,6 +44136,7 @@ function clearSingleton(instance) {
4412244136
isMarkedHoistable(node) ||
4412344137
nodeName === "HEAD" ||
4412444138
nodeName === "BODY" ||
44139+
nodeName === "SCRIPT" ||
4412544140
nodeName === "STYLE" ||
4412644141
(nodeName === "LINK" && node.rel.toLowerCase() === "stylesheet")
4412744142
);

compiled/facebook-www/ReactDOM-prod.classic.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8673,6 +8673,7 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
86738673
i[internalHoistableMarker] ||
86748674
"HEAD" === nodeName ||
86758675
"BODY" === nodeName ||
8676+
"SCRIPT" === nodeName ||
86768677
"STYLE" === nodeName ||
86778678
("LINK" === nodeName && "stylesheet" === i.rel.toLowerCase()) ||
86788679
hoistableRoot.removeChild(i);
@@ -15108,6 +15109,7 @@ function clearContainerSparingly(container) {
1510815109
clearContainerSparingly(node);
1510915110
detachDeletedInstance(node);
1511015111
continue;
15112+
case "SCRIPT":
1511115113
case "STYLE":
1511215114
continue;
1511315115
case "LINK":
@@ -16649,7 +16651,7 @@ Internals.Events = [
1664916651
var devToolsConfig$jscomp$inline_1827 = {
1665016652
findFiberByHostInstance: getClosestInstanceFromNode,
1665116653
bundleType: 0,
16652-
version: "18.3.0-www-classic-70819ba2",
16654+
version: "18.3.0-www-classic-ce251e44",
1665316655
rendererPackageName: "react-dom"
1665416656
};
1665516657
var internals$jscomp$inline_2201 = {
@@ -16679,7 +16681,7 @@ var internals$jscomp$inline_2201 = {
1667916681
scheduleRoot: null,
1668016682
setRefreshHandler: null,
1668116683
getCurrentFiber: null,
16682-
reconcilerVersion: "18.3.0-www-classic-70819ba2"
16684+
reconcilerVersion: "18.3.0-www-classic-ce251e44"
1668316685
};
1668416686
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1668516687
var hook$jscomp$inline_2202 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16922,4 +16924,4 @@ exports.unstable_renderSubtreeIntoContainer = function (
1692216924
);
1692316925
};
1692416926
exports.unstable_runWithPriority = runWithPriority;
16925-
exports.version = "18.3.0-www-classic-70819ba2";
16927+
exports.version = "18.3.0-www-classic-ce251e44";

compiled/facebook-www/ReactDOM-prod.modern.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8509,6 +8509,7 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
85098509
i[internalHoistableMarker] ||
85108510
"HEAD" === nodeName ||
85118511
"BODY" === nodeName ||
8512+
"SCRIPT" === nodeName ||
85128513
"STYLE" === nodeName ||
85138514
("LINK" === nodeName && "stylesheet" === i.rel.toLowerCase()) ||
85148515
hoistableRoot.removeChild(i);
@@ -15336,6 +15337,7 @@ function clearContainerSparingly(container) {
1533615337
clearContainerSparingly(node);
1533715338
detachDeletedInstance(node);
1533815339
continue;
15340+
case "SCRIPT":
1533915341
case "STYLE":
1534015342
continue;
1534115343
case "LINK":
@@ -16176,7 +16178,7 @@ Internals.Events = [
1617616178
var devToolsConfig$jscomp$inline_1786 = {
1617716179
findFiberByHostInstance: getClosestInstanceFromNode,
1617816180
bundleType: 0,
16179-
version: "18.3.0-www-modern-29fda94c",
16181+
version: "18.3.0-www-modern-de14310d",
1618016182
rendererPackageName: "react-dom"
1618116183
};
1618216184
var internals$jscomp$inline_2165 = {
@@ -16207,7 +16209,7 @@ var internals$jscomp$inline_2165 = {
1620716209
scheduleRoot: null,
1620816210
setRefreshHandler: null,
1620916211
getCurrentFiber: null,
16210-
reconcilerVersion: "18.3.0-www-modern-29fda94c"
16212+
reconcilerVersion: "18.3.0-www-modern-de14310d"
1621116213
};
1621216214
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1621316215
var hook$jscomp$inline_2166 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16378,4 +16380,4 @@ exports.unstable_createEventHandle = function (type, options) {
1637816380
return eventHandle;
1637916381
};
1638016382
exports.unstable_runWithPriority = runWithPriority;
16381-
exports.version = "18.3.0-www-modern-29fda94c";
16383+
exports.version = "18.3.0-www-modern-de14310d";

compiled/facebook-www/ReactDOM-profiling.classic.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9223,6 +9223,7 @@ function commitMutationEffectsOnFiber(finishedWork, root) {
92239223
i[internalHoistableMarker] ||
92249224
"HEAD" === nodeName ||
92259225
"BODY" === nodeName ||
9226+
"SCRIPT" === nodeName ||
92269227
"STYLE" === nodeName ||
92279228
("LINK" === nodeName && "stylesheet" === i.rel.toLowerCase()) ||
92289229
hoistableRoot.removeChild(i);
@@ -15883,6 +15884,7 @@ function clearContainerSparingly(container) {
1588315884
clearContainerSparingly(node);
1588415885
detachDeletedInstance(node);
1588515886
continue;
15887+
case "SCRIPT":
1588615888
case "STYLE":
1588715889
continue;
1588815890
case "LINK":
@@ -17424,7 +17426,7 @@ Internals.Events = [
1742417426
var devToolsConfig$jscomp$inline_1912 = {
1742517427
findFiberByHostInstance: getClosestInstanceFromNode,
1742617428
bundleType: 0,
17427-
version: "18.3.0-www-classic-c0d8bc44",
17429+
version: "18.3.0-www-classic-8d78e420",
1742817430
rendererPackageName: "react-dom"
1742917431
};
1743017432
(function (internals) {
@@ -17468,7 +17470,7 @@ var devToolsConfig$jscomp$inline_1912 = {
1746817470
scheduleRoot: null,
1746917471
setRefreshHandler: null,
1747017472
getCurrentFiber: null,
17471-
reconcilerVersion: "18.3.0-www-classic-c0d8bc44"
17473+
reconcilerVersion: "18.3.0-www-classic-8d78e420"
1747217474
});
1747317475
assign(Internals, {
1747417476
ReactBrowserEventEmitter: {
@@ -17698,7 +17700,7 @@ exports.unstable_renderSubtreeIntoContainer = function (
1769817700
);
1769917701
};
1770017702
exports.unstable_runWithPriority = runWithPriority;
17701-
exports.version = "18.3.0-www-classic-c0d8bc44";
17703+
exports.version = "18.3.0-www-classic-8d78e420";
1770217704

1770317705
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
1770417706
if (

0 commit comments

Comments
 (0)