Skip to content

Commit

Permalink
Explain the perf issue
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Nov 30, 2023
1 parent 974fd2c commit f15a92f
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function getElementsPositionInDocument(el: Element) {
let fixed = false;
let current: Element | ParentNode | null = el;
while (current instanceof Element) {
// This is the expensive part, we are calling getComputedStyle which triggers layout
// all the way up the tree. We are only doing so when the app initializes, so the cost is one-time
// If perf becomes an issue we'll want to refactor this somehow so that it reads this info in a rAF
let style = getComputedStyle(current);
let zIndex = Number(style.zIndex);
if (!Number.isNaN(zIndex) && zIndex > highestZIndex) {
Expand Down

0 comments on commit f15a92f

Please sign in to comment.