fix: code config values and UI settings save both ignored defaults#676
Open
FarbodGhasemi wants to merge 1 commit into
Open
Conversation
Two bugs fixed: 1. Server (setup.ts): `plugins.ts` code config values were silently ignored for any key that already had a hard-coded default. The original code merged `configBase.default` into `configRaw` before building the priority chain, so the hard-coded default always won. Fixed by separating the raw DB read (`dbConfig`) from the Zod validation object, then applying the correct priority order: DB value → code config (plugins.ts) → hard-coded default. 2. UI (AdditionalSettingsPanel): `NumberInput` from @strapi/design-system exposes the parsed number via `onValueChange`, not `onChange`. The previous `onChange` handler received a raw value that was not a string field name, so `isString(fieldName)` evaluated to false and `setFormValueItem` was never called. `formValue.allowedLevels` stayed at 2 while the input display (driven by the Form component's internal `values`) correctly showed the user's input — causing the stale value to be submitted on save. Fixed by switching to `onValueChange`. Also included: - useInitialConfig: guard with useRef so the form is only seeded from the server once per mount, preventing background refetches from overwriting user edits - useSaveConfig: invalidate the config query after a successful save - SettingsPage: move queryClient.invalidateQueries() into useEffect so it runs once on mount instead of on every render - Test infrastructure: add outDir to server/tsconfig.json and tsconfig path to jest.config.ts so ts-jest resolves correctly - Regression test: configSetup respects code config allowedLevels when DB is empty
7bd8cbd to
649e632
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
N/A
Summary
Fixes two independent bugs where plugin configuration values were silently ignored.
Bug 1 — Server:
plugins.tscode config values overridden by hard-coded defaultsIn
server/src/config/setup.ts,configSetupmergedconfigBase.defaultintoconfigRawbeforebuilding the fallback chain. This meant the hard-coded default always appeared as a DB value and
won, so any key set in
plugins.ts(e.g.allowedLevels: 5) was silently discarded.Fix: separate the raw DB read (
dbConfig) from the Zod validation object and apply the correctpriority order: DB value → code config (
plugins.ts) → hard-coded default.Bug 2 — UI: changing
allowedLevelsin admin settings reverts to default on saveNumberInputfrom@strapi/design-systemdelivers its parsed value viaonValueChange, notonChange. The existingonChangehandler received a non-string first argument, soisString(fieldName)returnedfalseandsetFormValueItemwas never called.formValue.allowedLevelsstayed at the server's initial value while the input display (driven bythe Form component's internal state) correctly showed the user's edit — causing the stale value to
be submitted on save.
Fix: switch
NumberInputtoonValueChangeand pass the field name explicitly tohandleChange.Additional:
useInitialConfig:useRefguard so the form is seeded from server data only once per mount,preventing background refetches from overwriting in-progress edits
useSaveConfig: invalidate the config query after a successful saveSettingsPage: movequeryClient.invalidateQueries()intouseEffect(was running on everyrender)
outDirinserver/tsconfig.json+tsconfigpath injest.config.tsfor
ts-jestconfigSetupwith empty DB respects a code configallowedLevelsvalueTest Plan
allowedLevels: 5inconfig/plugins.tswith no prior DB config → server bootstraps with5, not2allowedLevelsto4, click Save → PUT body contains4; valuepersists after restart
yarn jest→ 175 passing, 2 todo, 1 pre-existing failure (CommonService › getSlug()— ESM/CJSissue with
@sindresorhus/slugify, unrelated to this PR)