Reload the web interface when the controller's plugins change

The web interface loads plugin bundles, registers their messages and
adds their config fields once in bootstrap, and has no way to undo any
of it.  A controller restarted to pick up a plugin being installed,
enabled or disabled comes back running a different set, and a controller
started in recovery mode runs none of them while still accepting control
connections, so open pages carry on sending messages it no longer
handles.

The controller already states the plugins it is running in the handshake
it sends on every connection, which is what hosts track as serverPlugins
and use to decide what to forward and which instance plugins to load.
Compare that against the set the page loaded and stop rendering on a
mismatch, asking to be reloaded instead.

The comparison is against loaded rather than enabled because loaded is
what the handshake reports and what the controller is actually running;
enabled also takes load_plugin into account, which only applies from the
next restart and would otherwise latch a permanent mismatch.

Closes #804
This commit is contained in:
bbassie committed 2026-08-10 10:01:35 +00:00
1 parent 5e0ab3423f
commit e3c18db7b8
4 files changed
+73 -6

No files matched your search

+39 -2
View File
@@ -9,8 +9,9 @@ import ErrorBoundary from "./ErrorBoundary";
import SiteLayout from "./SiteLayout";
import ControlContext from "./ControlContext";
import LoginForm from "./LoginForm";
import { pluginSetKey } from "../util/pluginSet";
import { Card, ConfigProvider, Spin, Typography, theme } from "antd";
import { Button, Card, ConfigProvider, Spin, Typography, theme } from "antd";
const { Paragraph } = Typography;
@@ -28,11 +29,28 @@ function ErrorCard(props: ErrorProps) {
}
function PluginsChangedCard() {
return <div className="login-container">
<Card>
<h1>Reload required</h1>
<Paragraph>
The plugins the controller is running have changed since this page was opened. Plugin code,
messages and config fields are loaded once when the page starts and cannot be swapped out
while it runs, so this page has been stopped to keep it from acting on plugins that are no
longer there.
</Paragraph>
<Button type="primary" onClick={() => window.location.reload()}>Reload</Button>
</Card>
</div>;
}
type AppProps = {
control: Control;
};
export default function App(props: AppProps) {
let [connected, setConnected] = useState(false);
let [pluginsChanged, setPluginsChanged] = useState(false);
let [token, setToken] = useState(localStorage.getItem("controller_token") || null);
let connector = props.control.connector;
@@ -73,6 +91,22 @@ export default function App(props: AppProps) {
};
}, [token, props.control]);
// The controller reports the plugins it is running in the handshake it
// sends on every connection, so restarting it to install, enable or
// disable a plugin, or into recovery mode, is caught on reconnect.
useEffect(() => {
function onHello(data: any) {
if (pluginSetKey(data.plugins) !== props.control.pluginSetKey) {
setPluginsChanged(true);
}
}
connector.on("hello", onHello);
return () => {
connector.off("hello", onHello);
};
}, [props.control]);
useEffect(() => {
if (token && !connected) {
if (props.control.loggingOut) {
@@ -86,7 +120,10 @@ export default function App(props: AppProps) {
}, [token, connected]);
let page;
if (connected) {
if (pluginsChanged) {
page = <PluginsChangedCard />;
} else if (connected) {
page = <SiteLayout/>;
} else if (token) {