Skip to content

Commit

Permalink
fix: better relying on applied paint state for computing padding on a…
Browse files Browse the repository at this point in the history
…nchor elements
  • Loading branch information
peschee committed Jan 12, 2024
1 parent 0087f25 commit fca9078
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/thick-news-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@inventage-web-components/portal-navigation': patch
---

Instead of relying on two nested `requestAnimationFrame` callbacks to detect when style and layout information have been applied (for computing the `anchor` padding in `sticky` mode), we instead now use `requestAnimationFrame` in combination with `setTimeout`.

This should hopefully give us a more reliable hook into the point in time where the style and layout information have been calculated and the paint has occurred.
7 changes: 4 additions & 3 deletions packages/portal-navigation/src/PortalNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,12 @@ export class PortalNavigation extends LitElement {
this.dispatchEvent(new CustomEvent(NavigationEvents.breakpointChanged, { detail: this.isMobileBreakpoint, composed: true, bubbles: true }));
}

// Wait two paint cycles until CSS styles have been applied…
// This code will be run ASAP after Style and Layout information have been calculated and the paint has occurred.
// @see https://firefox-source-docs.mozilla.org/performance/bestpractices.html
requestAnimationFrame(() => {
requestAnimationFrame(() => {
setTimeout(() => {
this.updateAnchorPaddingWhenStickyInternal();
});
}, 0);
});
}

Expand Down

0 comments on commit fca9078

Please sign in to comment.