siyuan-note/siyuan · error
plugin has already been loaded
Error message
plugin ${plugin.name} has already been loaded What it means
The plugin lifecycle coordinator's attach hook guards against duplicate plugin instances: before pushing a plugin into app.plugins it checks for an existing plugin with the same name and throws this error, preventing double initialization and duplicated event subscriptions.
Solutions
- Ensure loads are awaited/serialized; don't call the loader twice concurrently
- Unload the existing plugin (via the lifecycle coordinator) before reloading it
- Check app.plugins for the name first and skip if present
- If stuck, reload the window to clear duplicated instances
Example fix
// before loadPlugin(app, item); loadPlugin(app, item); // throws // after if (!app.plugins.some(p => p.name === item.name)) await loadPlugin(app, item);
Defensive patterns
Strategy: validation
Validate before calling
if (app.plugins.some(p => p.name === pluginName)) return app.plugins.find(p => p.name === pluginName);
Type guard
const isLoaded = (app: App, name: string) => app.plugins.some(p => p.name === name);
Try / catch
try { await loadPlugin(app, item); } catch (e) { if (String(e.message).includes("has already been loaded")) return existing; throw e; } Prevention
- Serialize plugin loads with a promise map keyed by plugin name
- Always unload before reload in dev/hot-reload flows
- Check app.plugins before installing/activating
When it happens
Trigger: Calling getPlugin/manager load flow twice for the same plugin without awaiting the first load — e.g. double-clicking a marketplace install, racing layout-ready loads, or reloading a plugin while the old instance is still registered.
Common situations: Rapid double activation of a plugin; a plugin's own code re-invoking load; hot-reload/dev flows that don't unload first; concurrent calls from multiple windows sharing an App instance.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- agent runtime turn is not finalized
- capability handler unavailable
- capability is disabled or no longer available
- Conf.Language(1)
- database block [ ] is already bound
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/6d651e69ff667fc7.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/plugin/loader.ts:93
}) as Plugin;
insertPluginCSS(item, getPluginsStyle());
return plugin;
} catch (error) {
document.getElementById("pluginsStyle" + item.name)?.remove();
throw error;
}
};
const getLifecycleManager = (app: App) => {
let manager = lifecycleManagers.get(app);
if (manager) {
return manager;
}
manager = new PluginLifecycleCoordinator<IPluginData, Plugin>({
create: (item) => createPlugin(app, item),
attach: (plugin) => {
if (app.plugins.some((item) => item.name === plugin.name)) {
throw new Error(`plugin ${plugin.name} has already been loaded`);
}
app.plugins.push(plugin);
},
onload: (plugin) => plugin.onload(),
init: (plugin) => plugin.kernel.init(),
onLayoutReady: (plugin) => plugin.onLayoutReady(),
mount: (plugin) => {
mountPlugin(plugin);
activateCustomBlockPlugin(plugin.name);
},
shouldReloadOnDataChange: (plugin) => plugin.onDataChanged === Plugin.prototype.onDataChanged,
onDataChanged: (plugin, reason) => plugin.onDataChanged(reason),
onunload: (plugin) => {
deactivateCustomBlockPlugin(plugin.name);
beginPluginTeardown(plugin);
return plugin.onunload();
},
uninstall: (plugin) => plugin.uninstall(),View on GitHub (pinned to 9f775e8a12)