{"record":{"id":"6d651e69ff667fc7","repo":"siyuan-note/siyuan","slug":"plugin-plugin-name-has-already-been-loaded","errorCode":null,"errorMessage":"plugin ${plugin.name} has already been loaded","messagePattern":"plugin (.+?) has already been loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/plugin/loader.ts","lineNumber":93,"sourceCode":"        }) as Plugin;\n        insertPluginCSS(item, getPluginsStyle());\n        return plugin;\n    } catch (error) {\n        document.getElementById(\"pluginsStyle\" + item.name)?.remove();\n        throw error;\n    }\n};\n\nconst getLifecycleManager = (app: App) => {\n    let manager = lifecycleManagers.get(app);\n    if (manager) {\n        return manager;\n    }\n    manager = new PluginLifecycleCoordinator<IPluginData, Plugin>({\n        create: (item) => createPlugin(app, item),\n        attach: (plugin) => {\n            if (app.plugins.some((item) => item.name === plugin.name)) {\n                throw new Error(`plugin ${plugin.name} has already been loaded`);\n            }\n            app.plugins.push(plugin);\n        },\n        onload: (plugin) => plugin.onload(),\n        init: (plugin) => plugin.kernel.init(),\n        onLayoutReady: (plugin) => plugin.onLayoutReady(),\n        mount: (plugin) => {\n            mountPlugin(plugin);\n            activateCustomBlockPlugin(plugin.name);\n        },\n        shouldReloadOnDataChange: (plugin) => plugin.onDataChanged === Plugin.prototype.onDataChanged,\n        onDataChanged: (plugin, reason) => plugin.onDataChanged(reason),\n        onunload: (plugin) => {\n            deactivateCustomBlockPlugin(plugin.name);\n            beginPluginTeardown(plugin);\n            return plugin.onunload();\n        },\n        uninstall: (plugin) => plugin.uninstall(),","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/plugin/loader.ts#L75-L111","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nloadPlugin(app, item); loadPlugin(app, item); // throws\n// after\nif (!app.plugins.some(p => p.name === item.name)) await loadPlugin(app, item);","handlingStrategy":"validation","validationCode":"if (app.plugins.some(p => p.name === pluginName)) return app.plugins.find(p => p.name === pluginName);","typeGuard":"const isLoaded = (app: App, name: string) => app.plugins.some(p => p.name === name);","tryCatchPattern":"try { await loadPlugin(app, item); } catch (e) { if (String(e.message).includes(\"has already been loaded\")) return existing; throw e; }","preventionTips":["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"],"tags":["plugins","lifecycle","duplicate"],"backgroundTag":"invalid-state-transition","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}