Repository navigation
fix(dashboard): reset the Add API key modal between opens - #16628
Merged
diegosouzapw merged 2 commits intoOct 15, 2026
Merged
Conversation
The Add API key modal stayed mounted and only toggled `isOpen`, and its open effect refreshed just the name and base URL. Closing it (X, Cancel, or the parent closing after a successful save) kept the previous API key, token secret, AWS credentials, bulk text and the bulk tab, so the next add started pre-filled with the last credential. - ProviderModalsPanel mounts AddApiKeyModal only while it is open, so a close drops the whole form. - The modal itself rebuilds its form from createInitialAddApiKeyFormData() on every closed-to-open transition and resets mode, bulk state, advanced toggle, validation capabilities and the OpenRouter preset, covering callers that keep it mounted. The unique default name (#6499, #11033, #15006) is still recomputed on each open. - A failed save keeps the typed input and shows the error. Co-authored-by: Hamed Niroomand <hamed@niroomand.dev> Inspired-by: decolua/9router#4027 Co-authored-by: semihisikman <semihisikman@users.noreply.github.com> Inspired-by: decolua/9router#4582
Contributor
CI Coverage Report
Coverage artifact was not available for this run. |
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.
Summary
ProviderModalsPanelnow mountsAddApiKeyModalonly while it is open, and the modal itself rebuilds its whole form on every open for callers that keep it mounted.Attribution
Thanks to @hamedniroomand and @semihisikman for the original implementation.
Changes
components/ProviderModalsPanel.tsx: render<AddApiKeyModal>only whenshowAddApiKeyModalis true, so closing it drops all form state (API key, token secret, AWS credentials, bulk text, OpenRouter preset, region step).components/modals/addApiKeyInitialFormData.ts(new):createInitialAddApiKeyFormData()holds the initial form shape that was inline in the modal.components/modals/AddApiKeyModal.tsx: the open-transition effect now replaces the form withcreateInitialAddApiKeyFormData()instead of patchingname/baseUrlonto the old values, and resets mode, bulk text/result/warnings, the bulk "validate keys" toggle, advanced section, validation capabilities and the OpenRouter preset. The unique default name (fix(ui): prevent silent overwrite of existing API key connections on … #6499, [bug] ChatGPT Web: 5th connection replaces the 1st instead of appending #11033, fix(providers): adding a cookie connection can silently overwrite an existing one — count-based default name collides after a delete, and cookie rows upsert by name #15006) is still recomputed on each open. A failed save keeps the typed input and shows the error.components/modals/__tests__/addApiKeyModalReset.test.tsx(modal-level reset) and__tests__/addApiKeyModalMountOnOpen.test.tsx(panel mounts a fresh instance per open).Test plan
HEADwithgit show):npx vitest run --config vitest.config.ts addApiKeyModalReset→Tests 3 failed | 2 passed (5)(API key kept after reopen, bulk tab + textarea kept, key kept after a successful save; the unique-name and failed-save cases pass as regression guards).npx vitest run --config vitest.config.ts addApiKeyModalMountOnOpen→Tests 1 failed (1)(expected <div …> to be null: modal mounted while closed).npx vitest run --config vitest.config.ts addApiKeyModalMountOnOpen addApiKeyModalReset→Test Files 2 passed (2),Tests 6 passed (6).AddApiKeyModal/ProviderModalsPanel):npx vitest run --config vitest.config.ts tests/unit/ui/confirm-delete-connection-7361 tests/unit/ui/add-api-key-modal tests/unit/ui/compatible-provider-apikey-setup tests/unit/ui/web-session-cookie-modal-size-6265 proxySaveRefresh useApiKeySaveSkipsFullSync addApiKeyModalMountOnOpen addApiKeyModalReset connModals addApiKeyModal-default-name-15006→Test Files 13 passed (13),Tests 49 passed (49).node --import tsx/esm --test tests/unit/compute-connection-default-name-11033.test.ts tests/unit/compute-connection-default-name-6499.test.ts tests/unit/freebuff-risk-notice-15058.test.ts→ℹ tests 10 ℹ pass 10 ℹ fail 0.npx eslint --suppressions-location config/quality/eslint-suppressions.json <5 changed files>→ exit 0;npx prettier --check <5 changed files>→ all formatted.npm run typecheck:core→ exit 0. Targetedtscover the 5 changed files: identical pre-existing error set before and after (37 = 37, none in the new code).node scripts/check/check-pr-test-policy.mjs→Result: PASS;GITHUB_BASE_REF=release/v3.8.52 npm run check:test-masking→OK — 0 modified, 0 deleted.