Last active
June 18, 2023 10:11
-
-
Save noamr/45953448b22cf19f063bc67a3e3d1478 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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