fix(web): react-hooks/set-state-in-effect error & pnpm lint #1173

This commit is contained in:
Dihubopen 2026-03-06 16:08:00 +08:00
parent ac08300d9f
commit 1922d789f0

View file

@ -25,7 +25,7 @@ import {
AlertDialogTrigger, AlertDialogTrigger,
} from "@/components/ui/alert-dialog" } from "@/components/ui/alert-dialog"
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { useEffect, useState } from "react" import { useState } from "react"
export const Route = createFileRoute("/config")({ export const Route = createFileRoute("/config")({
component: ConfigPage, component: ConfigPage,
@ -80,7 +80,7 @@ function RawJsonPanel() {
setIsDirty(false) setIsDirty(false)
// Important: Invalidate the query to refresh the cached data // Important: Invalidate the query to refresh the cached data
queryClient.invalidateQueries({ queryKey: ["config"] }) queryClient.invalidateQueries({ queryKey: ["config"] })
} catch (error) { } catch {
// If JSON parsing fails, invalidate to get fresh data // If JSON parsing fails, invalidate to get fresh data
queryClient.invalidateQueries({ queryKey: ["config"] }) queryClient.invalidateQueries({ queryKey: ["config"] })
} }
@ -94,18 +94,17 @@ function RawJsonPanel() {
const [isDirty, setIsDirty] = useState(false) const [isDirty, setIsDirty] = useState(false)
// Store the last saved config to detect changes // Store the last saved config to detect changes
const [lastSavedConfig, setLastSavedConfig] = useState<any>(null) const [lastSavedConfig, setLastSavedConfig] = useState<Record<string, unknown> | null>(null)
useEffect(() => { // Initialize editor value when config is first loaded
if (config && JSON.stringify(config) !== JSON.stringify(lastSavedConfig)) { const getInitialEditorValue = () => {
// Only update if there are no unsaved changes or if this is the initial load if (config && !editorValue) {
if (!isDirty || !lastSavedConfig) { return JSON.stringify(config, null, 2)
setEditorValue(JSON.stringify(config, null, 2))
setLastSavedConfig(config)
setIsDirty(false)
} }
return editorValue
} }
}, [config, lastSavedConfig, isDirty])
const displayValue = getInitialEditorValue()
const handleSave = () => { const handleSave = () => {
try { try {
@ -170,7 +169,7 @@ function RawJsonPanel() {
<div className="bg-muted/30 relative rounded-lg border"> <div className="bg-muted/30 relative rounded-lg border">
<ScrollArea className="h-[calc(100vh-20rem)] min-h-[200px]"> <ScrollArea className="h-[calc(100vh-20rem)] min-h-[200px]">
<Textarea <Textarea
value={editorValue} value={displayValue}
onChange={(e) => { onChange={(e) => {
setEditorValue(e.target.value) setEditorValue(e.target.value)
setIsDirty(true) setIsDirty(true)