Skip to content

Commit 8e266c3

Browse files
silverwindzeripath
authored andcommitted
UI: Fix race in update issue labels and assignees (#6194)
Fix #6191 * fix issue update race condition * fix similar race same race when clearing assignee * always load promise polyfill * replace es6-promise with promise-polyfill * move promise-polyfill to <head>
1 parent 4a2e92b commit 8e266c3

File tree

6 files changed

+35
-32
lines changed

6 files changed

+35
-32
lines changed

public/js/index.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,19 @@ function initBranchSelector() {
216216
});
217217
}
218218

219-
function updateIssuesMeta(url, action, issueIds, elementId, afterSuccess) {
220-
$.ajax({
221-
type: "POST",
222-
url: url,
223-
data: {
224-
"_csrf": csrf,
225-
"action": action,
226-
"issue_ids": issueIds,
227-
"id": elementId
228-
},
229-
success: afterSuccess
219+
function updateIssuesMeta(url, action, issueIds, elementId) {
220+
return new Promise(function(resolve) {
221+
$.ajax({
222+
type: "POST",
223+
url: url,
224+
data: {
225+
"_csrf": csrf,
226+
"action": action,
227+
"issue_ids": issueIds,
228+
"id": elementId
229+
},
230+
success: resolve
231+
})
230232
})
231233
}
232234

@@ -348,6 +350,10 @@ function uploadFile(file, callback) {
348350
xhr.send(formData);
349351
}
350352

353+
function reload() {
354+
window.location.reload();
355+
}
356+
351357
function initImagePaste(target) {
352358
target.each(function(i, field) {
353359
field.addEventListener('paste', function(event){
@@ -385,18 +391,20 @@ function initCommentForm() {
385391
$('.' + selector).dropdown('setting', 'onHide', function(){
386392
hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var
387393
if (hasLabelUpdateAction) {
394+
var promises = [];
388395
for (var elementId in labels) {
389396
if (labels.hasOwnProperty(elementId)) {
390397
var label = labels[elementId];
391-
updateIssuesMeta(
398+
var promise = updateIssuesMeta(
392399
label["update-url"],
393400
label["action"],
394401
label["issue-id"],
395402
elementId
396403
);
404+
promises.push(promise);
397405
}
398406
}
399-
location.reload();
407+
Promise.all(promises).then(reload);
400408
}
401409
});
402410

@@ -479,8 +487,7 @@ function initCommentForm() {
479487
"clear",
480488
$listMenu.data('issue-id'),
481489
""
482-
);
483-
$listMenu.data('action', 'update'); // Update to reload the page when we updated items
490+
).then(reload);
484491
}
485492

486493
$(this).parent().find('.item').each(function () {
@@ -518,9 +525,8 @@ function initCommentForm() {
518525
$menu.data('update-url'),
519526
"",
520527
$menu.data('issue-id'),
521-
$(this).data('id'),
522-
function() { location.reload(); }
523-
);
528+
$(this).data('id')
529+
).then(reload);
524530
}
525531
switch (input_id) {
526532
case '#milestone_id':
@@ -545,9 +551,8 @@ function initCommentForm() {
545551
$menu.data('update-url'),
546552
"",
547553
$menu.data('issue-id'),
548-
$(this).data('id'),
549-
function() { location.reload(); }
550-
);
554+
$(this).data('id')
555+
).then(reload);
551556
}
552557

553558
$list.find('.selected').html('');
@@ -801,7 +806,7 @@ function initRepository() {
801806
function (data) {
802807
$editInput.val(data.title);
803808
$issueTitle.text(data.title);
804-
location.reload();
809+
reload();
805810
});
806811
return false;
807812
});
@@ -1786,7 +1791,7 @@ function u2fRegistered(resp) {
17861791
data: JSON.stringify(resp),
17871792
contentType: "application/json; charset=utf-8",
17881793
success: function(){
1789-
window.location.reload();
1794+
reload();
17901795
},
17911796
fail: function (xhr, textStatus) {
17921797
u2fError(1);
@@ -2073,9 +2078,7 @@ $(document).ready(function () {
20732078
return this.dataset.issueId;
20742079
}).get().join();
20752080
var url = this.dataset.url
2076-
updateIssuesMeta(url, action, issueIDs, elementId, function() {
2077-
location.reload();
2078-
});
2081+
updateIssuesMeta(url, action, issueIDs, elementId).then(reload);
20792082
});
20802083

20812084
buttonsClickOnEnter();
@@ -2912,7 +2915,7 @@ function updateDeadline(deadlineString) {
29122915
contentType: 'application/json',
29132916
type: 'POST',
29142917
success: function () {
2915-
window.location.reload();
2918+
reload();
29162919
},
29172920
error: function () {
29182921
$('#deadline-loader').removeClass('loading');

public/vendor/librejs.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@
146146
<td><a href="https://github.com/moment/moment/archive/2.22.2.tar.gz">0.4.1.tar.gz</a></td>
147147
</tr>
148148
<tr>
149-
<td><a href="./plugins/es6-promise/">es6-promise</a></td>
150-
<td><a href="https://github.com/stefanpenner/es6-promise/blob/master/LICENSE">MIT</a></td>
151-
<td><a href="https://github.com/stefanpenner/es6-promise/archive/v4.2.6.tar.gz">4.2.6.tar.gz</a></td>
149+
<td><a href="./plugins/promise-polyfill/">promise-polyfill</a></td>
150+
<td><a href="https://github.com/taylorhakes/promise-polyfill/blob/master/LICENSE">MIT</a></td>
151+
<td><a href="https://github.com/taylorhakes/promise-polyfill/archive/8.1.0.tar.gz">8.1.0.tar.gz</a></td>
152152
</tr>
153153
</tbody>
154154
</table>

public/vendor/plugins/es6-promise/es6-promise.auto.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/vendor/plugins/promise-polyfill/polyfill.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/base/footer.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
<script src="{{AppSubUrl}}/vendor/plugins/semantic/semantic.min.js"></script>
123123
<script src="{{AppSubUrl}}/js/index.js?v={{MD5 AppVer}}"></script>
124124
{{if .EnableHeatmap}}
125-
<script src="{{AppSubUrl}}/vendor/plugins/es6-promise/es6-promise.auto.min.js" charset="utf-8"></script>
126125
<script src="{{AppSubUrl}}/vendor/plugins/moment/moment.min.js" charset="utf-8"></script>
127126
<script src="{{AppSubUrl}}/vendor/plugins/vue-calendar-heatmap/vue-calendar-heatmap.browser.js" charset="utf-8"></script>
128127
<script type="text/javascript">

templates/base/head.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
{{end}}
124124
<style class="list-search-style"></style>
125125

126+
<script src="{{AppSubUrl}}/vendor/plugins/promise-polyfill/polyfill.min.js"></script>
126127
<script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/loadCSS.min.js"></script>
127128
<script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/cssrelpreload.min.js"></script>
128129
{{if .PageIsUserProfile}}

0 commit comments

Comments
 (0)