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

MWPW-161625: fix mas:pending event on requestUpdate #3388

Open
wants to merge 9 commits into
base: stage
Choose a base branch
from

Conversation

3ch023
Copy link
Contributor

@3ch023 3ch023 commented Dec 17, 2024

when requestUpdate on MAS inline-price or checkout-link is called the 'mas:resolved' event is dispatched twice.
this PR is fixing first event to be 'mas:pending' and it is followed by a single 'mas:resolved' or 'mas:failed'

added nala tests to cover this too.

Test URLs:

Copy link
Contributor

aem-code-sync bot commented Dec 17, 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 Dec 17, 2024

Page Scores Audits Google
📱 /?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.46%. Comparing base (c582faa) to head (13cc5b1).

Additional details and impacted files
@@           Coverage Diff           @@
##            stage    #3388   +/-   ##
=======================================
  Coverage   96.45%   96.46%           
=======================================
  Files         255      255           
  Lines       59420    59402   -18     
=======================================
- Hits        57314    57301   -13     
+ Misses       2106     2101    -5     

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice 👍

name: '@MAS-DOCS-checkout-link',
path: '/libs/features/mas/docs/checkout-link.html',
browserParams: '?theme=dark',
tags: '@mas-docs @checkout-link @commerce @smoke @regression @milo',
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need mas- prefix for the tags?

Copy link
Contributor Author

@3ch023 3ch023 Dec 18, 2024

Choose a reason for hiding this comment

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

i will ask @afmicka
i have a feeling that these tags should be unique for whole milo repo, so if we want an ability to run only our mas docs tests - then it should be @mas-docs, if we want to run 'all' docs - @docs
i am not sure which it should be

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, those tags are global, and docs would be ambiguous

@@ -153,6 +153,8 @@ export class MasElement {
this.state = STATE_FAILED;
this.update();
this.log?.error('Failed:', { element: this.wrapperElement, error });
// Allow calling code to perform sync updates of this element
// before notifying observers about state change
Copy link
Contributor

Choose a reason for hiding this comment

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

actually, setImmediate is deprecated, should we try it with setTimeout(callback, 0) by this occasion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i refactored it to just call notify function where we need to call it.. imo this thread breaks are making comprehension harder

@@ -166,7 +168,8 @@ export class MasElement {
if (options) this.options = options;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if you can listen the very first mas:pending event.
If you try to register an even listener for a <span is="price" data-wcs-osi="xyz">/span>, it is possible that, the pending event will be dispatched before you register.
To check. I would really remove pending all together, and consider the default state as pending.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed it, agree it's an unnessary event

Copy link
Contributor

Choose a reason for hiding this comment

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

i would somewhere here though add some debug log to mention that element is pending resolution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, thx

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Copy link
Contributor

This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.

selectOffers(await promise, options),
options,
version,
);
this.masElement.notify();
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic is handled at mas-element level(*), the custom elements (we may have more in the future) should not know how / when to notify.

(*) https://github.com/adobecom/milo/pull/3388/files#diff-b76179f008b9c485066e722d9e2b9265ccdbfe9d5abb33507d5ab8424e7a45b5L207-L219

Copy link
Contributor Author

@3ch023 3ch023 Dec 19, 2024

Choose a reason for hiding this comment

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

got it, i moved it back into mas-element

@@ -162,13 +162,15 @@ export class CheckoutLink extends HTMLAnchorElement {
{ ...extraOptions, ...options },
this,
);
return this.renderOffers(
const result = this.renderOffers(
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as for inline-price

@@ -166,7 +168,8 @@ export class MasElement {
if (options) this.options = options;
this.state = STATE_PENDING;
this.update();
setImmediate(() => this.notify());
// immediately notify observers about state change
this.notify();
Copy link
Contributor

Choose a reason for hiding this comment

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

couldn't we even remove notification for pending state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did that, thx

@@ -166,7 +168,8 @@ export class MasElement {
if (options) this.options = options;
Copy link
Contributor

Choose a reason for hiding this comment

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

i would somewhere here though add some debug log to mention that element is pending resolution

name: '@MAS-DOCS-checkout-link',
path: '/libs/features/mas/docs/checkout-link.html',
browserParams: '?theme=dark',
tags: '@mas-docs @checkout-link @commerce @smoke @regression @milo',
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, those tags are global, and docs would be ambiguous

@@ -148,6 +148,7 @@ export class MasElement {
if (options) this.options = options;
this.state = STATE_PENDING;
this.update();
this.log?.debug('Pending:', { element: this.wrapperElement });
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this has any performance impact, this it needs to kind of serialize the wrapperElement.

Copy link
Contributor

@yesil yesil left a comment

Choose a reason for hiding this comment

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

nala tests failing?

Copy link
Contributor

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

@Roycethan
Copy link

Verified, Regressions covered

@Roycethan Roycethan added verified PR has been E2E tested by a reviewer Ready for Stage labels Dec 20, 2024
@milo-pr-merge
Copy link
Contributor

milo-pr-merge bot commented Jan 2, 2025

Skipped 3388: "MWPW-161625: fix mas:pending event on requestUpdate" due to file "libs/deps/mas/commerce.js" overlap. Merging will be attempted in the next batch

@milo-pr-merge
Copy link
Contributor

milo-pr-merge bot commented Jan 7, 2025

Skipped 3388: "MWPW-161625: fix mas:pending event on requestUpdate" due to file "libs/deps/mas/mas.js" overlap. Merging will be attempted in the next batch

@Roycethan
Copy link

@3ch023 Plz resolve conflicts in this PR to merge, thanks

3ch023 added 2 commits January 8, 2025 10:01
# Conflicts:
#	libs/deps/mas/commerce.js
#	libs/deps/mas/mas.js
#	libs/deps/mas/merch-card-collection.js
#	libs/deps/mas/merch-sidenav.js
#	libs/deps/mas/merch-subscription-panel.js
#	libs/features/mas/dist/mas.js
@milo-pr-merge
Copy link
Contributor

milo-pr-merge bot commented Jan 9, 2025

Skipped 3388: "MWPW-161625: fix mas:pending event on requestUpdate" due to file "libs/deps/mas/commerce.js" overlap. Merging will be attempted in the next batch

# Conflicts:
#	libs/deps/mas/commerce.js
#	libs/deps/mas/mas.js
#	libs/features/mas/dist/mas.js
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [eslint] reported by reviewdog 🐶
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commerce Ready for Stage verified PR has been E2E tested by a reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants