Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modal] Dedup Ongoing Dialogs for Same Fragment #2594

Merged
merged 2 commits into from
Jul 22, 2024
Merged

Conversation

JingleH
Copy link
Contributor

@JingleH JingleH commented Jul 18, 2024

There exists a race condition that when the same modal hashes appear multiple times on the page, the same fragment could be loaded more than once. More specifically, after the hash change, there is a period when getModal() needs to fetch its content but the dialog-modal hasn't been appended to document yet. If another modal on the page gets its init() called (via section preloadLinks) during this period, all the early-exit safeguard in init() we currently have will fail. This PR aims to cover this condition by keeping track of what dialogs are being loaded but not yet appended.

How to reproduce:
Locally or using overrides, in modal.js, you can fake a longer getPathModal() call by making it into something like await Promise.all([getPathModal(details.path, dialog), new Promise((r) => setTimeout(r, 4000))]);. Then to delay the second modal, either throw in more content, or just manually make it slower by making init() async and adding if (document.querySelector('a.modal') !== el) { await new Promise((r) => setTimeout(r, 2000))} to the beginning. Then clicking the primary CTA should make the FaaS fragment start overwriting itself and acting weird.

Resolves: https://jira.corp.adobe.com/browse/MWPW-147304

Test URLs:

Copy link
Contributor

aem-code-sync bot commented Jul 18, 2024

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

Copy link
Contributor

aem-code-sync bot commented Jul 18, 2024

Page Scores Audits Google
/drafts/jinglhua/modal?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@JingleH JingleH added the bug Something isn't working label Jul 18, 2024
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.86%. Comparing base (31c21e8) to head (59a1cc4).

Additional details and impacted files
@@           Coverage Diff           @@
##            stage    #2594   +/-   ##
=======================================
  Coverage   95.86%   95.86%           
=======================================
  Files         176      176           
  Lines       46211    46215    +4     
=======================================
+ Hits        44300    44304    +4     
  Misses       1911     1911           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@skumar09 skumar09 added the run-nala Run Nala Test Automation against PR label Jul 18, 2024
Copy link
Contributor

@mokimo mokimo left a comment

Choose a reason for hiding this comment

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

Not sure why this is a draft PR, but looks good to me. I'd love to see a unit test for this case

libs/blocks/modal/modal.js Outdated Show resolved Hide resolved
Co-authored-by: Okan Sahin <39759830+mokimo@users.noreply.github.com>
@JingleH
Copy link
Contributor Author

JingleH commented Jul 19, 2024

Not sure why this is a draft PR, but looks good to me. I'd love to see a unit test for this case

Something else came up yesterday while I was reading the PR description 🥲 so I didn't get to finish it... I planned to record a video to reproduce the issue, but if @mokimo agrees that it's trivial enough, I am happy to not do that 🥺 I am going to open it up and ask for more approvals. Thanks, Okan!

@JingleH JingleH marked this pull request as ready for review July 19, 2024 17:17
Copy link
Contributor

Reminder to set the Ready for Stage label - to queue this to get merged to stage & production.

Copy link
Contributor

@vhargrave vhargrave left a comment

Choose a reason for hiding this comment

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

looks good!

@@ -246,6 +249,7 @@ export function delayedModal(el) {
export default function init(el) {
const { modalHash } = el.dataset;
if (delayedModal(el) || window.location.hash !== modalHash || document.querySelector(`div.dialog-modal${modalHash}`)) return null;
if (dialogLoadingSet.has(modalHash?.replace('#', ''))) return null; // prevent duplicate modal loading
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: to save some bytes you could add this as an or || to the upper condition. That way we only have code to return null once if any of the conditions are met.

@milo-pr-merge milo-pr-merge bot merged commit 0f3f4b8 into stage Jul 22, 2024
18 checks passed
@milo-pr-merge milo-pr-merge bot deleted the modal-dedup branch July 22, 2024 15:12
@milo-pr-merge milo-pr-merge bot mentioned this pull request Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Ready for Stage run-nala Run Nala Test Automation against PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants