fix(config): stabilize config hook callbacks to prevent action/filter flicker

This commit is contained in:
2026-03-24 20:13:23 +01:00
parent 2ea4a8304f
commit 9e43282bbc
5 changed files with 173 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
* React hook for loading and updating a single parsed action config.
*/
import { useCallback } from "react";
import { useConfigItem } from "./useConfigItem";
import { fetchAction, updateAction } from "../api/config";
import type { ActionConfig, ActionConfigUpdate } from "../types/config";
@@ -23,12 +24,18 @@ export interface UseActionConfigResult {
* @param name - Action base name (e.g. ``"iptables"``).
*/
export function useActionConfig(name: string): UseActionConfigResult {
const fetchFn = useCallback(() => fetchAction(name), [name]);
const saveFn = useCallback(
(update: ActionConfigUpdate) => updateAction(name, update),
[name],
);
const { data, loading, error, saving, saveError, refresh, save } = useConfigItem<
ActionConfig,
ActionConfigUpdate
>({
fetchFn: () => fetchAction(name),
saveFn: (update) => updateAction(name, update),
fetchFn,
saveFn,
mergeOnSave: (prev, update) =>
prev
? {