-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Fix web UI: prevent duplicate onload processing, correct localStorage default handling, and guard tab panes access #23908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… handling; guard tab panes access
- util/page.js: use a proper class selector with jQuery `.not("." + loadedClass)` to avoid repeatedly processing the same elements during page scans.
- util/localStorage.js: only return the provided default when `localStorage.getItem` returns `null`, preserving empty string and "0" values.
- section-to-tabs.js: safely no-op when a page has no `.jenkins-tab-pane`, preventing runtime errors.
These are safe, focused fixes that improve correctness and stability without changing existing behavior or adding features.
Signed-off-by: shbhmexe <[email protected]>
| tabPane.style.display = "none"; | ||
| }); | ||
| // If there are tab panes on the page, initialize tabs; otherwise no-op | ||
| if (tabPanes && tabPanes.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what issue is this resolving?
Can you provide steps to reproduce please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would require loading the js on a page that has no tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timja The section-to-tabs.js fix guards against JavaScript errors when the script runs on pages without .jenkins-tab-pane elements. It's a defensive fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s a fix for a non issue though. If there’s a use case for something that’s fine. I don’t think this is worth it though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timja I wasn't able to find a concrete use case where this script would be loaded on a page without tabs. The script is only included on pages that have tabs (like About Jenkins), so this error wouldn't occur in practice.
I'll close this PR. Thanks for the review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it if there’s no real use case right now, we can skip this change. Thanks for clarifying.
|
Are util/page.js and util/localStorage.js dead code? |
Yes, you are correct. These files are not imported or used anywhere in the codebase. |
Summary of Changes
1. Fix
localStorage.getItemreturning incorrect defaultsThe
getItemfunction was using a falsy check (!value) to determine when to return the default value. This caused problems when a stored value was an empty string"", as it would incorrectly return the default instead of the actual stored value.Fix: Changed to check for
nullexplicitly (value === null), which is whatlocalStorage.getItemreturns when a key doesn't exist.2. Fix
page.onloadnot properly excluding processed elementsThe
onloadfunction was using.not(loadedClass)butloadedClassis a string without the CSS class selector prefix. This caused jQuery's.not()to not work correctly.Fix: Added the
.prefix to create a proper CSS class selector (.not("." + loadedClass)).3. Guard tab initialization when no tab panes exist
The
section-to-tabs.jsscript was attempting to accesstabPanes[0]without checking if any tab panes exist, which could cause errors on pages without tabs.Fix: Wrapped the entire tab initialization logic in a guard condition that checks for the existence of tab panes.
Testing done
Proposed changelog entries
N/A
Proposed changelog category
/label skip-changelog,internal
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@timja @daniel-beck
Before the changes are marked as ready-for-merge:
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.