Skip to content

Commit 5505e1c

Browse files
committed
refactor(kb-connectors): tighten state primitives in modals
- edit modal: replace useMemo([]) + eslint-disable with useState lazy initializer for initialSourceConfig — same mount-once semantics without the escape hatch. - add modal: drop useCallback on handleConnectNewAccount (no observer saw the reference) and inline the one call site.
1 parent e6f17ca commit 5505e1c

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/add-connector-modal/add-connector-modal.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useCallback, useMemo, useState } from 'react'
3+
import { useMemo, useState } from 'react'
44
import { ArrowLeft, ArrowLeftRight, Loader2, Plus, Search } from 'lucide-react'
55
import { useParams } from 'next/navigation'
66
import {
@@ -180,10 +180,6 @@ export function AddConnectorModal({
180180
)
181181
}
182182

183-
const handleConnectNewAccount = useCallback(() => {
184-
setShowOAuthModal(true)
185-
}, [])
186-
187183
const filteredEntries = useMemo(() => {
188184
const term = searchTerm.toLowerCase().trim()
189185
if (!term) return CONNECTOR_ENTRIES
@@ -291,9 +287,7 @@ export function AddConnectorModal({
291287
: `Connect ${connectorConfig.name} account`,
292288
value: '__connect_new__',
293289
icon: Plus,
294-
onSelect: () => {
295-
void handleConnectNewAccount()
296-
},
290+
onSelect: () => setShowOAuthModal(true),
297291
},
298292
]}
299293
value={effectiveCredentialId ?? undefined}

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/edit-connector-modal/edit-connector-modal.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ export function EditConnectorModal({
6767
/**
6868
* Seeds from the stored canonical config. For canonical-pair fields (selector +
6969
* manual input), both field IDs get the same value so toggling preserves it.
70+
* Captured once on mount; editing state is owned by the hook afterward.
7071
*/
71-
const initialSourceConfig = useMemo(() => {
72+
const [initialSourceConfig] = useState<Record<string, string>>(() => {
7273
const config: Record<string, string> = {}
7374
if (!connectorConfig) {
7475
for (const [key, value] of Object.entries(connector.sourceConfig)) {
@@ -83,9 +84,7 @@ export function EditConnectorModal({
8384
if (rawValue !== undefined) config[field.id] = String(rawValue ?? '')
8485
}
8586
return config
86-
// Seed once on mount; editing state is owned by the hook afterward
87-
// eslint-disable-next-line react-hooks/exhaustive-deps
88-
}, [])
87+
})
8988

9089
const {
9190
sourceConfig,

0 commit comments

Comments
 (0)