Skip to content

Comments

Hotspot.js: reduce complexity and add DOMpurify#672

Open
helms-charity wants to merge 3 commits intomainfrom
671-hotspotsecurity
Open

Hotspot.js: reduce complexity and add DOMpurify#672
helms-charity wants to merge 3 commits intomainfrom
671-hotspotsecurity

Conversation

@helms-charity
Copy link
Collaborator

@helms-charity helms-charity commented Feb 21, 2026

  • DOMpurify related functions in scripts.js were already merged per scripts.js: Add global DOMpurify functions #673 but are repeated here. They are needed to sanitize document write methods.

  • applied the new sanitizeHTML to the places we were using innerHTML in hotspot.js
    So content from DOM/dataset/contentMap is sanitized both when it’s first read/stored and again when it’s written to innerHTML, which addresses the aikido.dev finding.

  • Reduced nested functions for less complexity and better maintainability.

Summary of what was refactored with regard to nested functions:

  1. runAfterDoubleRAF(fn)
    Single helper that runs fn after two requestAnimationFrame calls, so the “double RAF then run” logic lives in one place.

  2. schedulePadding
    A small function that runs runAfterDoubleRAF(calculateInitialPadding), used both as the image load listener and in the “already loaded” path.

  3. Removed waitForImageAndCalculate
    Replaced with a direct if/else: if the image isn’t loaded yet, register schedulePadding on load; otherwise call runAfterDoubleRAF(calculateInitialPadding) immediately.

  4. fadeTransition (was ~L300)
    Introduced makeFadeInEndHandler() so the transition-end logic is no longer nested inside startFadeIn.
    startFadeIn now only adds the class and attaches the handler returned by makeFadeInEndHandler().
    Kept the double-RAF call as a one-liner: requestAnimationFrame(() => requestAnimationFrame(startFadeIn)).

  5. Go-back link handling (was ~L748 and ~L947)
    Added a shared handleGoBackLinkClick(evt, sectionData, container, reattachListeners) that:
    Reads href and targetId. If no targetId: expands the hero and returns.
    Otherwise loads content from sectionData.contentMap, runs fadeTransition, then calls the passed-in reattachListeners and showInitialPanel.
    Both the initial decorate() setup and reattachHotspotListeners() now do:
    link.addEventListener('click', (evt) => handleGoBackLinkClick(evt, sectionData, container, reattachHotspotListeners)).

Fix #671

Test URLs:

Testing:
There should be no difference in how The Concept animation works.
The low mobile score isn't related to this ticket.

@aem-code-sync
Copy link

aem-code-sync bot commented Feb 21, 2026

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

  • Re-run PSI checks
  • Re-sync branch
Commits

@aem-code-sync aem-code-sync bot temporarily deployed to 671-hotspotsecurity February 21, 2026 18:22 Inactive
@aem-code-sync
Copy link

aem-code-sync bot commented Feb 21, 2026

Page Scores Audits Google
📱 /credit-card/metal-credit-card/mayura PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /credit-card/metal-credit-card/mayura PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@helms-charity helms-charity changed the title reduce complexity and add DOMpurify Hotspot.js: reduce complexity and add DOMpurify Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hotspot: security and maintainability fixes

1 participant