fix: remove this.forceUpdate() calls that always throw

CommandViewer, MacroViewer, and MobileModifyComponent are all plain
function components (not classes), so `this` inside their handlers
is undefined - this.forceUpdate() has never been able to succeed
since the plugin's first release, it just throws before Preact ever
gets a chance to visually update in place. The actual state mutation
and settings.save() on each of these handlers already happens before
the throwing line, so removing it doesn't change what the UI shows;
it removes a guaranteed, silently-swallowed error on every add/
remove/reorder/rename/recolor action.

Also drops mobileModifyComponent's cmdr-icon-changed listener, whose
only job was calling the broken forceUpdate.

Given this changes real code paths, worth a manual pass: add/remove/
reorder/rename commands and macros from the settings tab, and check
the mobile icon-picker modal, to confirm nothing regresses now that
the throw is gone.
This commit is contained in:
johnny1093 2026-07-11 09:43:10 -04:00
parent 2b58c0cbe0
commit b83e10af6a
3 changed files with 1 additions and 19 deletions

View file

@ -25,7 +25,6 @@ export default function MacroViewer({
);
plugin.saveSettings();
this.forceUpdate();
updateMacroCommands(plugin);
modal.close();
};
@ -36,7 +35,6 @@ export default function MacroViewer({
const handleDelete = (idx: number): void => {
macros.splice(idx, 1);
plugin.saveSettings();
this.forceUpdate();
updateMacroCommands(plugin);
};

View file

@ -47,7 +47,6 @@ export default function CommandViewer({
).didChooseRemove())
) {
await manager.removeCommand(cmd);
this.forceUpdate();
}
}}
handleUp={(): void => {
@ -57,7 +56,6 @@ export default function CommandViewer({
idx - 1
);
manager.reorder();
this.forceUpdate();
}}
handleDown={(): void => {
arrayMoveMutable(
@ -66,7 +64,6 @@ export default function CommandViewer({
idx + 1
);
manager.reorder();
this.forceUpdate();
}}
handleRename={async (
name
@ -74,7 +71,6 @@ export default function CommandViewer({
cmd.name = name;
await plugin.saveSettings();
manager.reorder();
this.forceUpdate();
}}
handleNewIcon={async (): Promise<void> => {
const newIcon =
@ -85,7 +81,6 @@ export default function CommandViewer({
cmd.icon = newIcon;
await plugin.saveSettings();
manager.reorder();
this.forceUpdate();
}
dispatchEvent(
new Event("cmdr-icon-changed")
@ -110,7 +105,6 @@ export default function CommandViewer({
mode || modes[currentIdx + 1];
await plugin.saveSettings();
manager.reorder();
this.forceUpdate();
}}
handleColorChange={async (
color?: string
@ -147,7 +141,6 @@ export default function CommandViewer({
const pair = await chooseNewCommand(plugin);
await manager.addCommand(pair);
manager.reorder();
this.forceUpdate();
}}
>
{t("Add command")}

View file

@ -1,5 +1,4 @@
import { h } from "preact";
import { useEffect } from "preact/hooks";
import t from "src/l10n";
import { ObsidianIcon } from "src/util";
import MobileModifyModal from "../mobileModifyModal";
@ -7,20 +6,12 @@ import { ColorPicker } from "./ColorPicker";
import CommanderPlugin from "src/main";
export default function MobileModifyComponent({
plugin,
plugin,
modal: controller,
}: {
plugin: CommanderPlugin;
modal: MobileModifyModal;
}): h.JSX.Element {
useEffect(() => {
const update = (): void => {
this.forceUpdate();
};
addEventListener("cmdr-icon-changed", update);
return (): void => removeEventListener("cmdr-icon-changed", update);
}, []);
return (
<div className="cmdr-mobile-modify-grid">
<div