Fix NpmButton fetching config on every render

The useEffect updates list has the major pitfall that passing an object
via for example a prop like foo={{ bar: 1 }} to it causes it to to
detect it as a change on every re-render due to the newly created object
comparing unqual to the previously passed in object.

Unpack the object to prevent the identity from changing every time the
metrics update on the Host page.
This commit is contained in:
Hornwitser committed 2026-03-09 15:58:35 +01:00
1 parent 41b9eb1005
commit 2399fb9d15
1 file changed
+7 -2
+7 -2
View File
@@ -82,7 +82,11 @@ function NpmPluginInstall({ setApplyAction, form, target }: NpmActionProps) {
</>;
}
export function NpmButton(props: { target: lib.AddressShorthand, canRestart?: boolean, disabled?: boolean }) {
export function NpmButton(props: {
target: "controller" | { hostId: number },
canRestart?: boolean,
disabled?: boolean
}) {
const control = useContext(ControlContext);
const account = useAccount();
const [open, setOpen] = useState(false);
@@ -93,6 +97,7 @@ export function NpmButton(props: { target: lib.AddressShorthand, canRestart?: bo
remoteUpdates: true, pluginUpdates: true, pluginInstall: true,
});
const hostId = props.target === "controller" ? undefined : props.target.hostId;
useEffect(() => {
if (props.target === "controller") {
if (!account.hasPermission("core.controller.get_config")) {
@@ -121,7 +126,7 @@ export function NpmButton(props: { target: lib.AddressShorthand, canRestart?: bo
});
}).catch(notifyErrorHandler("Failed to fetch host config for remote updates"));
}
}, [props.target]);
}, [hostId]);
function onValuesChange({ action } : { action?: string }) {
if (action) {