Description
This issue is automatically created based on existing pull request: #31933: Do not send an ajax request if there no affected sections
Description (*)
In the customer data, we have a handler for all ajax requests. If we have some custom JS that sends POST, PUT or DELETE request, it tries to send a request to the backend to reload affected sections. As we had such a request by some tracking - these requests caused an additional request to the backend on all the pages that caused a significant load to the servers.
In case if there are no affected sections, it is still sending requests to the backend.
We got this issue when we created a mixin to the getAffectedSections
for Magento_Customer/js/section-config
and returning an empty array for our custom URL (request is sent not to Magento, so it can't affect any Magento sections).
Related Pull Requests
Fixed Issues (if relevant)
- Fixes magento/magento2#<issue_number>
Manual testing scenarios (*)
- Open app/code/Magento/Customer/view/frontend/web/js/section-config.js
- at the beginning of the
getAffectedSections
method add following code in console:
if (typeof url === 'string' && url.indexOf('my-url-not-affecting-sections') !== -1) {
return [];
}
3. Open frontend
4. open developer tools, execute following JS:
jQuery.post('/my-url-not-affecting-sections');
- Go to the "network" tab in the developer tools, review the list of requests
Actual result:
❌ request for reloading customer sections was sent to the backend
Expected result
✔ request for reloading customer sections shouldn't be sent to the backend
Questions or comments
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)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status