Skip to content

Instantly share code, notes, and snippets.

@noamr
Last active June 18, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noamr/45953448b22cf19f063bc67a3e3d1478 to your computer and use it in GitHub Desktop.
Save noamr/45953448b22cf19f063bc67a3e3d1478 to your computer and use it in GitHub Desktop.
function hasPendingIncomingTransition() { }
function isRenderBlocked() { }
function continueIncomingTransition() { }
let hasSeenFold = false;
let lastFoldCheckTime = performance.now();
const FoldCheckThrolttle = 100;
function didSeeFold() {
if (hasSeenFold || !hasPendingIncomingTransition())
return;
hasSeenFold = true;
if (!isRenderBlocked())
continueIncomingTransition();
}
function onRenderUnblocked() {
if (hasSeenFold)
continueIncomingTransition();
}
function onDOMContentLoaded() {
didSeeFold();
}
function onParserYield() {
if (!hasPendingIncomingTransition || hasSeenFold)
return;
const now = performance.now();
if (now < (lastFoldCheckTime + FoldCheckThrolttle)
return;
computeStyle();
layout();
// In the future: consider adding something explicit rather than this heuristic
if (elements.some(element => element.clientTop > toPixels("200vh"))) {
didSeeFold();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment