-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 customer data race condition when bundling is enabled #23099
fix customer data race condition when bundling is enabled #23099
Conversation
Hi @davidverholen. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
09ad7ea
to
02d3b50
Compare
Thank you for taking the initiative on this at the Hackathon! Will be reviewing as soon as I'm back from travel (possibly sooner) |
02d3b50
to
fe6ef1b
Compare
Sorry for the delays, and thanks for doing the hard work! For future readers, want to make sure we're documenting the exact problem we're trying to solve in this PR. Currently, An exported property with the name Unfortunately, there are other APIs exposed from So basically, this problem is temporal coupling. |
re: the fix, I assume you (and most others) know this section of the code better than me. Can you help me understand what the situations are will this code will break down? Basically, I assume we didn't hard code the |
Awesome! @davidverholen fix worked like a charm. Thanks! |
@DrewML the url is static ( / defined in module code) so it should not be a problem to hardcode it (it is already hardcoded like this in php view code / in the block anyway) When a customer section is updated (for example adding a product to the cart) a function in the customer-data.js is called to reload the respective customer section from the backend. This call can also happen directly after a site reload (e.g. when not using an ajax call to add a product to cart). The options object is initialized in the body by the mage-init script while the ajax call is executed at some point when all dependencies are loaded (and I think you mentioned that it even is blocked until all js is loaded on the page). When the js is not bundled, it takes a huge amount of time to get to this point so the options object is mostly already initialized. When the js is bundled and minified, the customer section update is triggered before the initialization of the options object. The function then crashes with an error because it relies on options.sectionLoadUrl to execute the call |
There is probably a larger fix we could make here to just eliminate the race, BUT this at least gets us from a place where things fail for shoppers to a place where things should mostly succeed, and without breaking changes, so it's a 👍 from me. Thanks again |
Hi @kalpmehta, thank you for the review.
|
✔️ QA passed |
Hi @davidverholen, thank you for your contribution! |
Description (*)
when using advanced bundling there is a race condition leading to an error where options.sectionLoadUrl is undefined when customer data tries to retrieve sections from the server.
This has already lead to several issues with mostly different context but the same base problem: the options object is initialized as x-magento-init script in a phtml file which is not always executed fast enough (for example if you use the advanced bundling).
A fix for that will also be mandatory for tools that automate an advanced bundling mechanism (/cc @DrewML )
some related tickets that have been closed:
https://github.com/magento/magento2/issues?q=is%3Aissue+sectionLoadUrl+is%3Aclosed
related issue in m2-devtools project:
magento/m2-devtools#56
Manual testing scenarios (*)
-> For example by using: https://github.com/magento/m2-devtools
Contribution checklist (*)