Commit f6ac075
* fix(servers): make settings form re-render on every keystroke (#1361)
The settings modal is fully controlled by App.tsx, but pending edits were
stashed in a useRef — refs don't trigger re-renders, so the input's `value`
prop stayed stale until the 300ms debounce + PUT + refetch round-tripped.
Clicking "Add Header" / "Add Metadata" showed no row, and typing in OAuth
fields had no character echo, until that round-trip completed (~500ms).
The bug landed in #1353 with the debounced-flush pattern. It surfaced after
#1356 because per-keystroke PUTs now also write the keychain, making the
round-trip latency more noticeable.
Lift the draft into `useState`. Every change re-renders the modal
immediately. Keep the 300ms debounce on the PUT side. Initialize the draft
from the server-list entry only when the modal opens to a new target (not
on every `servers` change) so background refreshes don't clobber the user's
in-progress edits. Flush on close to preserve final keystrokes.
Verified live against the dev server: header/metadata rows appear on click,
OAuth Client ID / Client Secret typing echoes without lag, and the values
persist correctly (clientId in mcp.json, clientSecret in the macOS
Keychain).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(servers): extract useSettingsDraft hook + tests; review polish (#1361)
Picks up the three review observations on #1362:
1. Extract the draft state + debounce + flush logic from App.tsx into
`core/react/useSettingsDraft`. Same behavior; thinner App.tsx;
testable in isolation with `renderHook`. Tests pin the regression
#1361 was about (synchronous onChange → draft update) plus the
debounce window, burst-collapse, flush-on-close, error propagation,
and the "background refresh must not clobber in-progress edits"
contract via a `resolveInitial` closure swap.
2. Hoist the empty `InspectorServerSettings` fallback to a module-scope
`EMPTY_SETTINGS` const. Both the hook's init path and the modal's
closed-state fallback share the same object identity; the inline
`useMemo` that previously re-derived it is gone.
3. Add a comment on the `resolveInitial` callback noting that we read
`servers` from this render's closure under the assumption that the
entry point is the "Settings" button on a rendered server card.
Documents the contract for future callers (e.g. a keyboard shortcut
that opens the modal pre-hydration).
Validate clean: 1756 tests pass. New useSettingsDraft.test.tsx adds 13
test cases.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(servers): stabilize flush identity + add unmount-cleanup test (#1361)
Two non-blocking observations from the third review on #1362:
1. `flush` identity churned on every keystroke because the useCallback
closed over `draft` + `targetId`. Read both through refs instead so
the returned callback identity is stable. The behavior is unchanged
— but the consumer's `onSettingsModalClose` (which wraps `flush`)
no longer re-allocates per keystroke, which means the modal's
`onClose` prop identity also stays stable. A new test pins this.
2. Added a comment in `onChange` calling out that callers switching
`targetId` mid-debounce must `flush()` first to preserve the
pending PUT. The only switch path today (`onSettingsModalClose` in
App.tsx) does that already — the comment is for future refactors.
3. New unmount-cleanup test pins the intentional "drop final
<debounceMs window on unmount" trade-off — flushing on unmount
could fire a PUT against an unmounting component, which is a
worse footgun than losing a few hundred ms of typing on route
change / HMR.
Validate clean: 144 files, 1758 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 037225a commit f6ac075
3 files changed
Lines changed: 588 additions & 76 deletions
File tree
- clients/web/src
- test/core/react
- core/react
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
129 | 143 | | |
130 | 144 | | |
131 | 145 | | |
| |||
763 | 777 | | |
764 | 778 | | |
765 | 779 | | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
810 | 811 | | |
811 | | - | |
| 812 | + | |
812 | 813 | | |
813 | 814 | | |
814 | 815 | | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | 816 | | |
830 | | - | |
831 | | - | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
832 | 821 | | |
833 | 822 | | |
834 | | - | |
| 823 | + | |
835 | 824 | | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
| 825 | + | |
850 | 826 | | |
851 | 827 | | |
852 | 828 | | |
| |||
0 commit comments