{"record":{"id":"36007d9eca14ff21","repo":"eythaann/Seelen-UI","slug":"widget-definition-not-found-for-currentwidgetid","errorCode":null,"errorMessage":"Widget definition not found for ${currentWidgetId}","messagePattern":"Widget definition not found for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ui/vanilla/entry-point/MainSetup.ts","lineNumber":15,"sourceCode":"import type { Widget } from \"@seelen-ui/lib/types\";\nimport { _invoke, webviewInfo } from \"src/ui/vanilla/entry-point/_tauri.ts\";\nimport { listen } from \"@tauri-apps/api/event\";\n\nimport { hookLocalStorage } from \"src/ui/vanilla/entry-point/_LocalStorage\";\n\nconst indexJsCode = fetch(\"./index.js\").then((res) => res.text());\n\n// initialize global widget variable, needed by slu-lib\nconst currentWidgetId = webviewInfo.widgetId;\nconst widgetList = await _invoke<Widget[]>(\"state_get_widgets\");\nwindow.__SLU_WIDGET = widgetList.find((widget) => widget.id === currentWidgetId)!;\n\nif (!window.__SLU_WIDGET) {\n  throw new Error(`Widget definition not found for ${currentWidgetId}`);\n}\n\n// reload if widget definition changed\nlisten<Widget[]>(\"widgets-changed\", ({ payload }) => {\n  const actual = payload.find((widget) => widget.id === currentWidgetId);\n  if (actual && JSON.stringify(actual) !== JSON.stringify(window.__SLU_WIDGET)) {\n    window.location.reload();\n  }\n});\n\n// set document id\ndocument.documentElement.id = currentWidgetId;\n\n// hook local storage, to avoid collition of keys\nhookLocalStorage(currentWidgetId);\n\n// add base css\nconst link = document.createElement(\"link\");","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/src/ui/vanilla/entry-point/MainSetup.ts#L1-L33","documentation":"During vanilla widget bootstrap (`MainSetup.ts`), the app fetches the widget list from the backend (`state_get_widgets`) and looks up the definition matching this webview's widget id. If none matches, `window.__SLU_WIDGET` stays undefined and the setup throws `Widget definition not found for <id>`. This means the backend does not know a widget with that id.","triggerScenarios":"The widget id encoded in the webview URL is not present in the backend's widget registry — e.g. widget was uninstalled/renamed while its webview still runs, a custom widget id mismatch between `metadata.yml` and the launching code, or `state_get_widgets` returned a stale/partial list.","commonSituations":"Developing a custom widget with an id that doesn't match the registered resource id (`@user/name`); updating a built-in widget's id without restarting the app; loading a widget resource whose metadata failed to parse on the backend.","solutions":["Verify the widget id in the webview URL matches the `id` in the widget's `metadata.yml` exactly.","Restart Seelen UI (or re-run `slu resource load widget ./my-widget`) so the backend registry includes the widget.","Check that `state_get_widgets` returns the expected list (log it) and that the widget resource loaded without errors."],"exampleFix":"// before\nwindow.__SLU_WIDGET = widgetList.find((w) => w.id === currentWidgetId)!;\n// after\nwindow.__SLU_WIDGET = widgetList.find((w) => w.id === currentWidgetId);\nif (!window.__SLU_WIDGET) {\n  console.error(\"Available:\", widgetList.map((w) => w.id));\n  throw new Error(`Widget definition not found for ${currentWidgetId}`);\n}","handlingStrategy":"validation","validationCode":"const widgetList = await _invoke<Widget[]>(\"state_get_widgets\");\nconst def = widgetList.find((w) => w.id === currentWidgetId);\nif (!def) {\n  console.error(\"Registered ids:\", widgetList.map((w) => w.id));\n  // bail out gracefully before assigning window.__SLU_WIDGET\n}","typeGuard":"function isRegisteredWidget(widgets: Widget[], id: string): boolean {\n  return widgets.some((w) => w.id === id);\n}","tryCatchPattern":"try {\n  await bootstrapWidget();\n} catch (e) {\n  if (String((e as Error).message).startsWith(\"Widget definition not found\")) {\n    console.error(\"Widget id mismatch — check metadata.yml id vs webview id\");\n  } else throw e;\n}","preventionTips":["Keep the widget id in metadata.yml identical to the id used to launch the webview.","Reload resources (`slu resource load widget`) after renaming a widget.","Log the available widget ids on failure to spot id mismatches quickly."],"tags":["widget","bootstrap","resource-registry"],"backgroundTag":"widget-definition-not-found","analyzedSha":"dee4aaa94066c5d0888ab25554864862fc47be15","analyzedAt":"2026-09-03T10:20:37.842Z","contentChangedAt":"2026-09-03T10:20:37.842Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}