Skip to content

Commit 9bd5eda

Browse files
author
Aditya
committed
JENKINS-76241: Minimal fix
1 parent bd474c7 commit 9bd5eda

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

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

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,7 @@ var layoutUpdateCallback = {
27122712

27132713
/**
27142714
* Fix for JENKINS-76241: Prevent POST race condition
2715-
* Apply Behaviour rules synchronously after registration
2715+
* Apply Behaviour rules early - MINIMAL, SAFE VERSION
27162716
*/
27172717
(function () {
27182718
"use strict";
@@ -2722,50 +2722,40 @@ var layoutUpdateCallback = {
27222722
}
27232723
window._jenkinsPostHandlerFixApplied = true;
27242724

2725-
// Apply Behaviour rules immediately
2726-
if (typeof Behaviour !== "undefined" && Behaviour.apply) {
2727-
try {
2728-
Behaviour.apply();
2729-
} catch (e) {
2730-
// Silently ignore - will retry on DOMContentLoaded
2731-
}
2732-
}
2733-
2734-
// Also apply on DOMContentLoaded as backup
2735-
document.addEventListener("DOMContentLoaded", function () {
2725+
// Just apply Behaviour earlier - THAT'S IT
2726+
function applyEarly() {
27362727
if (typeof Behaviour !== "undefined" && Behaviour.apply) {
27372728
try {
27382729
Behaviour.apply();
27392730
} catch (e) {
2740-
// Silently ignore
2731+
// Ignore - will retry on DOMContentLoaded
27412732
}
27422733
}
2743-
});
2734+
}
2735+
2736+
// Apply immediately
2737+
applyEarly();
27442738

2745-
// Watch for dynamically added forms
2739+
// Apply on DOMContentLoaded as backup
2740+
document.addEventListener("DOMContentLoaded", applyEarly);
2741+
2742+
// Watch for new content
27462743
if (typeof MutationObserver !== "undefined") {
27472744
var observer = new MutationObserver(function (mutations) {
2748-
var hasNewForms = false;
2749-
2745+
var needsReapply = false;
27502746
mutations.forEach(function (mutation) {
27512747
mutation.addedNodes.forEach(function (node) {
2752-
if (node.nodeType === 1) {
2753-
if (
2754-
node.tagName === "FORM" ||
2755-
(node.querySelector && node.querySelector("FORM"))
2756-
) {
2757-
hasNewForms = true;
2758-
}
2748+
if (
2749+
node.nodeType === 1 &&
2750+
(node.tagName === "FORM" ||
2751+
(node.querySelector && node.querySelector("FORM")))
2752+
) {
2753+
needsReapply = true;
27592754
}
27602755
});
27612756
});
2762-
2763-
if (hasNewForms && typeof Behaviour !== "undefined" && Behaviour.apply) {
2764-
try {
2765-
Behaviour.apply();
2766-
} catch (e) {
2767-
// Silently ignore
2768-
}
2757+
if (needsReapply) {
2758+
applyEarly();
27692759
}
27702760
});
27712761

0 commit comments

Comments
 (0)