[Fiber] Use a safer strategy to track the last precedence (#28110)

Uses a safer strategy to track the last precedence to avoid the need to
consistently remember to preprend `'p'` to the precedence value

DiffTrain build for [1c958aa4ab](https://github.com/facebook/react/commit/1c958aa4abf9e6b638489b1d73cdb1b6dc7c3ab6)
This commit is contained in:
gnoff
2024-01-30 18:15:00 +00:00
parent 52a1078a24
commit bc0fa9ecd7
13 changed files with 113 additions and 89 deletions
+1 -1
View File
@@ -1 +1 @@
766eac46bb52bda28f87c11740214a4444ca881b
1c958aa4abf9e6b638489b1d73cdb1b6dc7c3ab6
+1 -1
View File
@@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-www-classic-482168c3";
var ReactVersion = "18.3.0-www-classic-2277e96d";
// ATTENTION
// When adding new symbols to this file,
+1 -1
View File
@@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}
var ReactVersion = "18.3.0-www-modern-2cff546f";
var ReactVersion = "18.3.0-www-modern-416a65ea";
var LegacyRoot = 0;
var ConcurrentRoot = 1;
+14 -8
View File
@@ -35039,7 +35039,7 @@ if (__DEV__) {
return root;
}
var ReactVersion = "18.3.0-www-classic-8a83edec";
var ReactVersion = "18.3.0-www-classic-dedd8149";
function createPortal$1(
children,
@@ -45535,7 +45535,13 @@ if (__DEV__) {
unsuspend();
}
}
} // This is typecast to non-null because it will always be set before read.
} // We use a value that is type distinct from precedence to track which one is last.
// This ensures there is no collision with user defined precedences. Normally we would
// just track this in module scope but since the precedences are tracked per HoistableRoot
// we need to associate it to something other than a global scope hence why we try to
// colocate it with the map of precedences in the first place
var LAST_PRECEDENCE = null; // This is typecast to non-null because it will always be set before read.
// it is important that this not be used except when the stack guarantees it exists.
// Currentlyt his is only during insertSuspendedStylesheet.
@@ -45585,28 +45591,28 @@ if (__DEV__) {
// and will be hoisted by the Fizz runtime imminently.
node.getAttribute("media") !== "not all"
) {
precedences.set("p" + node.dataset.precedence, node);
precedences.set(node.dataset.precedence, node);
last = node;
}
}
if (last) {
precedences.set("last", last);
precedences.set(LAST_PRECEDENCE, last);
}
} else {
last = precedences.get("last");
last = precedences.get(LAST_PRECEDENCE);
} // We only call this after we have constructed an instance so we assume it here
var instance = resource.instance; // We will always have a precedence for stylesheet instances
var precedence = instance.getAttribute("data-precedence");
var prior = precedences.get("p" + precedence) || last;
var prior = precedences.get(precedence) || last;
if (prior === last) {
precedences.set("last", instance);
precedences.set(LAST_PRECEDENCE, instance);
}
precedences.set("p" + precedence, instance);
precedences.set(precedence, instance);
this.count++;
var onComplete = onUnsuspend.bind(this);
instance.addEventListener("load", onComplete);
+14 -8
View File
@@ -34860,7 +34860,7 @@ if (__DEV__) {
return root;
}
var ReactVersion = "18.3.0-www-modern-30f1d245";
var ReactVersion = "18.3.0-www-modern-57106b67";
function createPortal$1(
children,
@@ -46021,7 +46021,13 @@ if (__DEV__) {
unsuspend();
}
}
} // This is typecast to non-null because it will always be set before read.
} // We use a value that is type distinct from precedence to track which one is last.
// This ensures there is no collision with user defined precedences. Normally we would
// just track this in module scope but since the precedences are tracked per HoistableRoot
// we need to associate it to something other than a global scope hence why we try to
// colocate it with the map of precedences in the first place
var LAST_PRECEDENCE = null; // This is typecast to non-null because it will always be set before read.
// it is important that this not be used except when the stack guarantees it exists.
// Currentlyt his is only during insertSuspendedStylesheet.
@@ -46071,28 +46077,28 @@ if (__DEV__) {
// and will be hoisted by the Fizz runtime imminently.
node.getAttribute("media") !== "not all"
) {
precedences.set("p" + node.dataset.precedence, node);
precedences.set(node.dataset.precedence, node);
last = node;
}
}
if (last) {
precedences.set("last", last);
precedences.set(LAST_PRECEDENCE, last);
}
} else {
last = precedences.get("last");
last = precedences.get(LAST_PRECEDENCE);
} // We only call this after we have constructed an instance so we assume it here
var instance = resource.instance; // We will always have a precedence for stylesheet instances
var precedence = instance.getAttribute("data-precedence");
var prior = precedences.get("p" + precedence) || last;
var prior = precedences.get(precedence) || last;
if (prior === last) {
precedences.set("last", instance);
precedences.set(LAST_PRECEDENCE, instance);
}
precedences.set("p" + precedence, instance);
precedences.set(precedence, instance);
this.count++;
var onComplete = onUnsuspend.bind(this);
instance.addEventListener("load", onComplete);
@@ -15801,7 +15801,7 @@ function insertSuspendedStylesheets(state, resources) {
function insertStylesheetIntoRoot(root, resource) {
if (!(resource.state.loading & 4)) {
var precedences = precedencesByRoot.get(root);
if (precedences) var last = precedences.get("last");
if (precedences) var last = precedences.get(null);
else {
precedences = new Map();
precedencesByRoot.set(root, precedences);
@@ -15818,15 +15818,15 @@ function insertStylesheetIntoRoot(root, resource) {
"link" === node.nodeName ||
"not all" !== node.getAttribute("media")
)
precedences.set("p" + node.dataset.precedence, node), (last = node);
precedences.set(node.dataset.precedence, node), (last = node);
}
last && precedences.set("last", last);
last && precedences.set(null, last);
}
nodes = resource.instance;
node = nodes.getAttribute("data-precedence");
i = precedences.get("p" + node) || last;
i === last && precedences.set("last", nodes);
precedences.set("p" + node, nodes);
i = precedences.get(node) || last;
i === last && precedences.set(null, nodes);
precedences.set(node, nodes);
this.count++;
last = onUnsuspend.bind(this);
nodes.addEventListener("load", last);
@@ -16637,7 +16637,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1801 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-092a346f",
version: "18.3.0-www-classic-aa2ac027",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2147 = {
@@ -16667,7 +16667,7 @@ var internals$jscomp$inline_2147 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-092a346f"
reconcilerVersion: "18.3.0-www-classic-aa2ac027"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2148 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17004,4 +17004,4 @@ exports.useFormState = function () {
exports.useFormStatus = function () {
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-classic-092a346f";
exports.version = "18.3.0-www-classic-aa2ac027";
@@ -16027,7 +16027,7 @@ function insertSuspendedStylesheets(state, resources) {
function insertStylesheetIntoRoot(root, resource) {
if (!(resource.state.loading & 4)) {
var precedences = precedencesByRoot.get(root);
if (precedences) var last = precedences.get("last");
if (precedences) var last = precedences.get(null);
else {
precedences = new Map();
precedencesByRoot.set(root, precedences);
@@ -16044,15 +16044,15 @@ function insertStylesheetIntoRoot(root, resource) {
"link" === node.nodeName ||
"not all" !== node.getAttribute("media")
)
precedences.set("p" + node.dataset.precedence, node), (last = node);
precedences.set(node.dataset.precedence, node), (last = node);
}
last && precedences.set("last", last);
last && precedences.set(null, last);
}
nodes = resource.instance;
node = nodes.getAttribute("data-precedence");
i = precedences.get("p" + node) || last;
i === last && precedences.set("last", nodes);
precedences.set("p" + node, nodes);
i = precedences.get(node) || last;
i === last && precedences.set(null, nodes);
precedences.set(node, nodes);
this.count++;
last = onUnsuspend.bind(this);
nodes.addEventListener("load", last);
@@ -16160,7 +16160,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1760 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-modern-492c5262",
version: "18.3.0-www-modern-571f606f",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2111 = {
@@ -16191,7 +16191,7 @@ var internals$jscomp$inline_2111 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-492c5262"
reconcilerVersion: "18.3.0-www-modern-571f606f"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2112 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16456,4 +16456,4 @@ exports.useFormState = function () {
exports.useFormStatus = function () {
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-modern-492c5262";
exports.version = "18.3.0-www-modern-571f606f";
@@ -16570,7 +16570,7 @@ function insertSuspendedStylesheets(state, resources) {
function insertStylesheetIntoRoot(root, resource) {
if (!(resource.state.loading & 4)) {
var precedences = precedencesByRoot.get(root);
if (precedences) var last = precedences.get("last");
if (precedences) var last = precedences.get(null);
else {
precedences = new Map();
precedencesByRoot.set(root, precedences);
@@ -16587,15 +16587,15 @@ function insertStylesheetIntoRoot(root, resource) {
"link" === node.nodeName ||
"not all" !== node.getAttribute("media")
)
precedences.set("p" + node.dataset.precedence, node), (last = node);
precedences.set(node.dataset.precedence, node), (last = node);
}
last && precedences.set("last", last);
last && precedences.set(null, last);
}
nodes = resource.instance;
node = nodes.getAttribute("data-precedence");
i = precedences.get("p" + node) || last;
i === last && precedences.set("last", nodes);
precedences.set("p" + node, nodes);
i = precedences.get(node) || last;
i === last && precedences.set(null, nodes);
precedences.set(node, nodes);
this.count++;
last = onUnsuspend.bind(this);
nodes.addEventListener("load", last);
@@ -17406,7 +17406,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1886 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-54ebd8ef",
version: "18.3.0-www-classic-071ab715",
rendererPackageName: "react-dom"
};
(function (internals) {
@@ -17450,7 +17450,7 @@ var devToolsConfig$jscomp$inline_1886 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-54ebd8ef"
reconcilerVersion: "18.3.0-www-classic-071ab715"
});
assign(Internals, {
ReactBrowserEventEmitter: {
@@ -17774,7 +17774,7 @@ exports.useFormState = function () {
exports.useFormStatus = function () {
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-classic-54ebd8ef";
exports.version = "18.3.0-www-classic-071ab715";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
@@ -16790,7 +16790,7 @@ function insertSuspendedStylesheets(state, resources) {
function insertStylesheetIntoRoot(root, resource) {
if (!(resource.state.loading & 4)) {
var precedences = precedencesByRoot.get(root);
if (precedences) var last = precedences.get("last");
if (precedences) var last = precedences.get(null);
else {
precedences = new Map();
precedencesByRoot.set(root, precedences);
@@ -16807,15 +16807,15 @@ function insertStylesheetIntoRoot(root, resource) {
"link" === node.nodeName ||
"not all" !== node.getAttribute("media")
)
precedences.set("p" + node.dataset.precedence, node), (last = node);
precedences.set(node.dataset.precedence, node), (last = node);
}
last && precedences.set("last", last);
last && precedences.set(null, last);
}
nodes = resource.instance;
node = nodes.getAttribute("data-precedence");
i = precedences.get("p" + node) || last;
i === last && precedences.set("last", nodes);
precedences.set("p" + node, nodes);
i = precedences.get(node) || last;
i === last && precedences.set(null, nodes);
precedences.set(node, nodes);
this.count++;
last = onUnsuspend.bind(this);
nodes.addEventListener("load", last);
@@ -16923,7 +16923,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1845 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-modern-2cff546f",
version: "18.3.0-www-modern-416a65ea",
rendererPackageName: "react-dom"
};
(function (internals) {
@@ -16968,7 +16968,7 @@ var devToolsConfig$jscomp$inline_1845 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-2cff546f"
reconcilerVersion: "18.3.0-www-modern-416a65ea"
});
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = Internals;
exports.createPortal = function (children, container) {
@@ -17220,7 +17220,7 @@ exports.useFormState = function () {
exports.useFormStatus = function () {
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-modern-2cff546f";
exports.version = "18.3.0-www-modern-416a65ea";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
@@ -35663,7 +35663,7 @@ if (__DEV__) {
return root;
}
var ReactVersion = "18.3.0-www-classic-a29685c5";
var ReactVersion = "18.3.0-www-classic-49254bd7";
function createPortal$1(
children,
@@ -46291,7 +46291,13 @@ if (__DEV__) {
unsuspend();
}
}
} // This is typecast to non-null because it will always be set before read.
} // We use a value that is type distinct from precedence to track which one is last.
// This ensures there is no collision with user defined precedences. Normally we would
// just track this in module scope but since the precedences are tracked per HoistableRoot
// we need to associate it to something other than a global scope hence why we try to
// colocate it with the map of precedences in the first place
var LAST_PRECEDENCE = null; // This is typecast to non-null because it will always be set before read.
// it is important that this not be used except when the stack guarantees it exists.
// Currentlyt his is only during insertSuspendedStylesheet.
@@ -46341,28 +46347,28 @@ if (__DEV__) {
// and will be hoisted by the Fizz runtime imminently.
node.getAttribute("media") !== "not all"
) {
precedences.set("p" + node.dataset.precedence, node);
precedences.set(node.dataset.precedence, node);
last = node;
}
}
if (last) {
precedences.set("last", last);
precedences.set(LAST_PRECEDENCE, last);
}
} else {
last = precedences.get("last");
last = precedences.get(LAST_PRECEDENCE);
} // We only call this after we have constructed an instance so we assume it here
var instance = resource.instance; // We will always have a precedence for stylesheet instances
var precedence = instance.getAttribute("data-precedence");
var prior = precedences.get("p" + precedence) || last;
var prior = precedences.get(precedence) || last;
if (prior === last) {
precedences.set("last", instance);
precedences.set(LAST_PRECEDENCE, instance);
}
precedences.set("p" + precedence, instance);
precedences.set(precedence, instance);
this.count++;
var onComplete = onUnsuspend.bind(this);
instance.addEventListener("load", onComplete);
@@ -35484,7 +35484,7 @@ if (__DEV__) {
return root;
}
var ReactVersion = "18.3.0-www-modern-6846ad23";
var ReactVersion = "18.3.0-www-modern-94e6d325";
function createPortal$1(
children,
@@ -46777,7 +46777,13 @@ if (__DEV__) {
unsuspend();
}
}
} // This is typecast to non-null because it will always be set before read.
} // We use a value that is type distinct from precedence to track which one is last.
// This ensures there is no collision with user defined precedences. Normally we would
// just track this in module scope but since the precedences are tracked per HoistableRoot
// we need to associate it to something other than a global scope hence why we try to
// colocate it with the map of precedences in the first place
var LAST_PRECEDENCE = null; // This is typecast to non-null because it will always be set before read.
// it is important that this not be used except when the stack guarantees it exists.
// Currentlyt his is only during insertSuspendedStylesheet.
@@ -46827,28 +46833,28 @@ if (__DEV__) {
// and will be hoisted by the Fizz runtime imminently.
node.getAttribute("media") !== "not all"
) {
precedences.set("p" + node.dataset.precedence, node);
precedences.set(node.dataset.precedence, node);
last = node;
}
}
if (last) {
precedences.set("last", last);
precedences.set(LAST_PRECEDENCE, last);
}
} else {
last = precedences.get("last");
last = precedences.get(LAST_PRECEDENCE);
} // We only call this after we have constructed an instance so we assume it here
var instance = resource.instance; // We will always have a precedence for stylesheet instances
var precedence = instance.getAttribute("data-precedence");
var prior = precedences.get("p" + precedence) || last;
var prior = precedences.get(precedence) || last;
if (prior === last) {
precedences.set("last", instance);
precedences.set(LAST_PRECEDENCE, instance);
}
precedences.set("p" + precedence, instance);
precedences.set(precedence, instance);
this.count++;
var onComplete = onUnsuspend.bind(this);
instance.addEventListener("load", onComplete);
@@ -16130,7 +16130,7 @@ function insertSuspendedStylesheets(state, resources) {
function insertStylesheetIntoRoot(root, resource) {
if (!(resource.state.loading & 4)) {
var precedences = precedencesByRoot.get(root);
if (precedences) var last = precedences.get("last");
if (precedences) var last = precedences.get(null);
else {
precedences = new Map();
precedencesByRoot.set(root, precedences);
@@ -16147,15 +16147,15 @@ function insertStylesheetIntoRoot(root, resource) {
"link" === node.nodeName ||
"not all" !== node.getAttribute("media")
)
precedences.set("p" + node.dataset.precedence, node), (last = node);
precedences.set(node.dataset.precedence, node), (last = node);
}
last && precedences.set("last", last);
last && precedences.set(null, last);
}
nodes = resource.instance;
node = nodes.getAttribute("data-precedence");
i = precedences.get("p" + node) || last;
i === last && precedences.set("last", nodes);
precedences.set("p" + node, nodes);
i = precedences.get(node) || last;
i === last && precedences.set(null, nodes);
precedences.set(node, nodes);
this.count++;
last = onUnsuspend.bind(this);
nodes.addEventListener("load", last);
@@ -16966,7 +16966,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1806 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-482168c3",
version: "18.3.0-www-classic-2277e96d",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2159 = {
@@ -16996,7 +16996,7 @@ var internals$jscomp$inline_2159 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-482168c3"
reconcilerVersion: "18.3.0-www-classic-2277e96d"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2160 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17484,4 +17484,4 @@ exports.useFormState = function () {
exports.useFormStatus = function () {
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-classic-482168c3";
exports.version = "18.3.0-www-classic-2277e96d";
@@ -16410,7 +16410,7 @@ function insertSuspendedStylesheets(state, resources) {
function insertStylesheetIntoRoot(root, resource) {
if (!(resource.state.loading & 4)) {
var precedences = precedencesByRoot.get(root);
if (precedences) var last = precedences.get("last");
if (precedences) var last = precedences.get(null);
else {
precedences = new Map();
precedencesByRoot.set(root, precedences);
@@ -16427,15 +16427,15 @@ function insertStylesheetIntoRoot(root, resource) {
"link" === node.nodeName ||
"not all" !== node.getAttribute("media")
)
precedences.set("p" + node.dataset.precedence, node), (last = node);
precedences.set(node.dataset.precedence, node), (last = node);
}
last && precedences.set("last", last);
last && precedences.set(null, last);
}
nodes = resource.instance;
node = nodes.getAttribute("data-precedence");
i = precedences.get("p" + node) || last;
i === last && precedences.set("last", nodes);
precedences.set("p" + node, nodes);
i = precedences.get(node) || last;
i === last && precedences.set(null, nodes);
precedences.set(node, nodes);
this.count++;
last = onUnsuspend.bind(this);
nodes.addEventListener("load", last);
@@ -16543,7 +16543,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1765 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-modern-e6f7fbc4",
version: "18.3.0-www-modern-79a03470",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2122 = {
@@ -16574,7 +16574,7 @@ var internals$jscomp$inline_2122 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-e6f7fbc4"
reconcilerVersion: "18.3.0-www-modern-79a03470"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2123 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -16989,4 +16989,4 @@ exports.useFormState = function () {
exports.useFormStatus = function () {
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-modern-e6f7fbc4";
exports.version = "18.3.0-www-modern-79a03470";