Skip to content

[2.x] fix: allow boolean settings with truthy defaults to be disabled#4782

Open
huoxin233 wants to merge 1 commit into
flarum:2.xfrom
huoxin233:huoxin/2.x-fix-boolean-setting-fallback
Open

[2.x] fix: allow boolean settings with truthy defaults to be disabled#4782
huoxin233 wants to merge 1 commit into
flarum:2.xfrom
huoxin233:huoxin/2.x-fix-boolean-setting-fallback

Conversation

@huoxin233

Copy link
Copy Markdown
Contributor

Fixes #4781

Changes proposed in this pull request:

Resolves a bug in AdminPage.tsx where boolean settings (toggles) that have a truthy default value could not be turned off by the administrator.

By switching from the logical OR operator (||) to the nullish coalescing operator (??), the setting stream correctly recognizes "" as a valid saved state. The fallback is now only applied when the setting is strictly undefined or null (e.g., during a fresh installation where the setting hasn't been saved to the database yet).

Reviewers should focus on:

Screenshot

PixPin_2026-06-26_18-10-57.mp4

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)

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.

[1.x & 2.x] Admin boolean settings with truthy default values cannot be disabled (Switch component)

1 participant