Skip to content

Fix TypeError when tree expand/collapse/search is used before the tree finished loading - #1482

Merged
jbtronics merged 1 commit into
Part-DB:masterfrom
Sebbeben:fix/tree-null-guard
Aug 10, 2026
Merged

Fix TypeError when tree expand/collapse/search is used before the tree finished loading#1482
jbtronics merged 1 commit into
Part-DB:masterfrom
Sebbeben:fix/tree-null-guard

Conversation

@Sebbeben

@Sebbeben Sebbeben commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Problem

The sidebar tree's collapseAll(), expandAll() and searchInput() Stimulus actions call methods on this._tree, which is only assigned in _fillTree() after the tree data has been fetched asynchronously (_getData() in reinitTree()).

If the expand-all / collapse-all button is clicked, or something is typed into the tree search box, before that fetch completes, this._tree is still null and the browser throws:

TypeError: Cannot read properties of null (reading 'expandAll')
    at ...tree_controller.js
    Error invoking action "click->elements--sidebar-tree#expandAll"

It is easy to hit on a cold cache / slow first load. The tree works normally once loaded — this is just an unhandled early interaction.

Fix

Guard the three actions with the controller's existing _isInitialized() helper (it already returns this._tree !== null), so they are no-ops until the tree is ready. One short guard per method; no behaviour change once the tree has loaded.

The collapseAll(), expandAll() and searchInput() actions dereference
this._tree, which is only assigned in _fillTree() after the tree data has
been fetched asynchronously. Triggering one of these actions (clicking
expand/collapse-all or typing in the tree search box) before the data has
loaded threw 'TypeError: Cannot read properties of null (reading ...)'.

Guard the three actions with the existing _isInitialized() helper so they
are no-ops until the tree is ready.
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.04%. Comparing base (3b4fdf9) to head (3ec4089).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1482      +/-   ##
============================================
- Coverage     60.06%   60.04%   -0.03%     
  Complexity     9057     9057              
============================================
  Files           675      675              
  Lines         29432    29432              
============================================
- Hits          17677    17671       -6     
- Misses        11755    11761       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jbtronics

Copy link
Copy Markdown
Member

looks good. Thanks.

@jbtronics
jbtronics merged commit 2f29563 into Part-DB:master Aug 10, 2026
16 checks passed
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.

2 participants