Skip to content

Commit

Permalink
bug #22300 [WebProfiler] Fix race condition in fast Ajax requests (cu…
Browse files Browse the repository at this point in the history
…rry684)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[WebProfiler] Fix race condition in fast Ajax requests

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22297
| License       | MIT

Patch `startAjaxRequest` and `finishAjaxRequest` functions to absolute noop in case the debug toolbar itself is not loaded yet, and spool historic requests after the toolbar is loaded.

Commits
-------

538a592 [WebProfiler] Fix race condition in fast Ajax requests
  • Loading branch information
fabpot committed Apr 5, 2017
2 parents 54495b2 + 538a592 commit 2a40b6f
Showing 1 changed file with 14 additions and 5 deletions.
Expand Up @@ -117,16 +117,16 @@
};
var startAjaxRequest = function(index) {
var request = requestStack[index];
pendingRequests++;
var row = document.createElement('tr');
request.DOMNode = row;
var tbody = document.querySelector('.sf-toolbar-ajax-request-list');
if (!tbody) {
return;
}
var request = requestStack[index];
pendingRequests++;
var row = document.createElement('tr');
request.DOMNode = row;
var methodCell = document.createElement('td');
methodCell.textContent = request.method;
row.appendChild(methodCell);
Expand Down Expand Up @@ -171,6 +171,9 @@
var finishAjaxRequest = function(index) {
var request = requestStack[index];
if (!request.DOMNode) {
return;
}
pendingRequests--;
var row = request.DOMNode;
/* Unpack the children from the row */
Expand Down Expand Up @@ -356,6 +359,12 @@
el.innerHTML = xhr.responseText;
el.setAttribute('data-sfurl', url);
removeClass(el, 'loading');
for (var i = 0; i < requestStack.length; i++) {
startAjaxRequest(i);
if (requestStack[i].duration) {
finishAjaxRequest(i);
}
}
(onSuccess || noop)(xhr, el);
},
function(xhr) { (onError || noop)(xhr, el); },
Expand Down

0 comments on commit 2a40b6f

Please sign in to comment.