Skip to content

[2.x] Admin settings search crash #4372

@imorland

Description

@imorland

Current Behavior

Admin settings search crashes with:

TypeError: e.tree.map is not a function

The error occurs in GeneralSearchSource.tsx when rendering search results for settings that use the tree property (e.g. extensions using generalIndexItems with tree).

Steps to Reproduce

  1. Open the Flarum admin panel.
  2. Open the search modal (e.g. via the search icon or keyboard shortcut).
  3. Search for a term that matches an extension setting (e.g. "upload", "file", "mime").
  4. The error appears and the search modal fails to render results.

Expected Behavior

Search results should render without errors, with breadcrumb paths (e.g. "Preferences › Max file size") when settings define a tree property.

Screenshots

No response

Environment

Output of php flarum info

Output of "php flarum info", run this in terminal in your Flarum directory.

Possible Solution

In framework/core/js/src/admin/components/GeneralSearchSource.tsx around line 130, the code is:

'tree' in setting && setting.tree ? setting.tree.map(extractText).push(label) : [label],

Array.prototype.push() returns the new length (a number), so the tree argument passed to GeneralSearchResult is a number instead of an array. Later, result.tree.map() fails because numbers don’t have .map.

Fix: use an expression that returns an array, for example:

'tree' in setting && setting.tree ? [...setting.tree.map(extractText), label] : [label],

Additional Context

The bug affects any extension that registers settings via generalIndexItems('settings', ...) with a tree property. For example, fof/upload uses tree: [t('fof-upload.admin.labels.preferences.title')] for its settings. A temporary workaround is to remove the tree property from those items so the fallback [label] is used, but that removes breadcrumb paths in search results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions