Skip to content

[Issue] Do not send an ajax request if there no affected sections #31948

Closed
@m2-assistant

Description

@m2-assistant

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)

  1. Fixes magento/magento2#<issue_number>

Manual testing scenarios (*)

  1. Open app/code/Magento/Customer/view/frontend/web/js/section-config.js
  2. 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 [];
            }

image
3. Open frontend
4. open developer tools, execute following JS:

jQuery.post('/my-url-not-affecting-sections');
  1. Go to the "network" tab in the developer tools, review the list of requests

Actual result:
image
❌ request for reloading customer sections was sent to the backend

Expected result
image
✔ 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

Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P1Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S1Affects critical data or functionality and forces users to employ a workaround.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions