creativecommons / creativecommons/search

[Bug] Add Null Checks for DOM Manipulation to Prevent Runtime Errors

Open
#301 7 comments 0 reactions 0 assignees View on GitHub
💻 aspect: code 🛠 goal: fix 🟨 priority: medium 🧹 status: ticket work required
Dominant language
CSS
Stars
27
Forks
112
PR merge metrics
No merged PRs in 30d

Description

## Description

Some parts of the JavaScript codebase lack proper null checks when manipulating DOM elements. This can lead to unexpected errors or crashes when trying to access or modify elements that might be null or undefined, especially when elements are dynamically created or loaded.

## Reproduction

1. Navigate to any part of the application where DOM elements are dynamically manipulated or loaded (e.g., elements added/removed via JavaScript).
2. Ensure that a specific DOM element expected to be present is not found (null or undefined).
3. Try to interact with the element (e.g., applying styles, setting content).
4. Observe the application behavior as it crashes or throws an error due to missing null checks.
5. See error.

## Expectation

The code should check if DOM elements exist before trying to manipulate them. Null checks should be added to ensure that DOM manipulations are only attempted when the element is properly loaded or exists in the document.

## Environment

- Device: laptop
- OS:Windows 112
- Browser: Chrome
- Version: 117
- Other info: 1920x1080

## Additional context

These null checks are crucial when manipulating DOM elements that may not yet exist at the time of execution, especially when dealing with asynchronous content loading or user-triggered dynamic changes in the DOM.

## Resolution

- [X] I would be interested in resolving this bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.