Skip to content

[MWPW-204799] - Perf: debounce resize handler and cache sticky-top read in comparison… - #6502

Open
DKos95 wants to merge 3 commits into
sr-perf-ddfrom
sr-perf-dd-comparison-table-c2
Open

[MWPW-204799] - Perf: debounce resize handler and cache sticky-top read in comparison…#6502
DKos95 wants to merge 3 commits into
sr-perf-ddfrom
sr-perf-dd-comparison-table-c2

Conversation

@DKos95

@DKos95 DKos95 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What/why

  • The resize listener called removeCollapsed() synchronously on every event; batched into a single requestAnimationFrame per resize burst to avoid redundant layout work.
  • getStickyTop() (a getComputedStyle call) ran on every scroll event even though the value only changes when syncTop() runs (nav height/breakpoint change). Cached it and only refresh on syncTop().
  • Swapped the block-local getNavHeight() calculation for the shared getGnavHeight() utility from global-navigation/utilities.js, so it stays consistent with the rest of the codebase instead of maintaining a duplicate nav-height calc.

Resolves: MWPW-204799

Test URLs:

Dusan Kosanovic added 2 commits August 18, 2026 19:45
…-table-c2

Batches resize-triggered layout work into a single rAF and avoids a
getComputedStyle read on every scroll event. Uses the shared
getGnavHeight() utility instead of a block-local nav-height calculation.
The sticky element is the outer header, not the nav inside it (per
MWPW-201841 / PR #6347's getGnavHeight fix). The ResizeObserver was
still targeting header > nav, so nav-height resync could miss size
changes on the actual sticky element.
@DKos95
DKos95 requested a review from a team August 18, 2026 18:07
@aem-code-sync

aem-code-sync Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@NadiiaSokolova
NadiiaSokolova requested a review from a team August 19, 2026 14:28
@@ -1,5 +1,6 @@
import { createTag, getConfig, loadStyle } from '../../../utils/utils.js';
import { getMetadata as getSectionMetadata } from '../section-metadata/section-metadata.js';
import { getGnavHeight } from '../../../blocks/global-navigation/utilities/utilities.js';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've seen the need of measuring gnavHeight in many places and will likely see more, so instead of importing it from the global-navigation block, should we move it to some higher-level util files? We also have the css variables in c2 styles sheet (stage branch, not in site-redesign-foundation branch yet), so maybe in the future we need to consolidate a bit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I think once we merge stage into site-redesign-foundation we'll have access to that CSS token, which should help.


const nav = document.querySelector('header > nav') ?? document.querySelector('header');
if (nav) new ResizeObserver(syncTop).observe(nav);
const header = document.querySelector('header');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the Promo-aside changes trigger a resync?

The height calc includes .feds-promo-aside-wrapper, but the ResizeObserver only watches <header>, and promo-aside height changes don't resize the header box.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promo is not in the header element, also it vanishes once you start scrolling so really it shouldn't be taken into account seeing as it doesn't occupy space.

// breakpoint change) — it's a static CSS value the rest of the time, not
// something that needs a fresh getComputedStyle read on every scroll
// event. Cache it here and refresh only when syncTop() actually runs.
let stickyTopCache = getStickyTop();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is read synchronously at setup, before syncTop() has ever set --ct-nav-height, so it can resolve to 0 on a scroll event that lands early (e.g., scroll restoration, hash-jump). The old per-scroll getComputedStyle read self-healed instantly. The new cache doesn't until a resize/breakpoint event reruns syncTop().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice catch, thanks for the review!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to match feedback.

@rgclayton

Copy link
Copy Markdown
Contributor

Not related to this PR but leaving some notes from Claude about utlities.js for later reference if needed.

  1. Crash risk (utilities.js:970) — getGnavHeight() reads .feds-localnav.offsetHeight with no null-check. A page where isLocalNav() is true but the local-nav element hasn't rendered yet throws a TypeError inside a listener that fires for the page's whole life, permanently killing the collapsing-header feature.
  2. Local-nav math is wrong (utilities.js:969) — on mobile with local-nav active, the helper replaces the main header height with the local-nav height instead of adding them, even though both bars are stacked and visible simultaneously per gnav's own CSS. Undercounts --ct-nav-height, causing overlap.

@narcis-radu
narcis-radu requested a review from rgclayton August 20, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants