fix(desktop): resolve the plugin-SDK namespaces lazily so bundler order can't break runtime plugins - #107518
fix(desktop): resolve the plugin-SDK namespaces lazily so bundler order can't break runtime plugins#107518ligorx wants to merge 1 commit into
Conversation
…er can't break runtime plugins
`apps/desktop/src/sdk/runtime.ts` captured its namespace map at module init:
const GLOBALS = { __HERMES_PLUGIN_SDK__: sdk, ... } as const
The 2026-09-10 packaged build emitted that map BEFORE `./index` assigns its
namespace binding (minified: `var bg={...}` @157012, `var Lb=t({...})` @231521),
so the SDK namespace was captured as `undefined` and `Object.keys(undefined)`
inside `shimUrl` threw for EVERY runtime (disk) plugin:
[plugins] runtime load failed (provider-usage) TypeError: Cannot convert
undefined or null to object (.../assets/sdk-RKHbz2ri.js:5)
`installPluginSdk()`/`sdkImportMap()` build all four shims eagerly, so one
unassigned namespace killed the whole map for every plugin; the 2026-08-31 build
emitted the same two statements in the other order, which is why this only
appeared with the rebuild.
Resolving the namespaces inside a function reads them when they are guaranteed
assigned (plugin load) instead of at module-init time. Nothing else changes.
|
Confirmed on the affected machine (Windows,
So the failure is confirmed fixed by this change; the patch in this PR is the same code path, made at the source. |
|
Clean-rebuild confirmation: I rebuilt the desktop app from this patched source (electron-builder via |
|
Closing as a duplicate of #107303 (@g3org3yo, merged as 6c3d4a4 on 2026-09-10), which lands the same fix — Thanks for the independent diagnosis and the Windows packaged-build confirmation — the issue was real and the approach matched what merged. Credit for the fix goes to the earliest submitter per repo policy; if a follow-up gap surfaces in production builds, please open a fresh PR against current |
What breaks
On the 2026-09-10 packaged Windows build (
main@073c57872a4) every runtime (disk) desktop plugin fails to load — reproducibly, for two unrelated plugins:Capabilities → Pluginslists both desktop plugins asfailedwith that message, and none of their contributions register (status-bar chips, palette commands). It hits unrelated plugins, so this is not plugin-specific: no disk plugin can load at all.Why
apps/desktop/src/sdk/runtime.tsmaterialises its namespace map at module init:In that build the bundler emitted this module's body before
./indexassigns its namespace binding:dist/assets/sdk-*.js)var bg={__HERMES_PLUGIN_SDK__:Lb, …}(this file)var Lb=t({…})(the./indexnamespace)so
bg.__HERMES_PLUGIN_SDK__was captured asundefined. The loader then runsinstallPluginSdk()/shimUrl(), whoseObject.keys(GLOBALS[key])throws exactly this TypeError; becausesdkImportMap()builds all four shims eagerly and only caches them on success, one unassigned namespace kills the map for every plugin.The previous packaged build (2026-08-31) emitted the same two statements in the opposite order (
var kp=…@101714,var tm=…@116891) and worked. Same source, different bundler order — which is why this appeared only with the rebuild, and why the capture is the bug.Fix
Resolve the namespaces inside a function, so they are read at call time (plugin load, when they are guaranteed assigned) instead of at module-init time. Nothing else changes.
Verification
TypeError: Cannot convert undefined or null to object; the lazy form → the namespace's live keys, globals installed.