mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
fix(webui): resolve conditional hooks and setState-in-render errors
- __root.tsx: move useTeamContextStore/useEffect/useQuery above the conditional 'return <Outlet />' so hooks run unconditionally in a stable order (fixes 'Rendered more hooks than during the previous render') - team-selector.tsx: move single-team navigate() into a useEffect to avoid updating the router Transitioner during render
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
} from '@/ui/components/ui/dialog'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { useEffect } from 'react'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
|
||||
export function TeamSelector() {
|
||||
@@ -23,14 +24,20 @@ export function TeamSelector() {
|
||||
},
|
||||
})
|
||||
|
||||
const teams = teamsData?.data
|
||||
const onlyTeamId = teams?.length === 1 ? teams[0].id : null
|
||||
|
||||
useEffect(() => {
|
||||
if (onlyTeamId) {
|
||||
navigate({ to: `/teams/${onlyTeamId}` })
|
||||
}
|
||||
}, [onlyTeamId, navigate])
|
||||
|
||||
if (isLoading) {
|
||||
return <div>{m.loading()}</div>
|
||||
}
|
||||
|
||||
const teams = teamsData?.data
|
||||
|
||||
if (teams?.length === 1) {
|
||||
navigate({ to: `/teams/${teams[0].id}` })
|
||||
if (onlyTeamId) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user