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
Fix race condition when rendering product attributes tab empty state #38354
Fix race condition when rendering product attributes tab empty state #38354
Conversation
Hi @octaedro, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: 2b58151
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
// we've seen some flakiness where the "Used for variations" checkbox is not visible, | ||
// so let's explicitly wait for it to be visible before proceeding | ||
await page | ||
.locator( '#product_attributes' ) | ||
.locator( `input[name="attribute_variation[${ i }]"]` ) | ||
.waitFor( { timeout: 10000 } ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodelgc I added this explicit wait for the "Used for variations" checkbox to help assure us that the underlying issue is fixed. That way, if it is missing, the test will fail with a timeout. Or, do you think we either don't need this at all, or should make this an expect
?
|
||
attribute_row_indexes(); | ||
async function add_attribute_to_list( globalAttributeId ) { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if we will use exception handling, we should add a catch
to this try
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add a catch
because I don't have anything terribly helpful to do at this point, so I figured I'd just let the error bubble up. I did the finally
because because I didn't want to totally lock the UI up in this failure case.
I could put up an alert
... do you think that is good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could put up an alert... do you think that is good enough?
An alert
mentioning the error sounds good to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll make that change and fix the conflicting test file right after lunch and ping you when ready for another review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job @mattsherman! This is testing well here and the code looks good. I just left a small comment.
…dd_custom_attribute_to_list
a759995
to
2b58151
Compare
@octaedro I added the alert. You can test by loading the product screen and then using your browser's dev tools I removed the e2e test change I made, as the e2e tests have been restructured and looking at the new structure of them, I don't see a need to add my check back in. If we happen to have future issues, the existing e2e tests should cover things. Ready for re-review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mattsherman for adding the change. The PR LGTM 🚀
Submission Review Guidelines:
Changes proposed in this Pull Request:
This PR fixes a race condition that could occur when the first (empty) attribute form was automatically added to the attributes tab of the product (the updated empty state from #38126).
Basically, in an environment such as our e2e tests, where the UI interactions occurred very quickly, the new attribute form would be added using a stale value of the product type, resulting in a missing "Used for variations" checkbox. Note that this is very unlikely to be reproducible manually, as humans just aren't that fast when interacting with the UI.
Flow in code that caused issue:
Simple
Variable
by userSimple
to determine if "Used for variations" on the newly added attribute should be shown (thus hiding it)The implementation has been updated to check the product type immediately before showing/hiding control on the new attribute form.
In addition, a number of refactors have been made to make this area of the code simpler and more maintainable, to lessen the chance of similar issues occurring in the future when further changes to the code are made.
There are no visible UI changes introduced in this PR, outside of the fixing of the visibility of the "Used for variations" checkbox.
How to test the changes in this Pull Request:
As this bug was introduced in #38126, the same test instructions from there should be followed (see below).
In addition, general smoke testing surrounding the following should be done:
Common instructions
Products
>Add New
Products
>All Products
Products
>Attributes
Save attributes
button on theAttributes
tabPublish
(orUpdate
, if an existing product)Tools
>WCA Test Helper
>Tools
>Enable wc-admin Tracking
recordevent
in the browser dev consoleNo global attributes in system
Attributes
tabGlobal attributes in system, adding a new local attribute
Attributes
tabGlobal attributes in system, adding a global attribute
Attributes
tabAdd existing
dropdownAdd existing
dropdownEditing an existing product with no attributes
Attributes
tab is shownEditing an existing product with local attributes
Attributes
tab is shownEditing an existing product with global attributes
Attributes
tab is shownTracks events
Add new
should logwcadmin_product_attributes_buttons
withaction: 'add_new'
Add existing
should logwcadmin_product_attributes_buttons
withaction: 'add_existing'
Create value
for a global attribute should logwcadmin_product_attributes_add_term
Error handling
Add new
when offline (or any other server-side error), should show a browser alert message and log the error to the browser console log.