Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): remove a provider-instance draft right after it saves (#20947)

chanxb67f965da04a
diff --git a/web/AGENTS.md b/web/AGENTS.md
index 8d379255fe..f88509918d 100644
--- a/web/AGENTS.md
+++ b/web/AGENTS.md
@@ -25,6 +25,16 @@ npm run test # Jest tests
## Development Conventions
+### Pre-commit Format Validation (Mandatory)
+
+Frontend code changes **must pass the lefthook format checks before every commit**. Do not rely on CI (`web-oxfmt` / `web-oxlint` jobs) to catch formatting after pushing.
+
+- Before staging or committing changed `.ts`/`.tsx`/`.js`/etc. files, run the formatter and linter locally:
+ - `npx oxfmt <changed files>` (or `npm run format`) to auto-fix formatting
+ - `npx oxlint` (or `npm run lint`) for lint issues
+- Verify with `npx oxfmt --check <changed files>` before `git commit`.
+- Let the lefthook pre-commit hook run to completion and fix everything it reports; never bypass hooks with `--no-verify`.
+
### Test File Placement
When tests are grouped in a dedicated directory, that directory is always named `__tests__/` — never `tests/`. Example: `src/pages/agent/utils/__tests__/extractor-transform.test.ts` for `src/pages/agent/utils/extractor-transform.ts`. Co-located `foo.test.ts(x)` files next to the source file are also fine. When you find an existing test under a `tests/` directory, move it into `__tests__/` (keep git history via `git mv`) rather than adding new tests there.
diff --git a/web/src/pages/user-setting/setting-model/index.tsx b/web/src/pages/user-setting/setting-model/index.tsx
index 83d90df4ab..03fbc9e7a0 100644
--- a/web/src/pages/user-setting/setting-model/index.tsx
+++ b/web/src/pages/user-setting/setting-model/index.tsx
@@ -171,13 +171,17 @@ const SettingModelV2: FC = () => {
// saved card's baseline so the next save short-circuits, and
// invalidate the instance query so the new/updated cards appear.
const handleSaveAll = useCallback(async () => {
- const refs = Array.from(cardRefs.current.values()).filter(
- (r): r is ProviderInstanceCardRef => r !== null,
+ // Keep each card's registry key alongside its ref: for drafts the
+ // key is the draft id, so a successfully-saved draft can be removed
+ // from `draftIds` individually even when a later card in the batch
+ // fails (the early return must not strand already-persisted drafts).
+ const refs = Array.from(cardRefs.current.entries()).flatMap(([key, ref]) =>
+ ref ? [{ key, ref }] : [],
);
if (refs.length === 0) return;
const dirty = refs
- .map((r) => ({ ref: r, payload: r.getSavePayload() }))
+ .map(({ key, ref }) => ({ key, ref, payload: ref.getSavePayload() }))
.filter((e) => e.payload !== null);
if (dirty.length === 0) return;
@@ -210,21 +214,27 @@ const SettingModelV2: FC = () => {
// `addDraft()`).
cancelledRef.current = true;
try {
- // 3. Dispatch one API call per dirty card. Sequential so any
+ // 3. Dispatch one API call per dirty card. Sequential so a
// backend error stops the batch and the user can retry the
- // remaining cards after fixing the issue.
- for (const { ref, payload } of validations) {
+ // remaining cards after fixing the issue. Each successfully
+ // persisted draft is removed immediately so it never lingers
+ // beside its now-saved card when a later card in the batch
+ // fails.
+ for (const { key, ref, payload } of validations) {
if (!payload) continue;
if (payload.apiKind === 'add') {
const ret = await addProviderInstance(payload.payload as any);
if (ret?.code !== 0) {
// Stop on the first failure so the user can see the error.
+ // Drafts already persisted above were removed individually.
return;
}
- // Remember the just-saved name so the persisted card mounts
- // expanded once it surfaces via the invalidated instances
- // query below.
if (payload.isDraft) {
+ // This draft is now persisted - drop its card right away.
+ setDraftIds((prev) => prev.filter((id) => id !== key));
+ // Remember the just-saved name so the persisted card mounts
+ // expanded once it surfaces via the invalidated instances
+ // query.
setNewlySavedInstanceName(payload.instanceName);
}
} else {
@@ -233,15 +243,12 @@ const SettingModelV2: FC = () => {
return;
}
// Saved card: update its dirty baseline so the next save
- // short-circuits. Drafts are removed below so they don't
- // need this.
+ // short-circuits.
ref.markSaved();
}
}
- // 4. Clear drafts (all valid drafts were just persisted) and
- // invalidate the instance query so the newly-saved cards
- // appear in the persisted list.
- setDraftIds([]);
+ // 4. Refresh the persisted instance list (covers updates; adds are
+ // already invalidated by the add mutation) so saved cards show.
queryClient.invalidateQueries({
queryKey: LlmKeys.providerInstances(providerQueryName),
});