Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/account-modal-effect-deps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### English

- Account check-in records and models modals now declare their data-loader effect dependencies explicitly via `useCallback`, eliminating stale-closure risk when the loader later gains inputs. Pagination size stays stable across account switches, with no duplicate refetch on page-size change.

### 中文

- 打卡记录与账号模型弹窗的数据加载 effect 现在通过 `useCallback` 显式声明依赖,避免加载函数后续新增入参时产生陈旧闭包;切换账号时分页尺寸保持稳定,调整分页尺寸时不会重复拉取。
6 changes: 5 additions & 1 deletion frontend/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"plugins": ["react", "typescript", "oxc"],
"rules": {
"react/rules-of-hooks": "error",
"react/only-export-components": ["warn", { "allowConstantExport": true }]
"react/only-export-components": ["warn", { "allowConstantExport": true }],
"react/exhaustive-deps": "warn",
"react/refs": "off",
"react/purity": "off",
"react/set-state-in-effect": "off"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { Button, Chip, Modal } from '@heroui/react'
import { ArrowClockwise, X } from '@phosphor-icons/react'
import { fetchCheckinRecords } from '@/api/overview'
Expand Down Expand Up @@ -35,7 +35,7 @@ export function AccountCheckinRecordsModal({ account, t, onClose }: Props) {
const accountId = account?.id || ''
const title = t('checkinRecordsTitle', { name: account?.name || account?.id || '' })

async function load() {
const load = useCallback(async () => {
if (!accountId) return
setLoading(true)
setError('')
Expand All @@ -48,12 +48,12 @@ export function AccountCheckinRecordsModal({ account, t, onClose }: Props) {
} finally {
setLoading(false)
}
}
}, [accountId])

useEffect(() => {
if (!accountId) return
void load()
}, [accountId])
}, [accountId, load])

return (
<Modal.Root isOpen={Boolean(account)} onOpenChange={(next: boolean) => { if (!next) onClose() }}>
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/components/account/AccountModelsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { Button, Chip, Modal } from '@heroui/react'
import { ArrowClockwise, Cube, X } from '@phosphor-icons/react'
import { fetchModels, refreshModels } from '@/api/overview'
Expand Down Expand Up @@ -35,11 +35,13 @@ export function AccountModelsModal({ account, t, onClose }: Props) {
const [total, setTotal] = useState(0)
const [pageCount, setPageCount] = useState(1)
const requestID = useRef(0)
const pageSizeRef = useRef(pageSize)
pageSizeRef.current = pageSize
const accountId = account?.id || ''
const title = t('accountModelsTitle', { name: account?.name || account?.id || '' })
const provider = account ? accountProviderLabel(account.provider, account.region, t) : ''

async function load(requestedPage = 1, requestedPageSize = pageSize, refresh = false) {
const load = useCallback(async (requestedPage = 1, requestedPageSize = pageSizeRef.current, refresh = false) => {
if (!accountId) return
const currentRequest = ++requestID.current
if (refresh) setRefreshing(true)
Expand Down Expand Up @@ -71,13 +73,13 @@ export function AccountModelsModal({ account, t, onClose }: Props) {
setRefreshing(false)
}
}
}
}, [accountId])

useEffect(() => {
if (!accountId) return
setPage(1)
void load(1, pageSize)
}, [accountId])
void load(1, pageSizeRef.current)
}, [accountId, load])

const shownFrom = total === 0 ? 0 : (page - 1) * pageSize + 1
const shownTo = total === 0 ? 0 : Math.min(total, shownFrom + models.length - 1)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/overview/AgentQueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ export function AgentQueue({
}
}
const [announce, setAnnounce] = useState('')
// Runs after every render to flush the latest announcement; state only updates when the message changed.
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => {
mem.current.mounted = true
if (mem.current.msg && mem.current.msg !== announce) setAnnounce(mem.current.msg)
Expand Down Expand Up @@ -792,6 +794,8 @@ export function AgentQueue({
})

const [popH, setPopH] = useState(120)
// Re-measure the popover after every render; state only updates when the height changed materially.
// eslint-disable-next-line react-hooks/exhaustive-deps
useLayoutEffect(() => {
const h = popRef.current?.offsetHeight
if (h && Math.abs(h - popH) > 1) setPopH(h)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/OverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ export function OverviewPage() {

useEffect(() => {
loadStats(false)
// Invalidate the in-flight request when this effect tears down; ref version is intentionally bumped here.
// eslint-disable-next-line react-hooks/exhaustive-deps
return () => { statsRequestRef.current++ }
}, [loadStats])

Expand Down

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions internal/webui/static/assets/AccountsPage-DAwU5tJE.js

This file was deleted.

8 changes: 8 additions & 0 deletions internal/webui/static/assets/AccountsPage-Us88hnPK.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading