fix(ui): reflect persisted "Store Prompts in Spend Logs" toggle on load - #32145
Conversation
Co-Authored-By: bot_apk <apk@cognition.ai>
Co-Authored-By: bot_apk <apk@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
|
Tested end-to-end on a local proxy (
Toggle ON persists after a full reload (the fix)
After navigating away and hard-reloading, the switch stays ON (pre-fix it reverted to OFF here): Session: https://app.devin.ai/sessions/32b64ceba1494e5991cb45a42c68d9d1 |
Greptile SummaryThis PR fixes a UI-only bug where the "Store Prompts in Spend Logs" toggle always rendered as OFF on page load, even though the value was correctly persisted in the database. The root cause was the form mounting before
Confidence Score: 5/5Safe to merge — the change is scoped to one UI component, the fix is mechanically sound, and the new test directly reproduces the reported bug scenario. The conditional render is a minimal, well-understood solution that eliminates the race between antd's form store initialisation and asynchronous data arrival. No backend logic is touched. The removed test is replaced by equivalent or stricter assertions, and the new regression test would fail on the old code. No files require special attention.
|
| Filename | Overview |
|---|---|
| ui/litellm-dashboard/src/components/Settings/AdminSettings/LoggingSettings/LoggingSettings.tsx | Replaced fragile key-based form remounting with conditional rendering; Form now mounts only after data loads, so initialValues are always fully populated on mount. Also drops the now-unnecessary Form.useWatch + manual Switch binding. |
| ui/litellm-dashboard/src/components/Settings/AdminSettings/LoggingSettings/LoggingSettings.test.tsx | Replaces the removed "save button disabled during loading" test (button no longer renders at all while loading) with a stronger async rerender test that reproduces the original bug scenario. Coverage is maintained or improved. |
| ui/litellm-dashboard/eslint-metrics.json | Decrements the no-explicit-any count from 1991 to 1990 reflecting the single any type removed from the component. |
Reviews (2): Last reviewed commit: "style(ui): prettier-format LoggingSettin..." | Re-trigger Greptile
… an Effect The persisted store_prompts_in_spend_logs toggle was reflected on load via a useEffect that pushed proxy-config data into form state. Syncing server state into local form state with an Effect is an antipattern, and it also clobbers a user's in-progress edits whenever the config query refetches. react-query (useProxyConfig) already provides the data and an isLoading flag. antd applies initialValues once, at mount, so the real fix is to not mount the Form until the config has loaded. Then initialValues (derived from the query data) is correct on first render, and the Effect, the JSON.stringify remount key, and the controlled Switch are all unnecessary; the form stays uncontrolled.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Reworked how the persisted toggle is reflected on load (74ab60f). The prior approach synced the proxy-config data into form state with a
Tests: 14 pass, including |
Co-Authored-By: bot_apk <apk@cognition.ai>
|
Thanks — the render-when-ready approach is cleaner, and agreed that pushing server state into form state via an Effect was an antipattern (and would clobber in-progress edits on refetch). Heads up: |
Relevant issues
Admin Settings -> Logging Settings -> "Store Prompts in Spend Logs" toggle appeared to revert to OFF. The value was correctly persisted to the DB (verified via
/config/update+/config/list), but the switch rendered as OFF whenever the config loaded asynchronously (fresh page load / navigating back to the tab)Linear ticket
Resolves LIT-4204
Pre-Submission checklist
Screenshots / Proof of Fix
Backend was already persisting correctly; the bug was purely in the UI. Reproduced live on a local proxy (
/ui/admin-panel-> Logging Settings)End-to-end recording: toggle ON -> Save -> navigate away -> hard reload stays ON, then OFF -> Save -> hard reload stays OFF
DB round-trip confirming persistence both directions:
Type
🐛 Bug Fix
Changes
Root cause: the form was reset via
key={JSON.stringify(initialValues)}while reusing the sameuseForminstance. On first renderproxyConfigDataisundefined, so the form mounted withstore_prompts_in_spend_logs: falseand wrote that into the (preserved) form store. When the config arrived and thekeychanged, antd re-mounts the Form element but keeps the persisted store, so the newerinitialValues(true) were not re-applied; theSwitch, driven byForm.useWatch, kept showingfalseFix in
LoggingSettings.tsx:form.setFieldsValue(initialValues)in auseEffectkeyed onproxyConfigData(re-applies on initial load and after post-save refetch), instead of the fragilekey-remountForm.Itemown the switch (name+valuePropName="checked"); drop the manualForm.useWatch+ controlledchecked/onChangeAdded a regression test (
LoggingSettings.test.tsx) that renders in the loading state first, then rerenders withfield_value: true, and asserts the switch is checked; this fails on the old code and passes with the fixLink to Devin session: https://app.devin.ai/sessions/32b64ceba1494e5991cb45a42c68d9d1