Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/browser-sandbox/pruneNonCriticalSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ export default function pruneNonCriticalSelectors ({
// temporarily force clear none in order to catch elements that clear previous
// content themselves and who w/o their styles could show up unstyled in above
// the fold content (if they rely on f.e. 'clear:both;' to clear some main content)
var originalClearStyle = element.style.clear || ''
element.style.clear = 'none'

// but do that only if elements have their style attribute defined
// (ref: https://github.com/pocketjoso/penthouse/issues/342)
const isElementStyleDefined = typeof element.style !== 'undefined'
if (isElementStyleDefined) {
var originalClearStyle = element.style.clear || ''
element.style.clear = 'none'
}

var aboveFold = element.getBoundingClientRect().top < h
// cache so we dont have to re-query DOM for this value
isElementAboveFoldCache.set(element, aboveFold)

// set clear style back to what it was
element.style.clear = originalClearStyle
if (isElementStyleDefined) {
// set clear style back to what it was
element.style.clear = originalClearStyle
}

// Should not be needed anymore with Chrome Headless:
// do some monitoring before complete removing the code (below)
Expand Down