Skip to content

Fix console warning when no password set - #3410

Merged
PromoFaux merged 1 commit into
developmentfrom
fix-warning
Apr 23, 2025
Merged

PromoFaux merged 1 commit into
developmentfrom
fix-warning

Conversation

@PromoFaux

@PromoFaux PromoFaux commented Apr 23, 2025 •

Copy link
Copy Markdown
Member

What does this PR aim to accomplish?:

Noticed while starting a container with web password explicitly set to empty.

image

Ensures that logoutButton exists before chaining the addEventListener method

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

  • I have read the above and my PR is ready for review. Check this box to confirm

…r not thrown when password is empty

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
@PromoFaux
PromoFaux requested review from a team and Copilot April 23, 2025 17:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a console warning by ensuring that the logout button exists before attaching the click event listener.

  • Introduces an optional chaining check for logoutButton before adding the event listener
  • Prevents potential runtime errors when the password is not set

@DL6ER DL6ER left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.

100% voodoo

@PromoFaux
PromoFaux merged commit 5258c8f into development Apr 23, 2025
@PromoFaux
PromoFaux deleted the fix-warning branch April 23, 2025 18:26
@XhmikosR

Copy link
Copy Markdown
Contributor

I'm personally more old-school and prefer explicit returns but this works too of course. As long as it's not overused since optional chaining can have an impact. :)

@PromoFaux PromoFaux mentioned this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants