Fix unsaved changes warning in new Manage Jenkins UI#26314
Fix unsaved changes warning in new Manage Jenkins UI#26314timja merged 6 commits intojenkinsci:masterfrom
Conversation
|
Yay, your first pull request towards Jenkins core was created successfully! Thank you so much! |
Include lib.form.confirm in settings-subpage.jelly and delay confirm.js initialization until the configuration form is present.
ff54a65 to
6ac2d73
Compare
mawinter69
left a comment
There was a problem hiding this comment.
Without testing myself I assume that the delayed loading in js is sufficient already. If there is a page where it isn't working then I assume it is also not working with the new manage page turned off. So might be good if you can test all pages that use l:settings-subpage. If that is the case then adding the adjunct to that page would be the proper approach I think.
It might also be a valid approach to generally include that unconditionally on l:settings-subpage, then we could remove the adjuncts from all jelly files that use l:settings-subpage.
| permissions="${attrs.permissions}" | ||
| type="${newManageJenkins ? 'two-column' : 'one-column'}"> | ||
|
|
||
| <st:adjunct includes="lib.form.confirm"/> |
There was a problem hiding this comment.
I think it is not 100% correct to include that here. You will find that the pages that use <l:settings-subpage usually already include the adjunct. And frequently conditionally requiring permissions. So when you are in readonly mode you can't modify anything. Please test whether all pages still properly react on page leave when you remove this.
There was a problem hiding this comment.
I tried removing <st:adjunct includes="lib.form.confirm"/> from settings-subpage.jelly and tested the pages using <l:settings-subpage> (Configure System, Security, Appearance).
After removing it, the unsaved changes warning no longer appears in the new Manage Jenkins UI.
With the adjunct included at the layout level, the warning behaves as expected.
From my testing it seems that lib.form.confirm is not consistently included by all pages rendered via <l:settings-subpage>, so including it here ensures consistent dirty-form tracking.
There was a problem hiding this comment.
the adjunct is included in the global config page, but I think due to the deferred loading, the load event has already happened and so the js can't hook into the change events in the form.
I added an load event listener in hudson-behavior.js that logs when the load event was called and to confirm.js when the js was loaded. This is what I get:
20:54:49.096 hudson-behavior.js:2751 Window load event called.
...
20:54:57.853 confirm.js:149 confirm.js was loaded
So there are almost 8 seconds between the load event until the confirm.js is loaded.
By adding it generally at the beginning the confirm.js is loaded earlier and thus can hook in properly. That probably means any page using <l:settings-subpage doesn't need to include the adjunct explicitly or indirectly. Though it doesn't hurt to include it twice as stapler will take care not to double load it.
The CloudSet/index.jelly uses noDefer and there I can see that the load event reaches the confirm.js. But then there is nothing to hook in it seems.
There was a problem hiding this comment.
Thanks for adding the logging, that makes the timing issue much clearer.
From the logs it looks like confirm.js is loaded several seconds after the window.load event has already fired when using <l:defer>, so its load listener never runs and it cannot attach the change listeners.
Including the adjunct earlier causes confirm.js to load before the load event and therefore work as expected.
That said, it might be cleaner to make confirm.js resilient to late loading instead of relying on earlier inclusion. I can try updating it to initialize immediately if the document is already loaded. Let me know if that would be preferable.
There was a problem hiding this comment.
I think confirm.js should be loaded as late as possible to ensure when it loads that it detects all possible things that are changeable. So it should be made resilient to late loading.
There was a problem hiding this comment.
I’ve updated confirm.js to initialize immediately if the document is already loaded, and to observe DOM changes so it attaches once the configuration form becomes available.
This keeps the script resilient to late loading without requiring earlier inclusion. Please let me know if you’d like further adjustments.
|
Hi @mawinter69 , just checking in on this PR. |
mawinter69
left a comment
There was a problem hiding this comment.
Small change otherwise looks good. Tested that and I can confirm that changes to the configure page are properly detected.
| permissions="${attrs.permissions}" | ||
| type="${newManageJenkins ? 'two-column' : 'one-column'}"> | ||
|
|
||
|
|
There was a problem hiding this comment.
Thanks for the review and for testing. I’ve applied the requested change.
|
Hi @timja I see that some tests which were previously passing are now failing. Does this need a re-run, or is there something else that requires attention from my side? |
The failing test has been disabled by pull request: It will be fixed with issue: You can disable the failing test by updating the branch or wait a little longer for the fix. |
|
/label ready-for-merge This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback. Thanks! |
The related issue appears to be fixed now. A CI re-run would be helpful. |
|
Congratulations on getting your very first Jenkins core pull request merged 🎉🥳 |
Fixes #26270
In the new Manage Jenkins UI, configuration pages rendered via
settings-subpage.jellydid not includelib.form.confirm, so dirty-form tracking was not initialized and the native "unsaved changes" warning was not shown.Additionally, because configuration content is rendered using
<l:defer>, the form may not be present in the DOM whenconfirm.jsinitializes onwindow.load, preventing event listeners from being attached.This change restores the expected behavior by including
lib.form.confirmin the new layout and ensuring initialization occurs once the configuration form is available.Testing done
Build and verification:
mvn -pl war -am verify -P light-test -Dskip.yarnyarn lintmvn spotless:checkScreenshots (UI changes only)
Before
Modified a configuration checkbox and navigated away — no warning dialog appeared.

After
Modified a configuration checkbox and navigated away — native browser unsaved changes warning is shown.



Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
Desired reviewers
@jenkinsci/core-pr-reviewers
Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered.