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

Fix customer data and sections configuration race condition #24847

Closed
wants to merge 2 commits into from

Conversation

krzksz
Copy link
Contributor

@krzksz krzksz commented Oct 4, 2019

This pull request aims to fix all issues connected with the fact that the configuration of customer data and its sections is currently being passed through x-magento-init script block.

Description (*)

The majority of information is already provided within #17125 and #23099. Because of the fact that both customer-data.js and section-config.js modules rely on x-magento-init script to initialize them with configuration there are situations in which they can be required and evaluated by other modules before that actually happens which results in multiple errors e.g.:

  • TypeError: sections is undefined
  • Uncaught TypeError: Cannot set property 'sectionLoadUrl' of undefined
  • TypeError: Cannot read property '*' of undefined

My initial idea was to pass mentioned configuration simply via a global variable but then I remembered that RequireJS actually has a build-in mechanism for that https://requirejs.org/docs/api.html#config-moduleconfig which I took advantage of. This pull request also makes changes within #23099 obsolete.

Fixed Issues (if relevant)

  1. x-magento-init initialisation not bound to happen in the right order. #17125: x-magento-init initialisation not bound to happen in the right order.
  2. Magento 2.2.3 TypeErrors Cannot read property 'quoteData' / 'storecode' / 'sectionLoadUrl' of undefined  #14412 Magento 2.2.3 TypeErrors Cannot read property 'quoteData' / 'storecode' / 'sectionLoadUrl' of undefined
  3. Magento 2.1.11 CE ADD TO CART is stuck on ADDING ... #13403 Magento 2.1.11 CE ADD TO CART is stuck on ADDING
  4. cannot read property 'section loadurl' of undefined in all pages - Custom Theme #8628 cannot read property 'section loadurl' of undefined in all pages - Custom Theme

Manual testing scenarios (*)

  1. Reload the shop.
  2. Trigger customer data or sections data module at the very beginning for example by running the following code:
require(['Magento_Customer/js/section-config'], function(sectionsConfig) {
    console.log(sectionsConfig.getAffectedSections('test'));
});
  1. TypeError: sections is undefined is being thrown without this changes.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Oct 4, 2019

Hi @krzksz. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@krzksz
Copy link
Contributor Author

krzksz commented Oct 4, 2019

@magento give me 2.3-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @krzksz. Thank you for your request. I'm working on Magento 2.3-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @krzksz, here is your Magento instance.
Admin access: https://i-24847-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@krzksz
Copy link
Contributor Author

krzksz commented Oct 4, 2019

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @krzksz. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @krzksz, here is your new Magento instance.
Admin access: https://pr-24847.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@sidolov
Copy link
Contributor

sidolov commented Oct 4, 2019

@DrewML could you please take a look at the changes?

@krzksz
Copy link
Contributor Author

krzksz commented Oct 5, 2019 via email

@krzksz
Copy link
Contributor Author

krzksz commented Oct 6, 2019

Ok, it seems that everything is back to normal. Currently the only errors that are left are:

  • Usage of $this in the template to access helper.
  • Inline JavaScript in script tags.

Please @DrewML and @paliarush what I should do with them.

@DrewML
Copy link

DrewML commented Oct 7, 2019

I'm a bit backed up with work at the moment, but tagging in @vzabaznov to try and get a review done. He's done a massive amount of investigation into customer-data problems over the last few weeks.

@vzabaznov vzabaznov self-requested a review October 7, 2019 18:57
@vzabaznov
Copy link
Contributor

Hi @krzksz, thank you for PR.
Dont think using require.config is what we need here, because this will not fix this problem globally.
I believe that better approach here is to use our uiRegistry - https://devdocs.magento.com/guides/v2.3/ui_comp_guide/concepts/ui_comp_uiregistry.html. Can you take a look at it?

@DrewML
Copy link

DrewML commented Oct 8, 2019

Have we checked yet if using require.config is going to work with mixins? In other words, if I want to mixin section-config.js, will module.config() in that mixed-in module be able to obtain the needed data?

@krzksz
Copy link
Contributor Author

krzksz commented Oct 23, 2019

@ya

Hi @krzksz, thank you for PR.
Dont think using require.config is what we need here, because this will not fix this problem globally.
I believe that better approach here is to use our uiRegistry - https://devdocs.magento.com/guides/v2.3/ui_comp_guide/concepts/ui_comp_uiregistry.html. Can you take a look at it?

Hmm, I'm not sure what the actual approach should be, but I'm guessing we should try to provide the information via registry.async as it waits for the component to be initialized. I hope that's what you mean and so I'll try to investigate but I don't really know if it is the best option and what you mean by this will not fix this problem globally. Can you elaborate a bit?

Have we checked yet if using require.config is going to work with mixins? In other words, if I want to mixin section-config.js, will module.config() in that mixed-in module be able to obtain the needed data?

Good point, will check.

@krzksz
Copy link
Contributor Author

krzksz commented Oct 23, 2019

@DrewML

As suspected module.config() inside mixin returns the configuration for that said mixin which means that it would not be possible to customize section or customer data configuration frontend-only without modifying the template. Is it really a problem? Maybe adding another method to update the configuration would be enough?

@vzabaznov I tried to figure it out but I still don't know how uiRegistry could be applied here 🤔

@m2-assistant
Copy link

m2-assistant bot commented Oct 29, 2019

Hi @krzksz, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@krzksz krzksz reopened this Oct 29, 2019
@krzksz
Copy link
Contributor Author

krzksz commented Nov 26, 2019

@magento give me 2.3-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @krzksz. Thank you for your request. I'm working on Magento 2.3-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @krzksz, here is your Magento instance.
Admin access: https://i-24847-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@krzksz
Copy link
Contributor Author

krzksz commented Nov 26, 2019

I am closing this PR because its changes would do more damage then help. I decided to prepare a separate one where I'm covering both section-config and customer-data with unit tests and make sure they do not throw any errors before they are initialized.

@krzksz krzksz closed this Nov 26, 2019
@m2-assistant
Copy link

m2-assistant bot commented Nov 26, 2019

Hi @krzksz, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@ihor-sviziev ihor-sviziev mentioned this pull request Feb 1, 2021
5 tasks
krisdante pushed a commit to magesuite/magento-patches that referenced this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants