Skip to content

Conversation

@shbhmexe
Copy link
Contributor

@shbhmexe shbhmexe commented Dec 5, 2025

Summary of Changes

1. Fix localStorage.getItem returning incorrect defaults

The getItem function 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 null explicitly (value === null), which is what localStorage.getItem returns when a key doesn't exist.

2. Fix page.onload not properly excluding processed elements

The onload function was using .not(loadedClass) but loadedClass is 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.js script was attempting to access tabPanes[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

  • Verified localStorage correctly stores and retrieves empty strings
  • Verified onload callbacks only fire once per element
  • Verified pages with tabs (e.g., About Jenkins) work correctly
  • Verified pages without tabs don't throw JavaScript errors

Proposed changelog entries

N/A

Proposed changelog category

/label skip-changelog,internal

Proposed upgrade guidelines

N/A

Submitter checklist

  • The issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • UI changes do not introduce regressions when enforcing the current default rules of Content Security Policy Plugin. In particular, new or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@timja @daniel-beck


Before the changes are marked as ready-for-merge:

Maintainer checklist

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, be a Bug or Improvement, and either the issue or pull request must be labeled as lts-candidate to be considered.

… 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]>
@comment-ops-bot comment-ops-bot bot added skip-changelog Should not be shown in the changelog internal labels Dec 5, 2025
tabPane.style.display = "none";
});
// If there are tab panes on the page, initialize tabs; otherwise no-op
if (tabPanes && tabPanes.length > 0) {
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.

@mawinter69
Copy link
Contributor

Are util/page.js and util/localStorage.js dead code?
When I look at what is loaded with chrome devtools then both files are not there

@shbhmexe
Copy link
Contributor Author

shbhmexe commented Dec 7, 2025

Are util/page.js and util/localStorage.js dead code? When I look at what is loaded with chrome devtools then both files are not there

Yes, you are correct. These files are not imported or used anywhere in the codebase.

@shbhmexe shbhmexe closed this Dec 9, 2025
@shbhmexe shbhmexe deleted the fix/web-ui-onload-localstorage-guard branch December 9, 2025 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal skip-changelog Should not be shown in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants