Skip to content

Commit

Permalink
[Fizz][Float] stop automatically preloading scripts that are not scri…
Browse files Browse the repository at this point in the history
…pt resources (#26877)

Currently we preload all scripts that are not hoisted. One of the
original reasons for this is we stopped SSR rendering async scripts that
had an onLoad/onError because we needed to be able to distinguish
between Float scripts and non-Float scripts during hydration. Hydration
has been refactored a bit and we can not get around this limitation so
we can just emit the async script in place. However, sync and defer
scripts are also preloaded. While this is sometimes desirable it is not
universally so and there are issues with conveying priority properly
(see fetchpriority) so with this change we remove the automatic
preloading of non-Float scripts altogether.

For this change to make sense we also need to emit async scripts with
loading handlers during SSR. we previously only preloaded them during
SSR because it was necessary to keep async scripts as unambiguously
resources when hydrating. One ancillary benefit was that load handlers
would always fire b/c there was no chance the script would run before
hydration. With this change we go back to having the ability to have
load handlers fired before hydration. This is already a problem with
images and we don't have a generalized solution for it however our
likely approach to this sort of thing where you need to wait for a
script to load is to use something akin to `importScripts()` rather than
rendering a script with onLoad.

DiffTrain build for [e1ad4aa](e1ad4aa)
  • Loading branch information
gnoff committed Jun 1, 2023
1 parent 54ded05 commit 650431a
Show file tree
Hide file tree
Showing 21 changed files with 906 additions and 1,334 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5fb2c15a89de844a1dd12a61e7674e55dc0dfa89
e1ad4aa3615333009d76f947ff05ddeff01039c6
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-c2caceb8";
var ReactVersion = "18.3.0-www-modern-c6e529af";

// ATTENTION
// When adding new symbols to this file,
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-173d7c2e";
var ReactVersion = "18.3.0-www-classic-98dc4286";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-modern-c2caceb8";
var ReactVersion = "18.3.0-www-modern-c6e529af";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10193,7 +10193,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-classic-808eab78",
version: "18.3.0-www-classic-ced03d12",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1318 = {
Expand Down Expand Up @@ -10224,7 +10224,7 @@ var internals$jscomp$inline_1318 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-808eab78"
reconcilerVersion: "18.3.0-www-classic-ced03d12"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1319 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
45 changes: 11 additions & 34 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8196,16 +8196,6 @@ function tryToClaimNextHydratableInstance(fiber) {
return;
}

{
if (!isHydratableType(fiber.type, fiber.pendingProps)) {
// This fiber never hydrates from the DOM and always does an insert
fiber.flags = (fiber.flags & ~Hydrating) | Placement;
isHydrating = false;
hydrationParentFiber = fiber;
return;
}
}

var initialInstance = nextHydratableInstance;
var nextInstance = nextHydratableInstance;

Expand Down Expand Up @@ -34188,7 +34178,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-632e744f";
var ReactVersion = "18.3.0-www-classic-494075fe";

function createPortal$1(
children,
Expand Down Expand Up @@ -42955,20 +42945,6 @@ function clearContainerSparingly(container) {

return;
} // Making this so we can eventually move all of the instance caching to the commit phase.
// inserted without breaking hydration

function isHydratableType(type, props) {
{
if (type === "script") {
var async = props.async,
onLoad = props.onLoad,
onError = props.onError;
return !(async && (onLoad || onError));
}

return true;
}
}
function isHydratableText(text) {
return text !== "";
}
Expand Down Expand Up @@ -43059,21 +43035,22 @@ function canHydrateInstance(instance, type, props, inRootOrSingleton) {
var srcAttr = element.getAttribute("src");

if (
srcAttr &&
element.hasAttribute("async") &&
!element.hasAttribute("itemprop")
) {
// This is an async script resource
break;
} else if (
srcAttr !== (anyProps.src == null ? null : anyProps.src) ||
element.getAttribute("type") !==
(anyProps.type == null ? null : anyProps.type) ||
element.getAttribute("crossorigin") !==
(anyProps.crossOrigin == null ? null : anyProps.crossOrigin)
) {
// This script is for a different src
break;
// This script is for a different src/type/crossOrigin. It may be a script resource
// or it may just be a mistmatch
if (
srcAttr &&
element.hasAttribute("async") &&
!element.hasAttribute("itemprop")
) {
// This is an async script resource
break;
}
}

return element;
Expand Down
45 changes: 11 additions & 34 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -8137,16 +8137,6 @@ function tryToClaimNextHydratableInstance(fiber) {
return;
}

{
if (!isHydratableType(fiber.type, fiber.pendingProps)) {
// This fiber never hydrates from the DOM and always does an insert
fiber.flags = (fiber.flags & ~Hydrating) | Placement;
isHydrating = false;
hydrationParentFiber = fiber;
return;
}
}

var initialInstance = nextHydratableInstance;
var nextInstance = nextHydratableInstance;

Expand Down Expand Up @@ -34033,7 +34023,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-c632da18";
var ReactVersion = "18.3.0-www-modern-88494b05";

function createPortal$1(
children,
Expand Down Expand Up @@ -43465,20 +43455,6 @@ function clearContainerSparingly(container) {

return;
} // Making this so we can eventually move all of the instance caching to the commit phase.
// inserted without breaking hydration

function isHydratableType(type, props) {
{
if (type === "script") {
var async = props.async,
onLoad = props.onLoad,
onError = props.onError;
return !(async && (onLoad || onError));
}

return true;
}
}
function isHydratableText(text) {
return text !== "";
}
Expand Down Expand Up @@ -43569,21 +43545,22 @@ function canHydrateInstance(instance, type, props, inRootOrSingleton) {
var srcAttr = element.getAttribute("src");

if (
srcAttr &&
element.hasAttribute("async") &&
!element.hasAttribute("itemprop")
) {
// This is an async script resource
break;
} else if (
srcAttr !== (anyProps.src == null ? null : anyProps.src) ||
element.getAttribute("type") !==
(anyProps.type == null ? null : anyProps.type) ||
element.getAttribute("crossorigin") !==
(anyProps.crossOrigin == null ? null : anyProps.crossOrigin)
) {
// This script is for a different src
break;
// This script is for a different src/type/crossOrigin. It may be a script resource
// or it may just be a mistmatch
if (
srcAttr &&
element.hasAttribute("async") &&
!element.hasAttribute("itemprop")
) {
// This is an async script resource
break;
}
}

return element;
Expand Down
Loading

0 comments on commit 650431a

Please sign in to comment.