Skip to content

[2.x] fix: keep a saved falsy setting in settings modals too - #4901

Merged
imorland merged 1 commit into
2.xfrom
im/settings-modal-falsy-fallback
Aug 5, 2026
Merged

[2.x] fix: keep a saved falsy setting in settings modals too#4901
imorland merged 1 commit into
2.xfrom
im/settings-modal-falsy-fallback

Conversation

@imorland

@imorland imorland commented Aug 5, 2026

Copy link
Copy Markdown
Member

Follow-up to #4782, which fixed this in AdminPage while the identical line in SettingsModal survived. Same defect, different file — context in #4781.

// AdminPage.tsx — fixed by #4782
this.settings[key] = this.settings[key] || Stream<string>(app.data.settings[key] ?? fallback);

// SettingsModal.tsx — this PR
this.settings[key] = this.settings[key] || Stream(app.data.settings[key] ?? fallback);

Settings live in a string column, so a saved false arrives as an empty string. Choosing the fallback on falsiness discarded it and reseeded the default, which meant a boolean setting whose default is truthy could not be switched off — it came back on with every reload.

Why it matters

SettingsModal is public API — extensions import it as flarum/admin/components/SettingsModal. Current consumers:

  • core: EditCustomHeaderModal, EditCustomFooterModal, EditCustomCssModal
  • flarum/audit: LimitedSettingsModal

Tests

The existing AdminPageSetting.test.ts (added in #4782) now covers both classes side by side rather than only the one the original issue named — which is what would have caught this the first time round. Seven tests: four for AdminPage, three for SettingsModal.

I checked the new SettingsModal empty-string test fails without this change.

Its docblock is also corrected. It claimed a saved '0' was discarded too, but the string '0' is truthy in JavaScript — only the number is falsy. The empty string is the only value a setting can hold that JavaScript reads as absent.

All integration suites green: 50 suites, 169 tests. check-typings clean.

Testing by hand

Awkward to demonstrate in core, since none of the three core modals has a boolean setting with a truthy default — the visible effect there is nil. It reproduces through an extension that puts such a setting in a modal. The test coverage is the real assurance here.

#4782 fixed this in `AdminPage` but the identical line in `SettingsModal`
survived, so the bug still reached every settings *modal*: settings live in a
string column, a saved `false` arrives as an empty string, and choosing the
fallback on falsiness discarded it and reseeded the default. A boolean setting
whose default is truthy could not be switched off — it came back on with every
reload.

`SettingsModal` is public API, imported by extensions as
`flarum/admin/components/SettingsModal`, and core's custom header, footer and
CSS modals extend it, as does flarum/audit.

The existing test file now covers both classes side by side rather than only
the one the original issue named, which is what would have caught this the
first time. Its docblock is corrected too: it claimed a saved `'0'` was also
discarded, but the string is truthy in JavaScript, unlike the number — the
empty string is the only value a setting can hold that JavaScript reads as
absent.
@imorland
imorland requested a review from a team as a code owner August 5, 2026 15:04
@imorland imorland added this to the 2.0.0-rc.6 milestone Aug 5, 2026
@imorland
imorland merged commit e51f70b into 2.x Aug 5, 2026
25 checks passed
@imorland
imorland deleted the im/settings-modal-falsy-fallback branch August 5, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant