fix: stabilize settings form hydration

This commit is contained in:
linkong
2026-04-01 15:46:02 +08:00
parent b8f70f8b71
commit 6bfcd05345
7 changed files with 54 additions and 9 deletions

View File

@@ -1 +1 @@
0.22.7
0.22.8

View File

@@ -7,6 +7,27 @@ This project follows the repository versioning rule:
- `feature` -> `+0.1.0`
- `bugfix` -> `+0.0.1`
## 0.22.8
Released: 2026-04-01
### Highlights
- Fixed the configuration center form lifecycle so revisiting the Settings page no longer triggers Ant Design's `useForm` warning during async settings hydration.
- Aligned repository version metadata across the backend, frontend, and lockfiles so the new bugfix release reports a consistent `0.22.8` version everywhere.
### Improved
- Improved settings data hydration in [Settings.tsx](/home/ray/dev/linkong/planet/frontend/src/pages/Settings/Settings.tsx) by staging fetched system, notification, and security payloads in React state first instead of writing directly into form instances during the request callback.
- Improved settings form synchronization in [Settings.tsx](/home/ray/dev/linkong/planet/frontend/src/pages/Settings/Settings.tsx) by delaying `setFieldsValue(...)` until the page loading skeleton is gone, ensuring each Ant Design form is actually mounted before values are pushed into it.
- Improved tab readiness in [Settings.tsx](/home/ray/dev/linkong/planet/frontend/src/pages/Settings/Settings.tsx) by keeping the primary configuration tabs force-rendered so revisits and tab switches no longer race form instance registration.
- Improved release consistency by updating [VERSION](/home/ray/dev/linkong/planet/VERSION), [pyproject.toml](/home/ray/dev/linkong/planet/pyproject.toml), [frontend/package.json](/home/ray/dev/linkong/planet/frontend/package.json), [frontend/package-lock.json](/home/ray/dev/linkong/planet/frontend/package-lock.json), and [uv.lock](/home/ray/dev/linkong/planet/uv.lock) to the same bugfix version.
### Fixed
- Fixed the `Instance created by useForm is not connected to any Form element` warning in [Settings.tsx](/home/ray/dev/linkong/planet/frontend/src/pages/Settings/Settings.tsx), which could still reappear after navigating away from the configuration center and returning while settings were being refetched.
- Fixed the timing bug where the page attempted to hydrate hidden/loading tab forms before the enclosing `Card loading` state had mounted the real form tree.
## 0.22.7
Released: 2026-04-01

View File

@@ -1,12 +1,12 @@
{
"name": "planet-frontend",
"version": "0.22.7",
"version": "0.22.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "planet-frontend",
"version": "0.22.7",
"version": "0.22.8",
"dependencies": {
"@ant-design/icons": "^5.2.6",
"antd": "^5.12.5",

View File

@@ -1,6 +1,6 @@
{
"name": "planet-frontend",
"version": "0.22.7",
"version": "0.22.8",
"private": true,
"dependencies": {
"@ant-design/icons": "^5.2.6",

View File

@@ -75,6 +75,9 @@ function Settings() {
const [loading, setLoading] = useState(true)
const [savingCollectorId, setSavingCollectorId] = useState<number | null>(null)
const [collectors, setCollectors] = useState<CollectorSettings[]>([])
const [systemSettings, setSystemSettings] = useState<SystemSettings | null>(null)
const [notificationSettings, setNotificationSettings] = useState<NotificationSettings | null>(null)
const [securitySettings, setSecuritySettings] = useState<SecuritySettings | null>(null)
const collectorTableRegionRef = useRef<HTMLDivElement | null>(null)
const [collectorTableHeight, setCollectorTableHeight] = useState(360)
const [systemForm] = Form.useForm<SystemSettings>()
@@ -85,9 +88,9 @@ function Settings() {
try {
setLoading(true)
const response = await axios.get('/api/v1/settings')
systemForm.setFieldsValue(response.data.system)
notificationForm.setFieldsValue(response.data.notifications)
securityForm.setFieldsValue(response.data.security)
setSystemSettings(response.data.system)
setNotificationSettings(response.data.notifications)
setSecuritySettings(response.data.security)
setCollectors(response.data.collectors || [])
} catch (error) {
message.error('获取系统配置失败')
@@ -101,6 +104,24 @@ function Settings() {
fetchSettings()
}, [])
useEffect(() => {
if (!loading && systemSettings) {
systemForm.setFieldsValue(systemSettings)
}
}, [loading, systemForm, systemSettings])
useEffect(() => {
if (!loading && notificationSettings) {
notificationForm.setFieldsValue(notificationSettings)
}
}, [loading, notificationForm, notificationSettings])
useEffect(() => {
if (!loading && securitySettings) {
securityForm.setFieldsValue(securitySettings)
}
}, [loading, securityForm, securitySettings])
useEffect(() => {
const updateTableHeight = () => {
const regionHeight = collectorTableRegionRef.current?.offsetHeight || 0
@@ -257,6 +278,7 @@ function Settings() {
{
key: 'system',
label: '系统显示',
forceRender: true,
children: (
<SettingsPanel loading={loading}>
<Form form={systemForm} layout="vertical" onFinish={(values) => saveSection('system', values)}>
@@ -283,6 +305,7 @@ function Settings() {
{
key: 'notifications',
label: '通知策略',
forceRender: true,
children: (
<SettingsPanel loading={loading}>
<Form form={notificationForm} layout="vertical" onFinish={(values) => saveSection('notifications', values)}>
@@ -309,6 +332,7 @@ function Settings() {
{
key: 'security',
label: '安全策略',
forceRender: true,
children: (
<SettingsPanel loading={loading}>
<Form form={securityForm} layout="vertical" onFinish={(values) => saveSection('security', values)}>

View File

@@ -1,6 +1,6 @@
[project]
name = "planet"
version = "0.22.6"
version = "0.22.8"
description = "智能星球计划 - 态势感知系统"
requires-python = ">=3.14"
dependencies = [

2
uv.lock generated
View File

@@ -475,7 +475,7 @@ wheels = [
[[package]]
name = "planet"
version = "0.22.7"
version = "0.22.8"
source = { virtual = "." }
dependencies = [
{ name = "aiofiles" },