Skip to content

Commit f05a46c

Browse files
committed
Implement fundamental Build Now race fix using DOMContentLoaded
1 parent 665e565 commit f05a46c

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

core/src/main/java/hudson/Functions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ public static boolean useHidingPasswordFields() {
448448
return SystemProperties.getBoolean(Functions.class.getName() + ".hidingPasswordFields", true);
449449
}
450450

451+
/**
452+
* Toggles whether to use the DOMContentLoaded event instead of window.onload for behavior script initialization.
453+
* @since TODO
454+
*/
455+
@Restricted(NoExternalUse.class)
456+
public static boolean getUseDOMContentLoaded() {
457+
return SystemProperties.getBoolean(Functions.class.getName() + ".useDOMContentLoaded", true);
458+
}
459+
451460
/**
452461
* URL decomposed for easier computation of relevant URLs.
453462
*

core/src/main/resources/lib/hudson/project/configurable.jelly

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ THE SOFTWARE.
2929

3030
<j:if test="${!newJobPage}">
3131
<j:if test="${it.buildable}">
32-
<st:adjunct includes="lib.hudson.project.configurable.configurable"/>
33-
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" permission="${it.BUILD}" post="${!it.parameterized}" data-callback="lib_hudson_project_configurable_build_now_callback" data-build-failure="${%buildFailed}" data-build-success="${%Build scheduled}" data-parameterized="${it.parameterized}" title="${it.buildNowText}"/>
32+
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" permission="${it.BUILD}" post="${!it.parameterized}" data-task-failure="${%buildFailed}" data-task-success="${%Build scheduled}" title="${it.buildNowText}"/>
3433
</j:if>
3534
<j:choose>
3635
<j:when test="${h.hasPermission(it,it.CONFIGURE)}">

core/src/main/resources/lib/layout/layout.jelly

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ THE SOFTWARE.
105105
<head data-rooturl="${rootURL}" data-resurl="${resURL}" data-imagesurl="${imagesURL}" resURL="${resURL}"
106106
data-extensions-available="${extensionsAvailable}"
107107
data-crumb-header="${h.getCrumbRequestField()}" data-crumb-value="${h.getCrumb(request2)}"
108-
data-unit-test="${h.isUnitTest}">
108+
data-unit-test="${h.isUnitTest}"
109+
data-use-dom-content-loaded="${h.getUseDOMContentLoaded()}">
109110
${h.checkPermission(it,permission)}
110111
${h.checkAnyPermission(it, permissions)}
111112

war/src/main/webapp/scripts/behavior.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,17 @@ var Behaviour = (function () {
8181
},
8282

8383
start: function () {
84-
Behaviour.addLoadEvent(function () {
85-
Behaviour.apply();
86-
});
84+
var useDOMContentLoaded =
85+
document.head.getAttribute("data-use-dom-content-loaded") === "true";
86+
if (useDOMContentLoaded && document.addEventListener) {
87+
document.addEventListener("DOMContentLoaded", function () {
88+
Behaviour.apply();
89+
});
90+
} else {
91+
Behaviour.addLoadEvent(function () {
92+
Behaviour.apply();
93+
});
94+
}
8795
},
8896

8997
apply: function () {

0 commit comments

Comments
 (0)