Skip to content

Commit 538a592

Browse files
committed
[WebProfiler] Fix race condition in fast Ajax requests
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. Fixes symfony#22297
1 parent 958b0ae commit 538a592

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@
117117
};
118118
119119
var startAjaxRequest = function(index) {
120-
var request = requestStack[index];
121-
pendingRequests++;
122-
var row = document.createElement('tr');
123-
request.DOMNode = row;
124-
125120
var tbody = document.querySelector('.sf-toolbar-ajax-request-list');
126121
if (!tbody) {
127122
return;
128123
}
129124
125+
var request = requestStack[index];
126+
pendingRequests++;
127+
var row = document.createElement('tr');
128+
request.DOMNode = row;
129+
130130
var methodCell = document.createElement('td');
131131
methodCell.textContent = request.method;
132132
row.appendChild(methodCell);
@@ -171,6 +171,9 @@
171171
172172
var finishAjaxRequest = function(index) {
173173
var request = requestStack[index];
174+
if (!request.DOMNode) {
175+
return;
176+
}
174177
pendingRequests--;
175178
var row = request.DOMNode;
176179
/* Unpack the children from the row */
@@ -356,6 +359,12 @@
356359
el.innerHTML = xhr.responseText;
357360
el.setAttribute('data-sfurl', url);
358361
removeClass(el, 'loading');
362+
for (var i = 0; i < requestStack.length; i++) {
363+
startAjaxRequest(i);
364+
if (requestStack[i].duration) {
365+
finishAjaxRequest(i);
366+
}
367+
}
359368
(onSuccess || noop)(xhr, el);
360369
},
361370
function(xhr) { (onError || noop)(xhr, el); },

0 commit comments

Comments
 (0)