{"record":{"id":"4d8d4ccff87394ae","repo":"eythaann/Seelen-UI","slug":"current-monitor-not-found-4d8d4c","errorCode":null,"errorMessage":"Current monitor not found","messagePattern":"Current monitor not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ui/svelte/window-manager/state.svelte.ts","lineNumber":81,"sourceCode":"    sheet.addVariable(\"--config-margin-left\", `${settings.workspaceMargin.left}px`);\n    sheet.addVariable(\"--config-margin-right\", `${settings.workspaceMargin.right}px`);\n    sheet.addVariable(\"--config-margin-bottom\", `${settings.workspaceMargin.bottom}px`);\n    sheet.addVariable(\"--config-border-offset\", `${settings.border.offset}px`);\n    sheet.addVariable(\"--config-border-width\", `${settings.border.width}px`);\n    sheet.applyToDocument();\n  });\n});\n\n// =================================================\n//                   Positioning\n// =================================================\n\nconst monitorId = Widget.getCurrent().decoded.monitorId!;\n\nconst widgetRect = $derived.by(() => {\n  const monitor = monitors.value.find((m) => m.id === monitorId);\n  if (!monitor) {\n    throw new Error(\"Current monitor not found\");\n  }\n\n  const rect = { ...monitor.rect };\n  const tbConfig = fullSettings.byWidget[\"@seelen/fancy-toolbar\"];\n  const tbMonitorConfig = (fullSettings.monitorsV3[monitor.id] as any)?.byWidget?.[\n    \"@seelen/fancy-toolbar\"\n  ] ?? {\n    enabled: true,\n  };\n\n  if (\n    tbConfig.enabled &&\n    tbMonitorConfig.enabled &&\n    (tbConfig.hideMode === HideMode.Never || isTouchPrimary.value)\n  ) {\n    const tbSize = Math.round(\n      (tbConfig.itemSize + tbConfig.padding * 2 + tbConfig.margin * 2) * monitor.scaleFactor,\n    );","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/src/ui/svelte/window-manager/state.svelte.ts#L63-L99","documentation":"The window-manager widget resolves its target monitor via `monitors.value.find((m) => m.id === monitorId)` where `monitorId` comes from the widget's decoded `decoded.monitorId!`. If the backend monitor list has no such id, the `widgetRect` derivation throws `Current monitor not found`, preventing WM window-rect calculations.","triggerScenarios":"The widget was created for a monitor id that no longer exists in `monitors.value` (display unplugged between widget creation and render); `decoded.monitorId` is stale in the widget URL/definition; monitors signal not yet loaded at first derivation.","commonSituations":"Monitor hot-plug while a WM toolbar widget is attached; stale widget definition cached with an old monitor id; race at app startup before the first monitor list event.","solutions":["Guard the derivation: return a default rect or skip rendering when the monitor is missing.","Re-request the current monitor id on `MonitorsChanged` instead of trusting the stale `decoded.monitorId!`.","Verify the widget creation flow passes a valid, current monitor id into the widget URL."],"exampleFix":"// before\nconst monitor = monitors.value.find((m) => m.id === monitorId);\nif (!monitor) throw new Error(\"Current monitor not found\");\n// after\nconst monitor = monitors.value.find((m) => m.id === monitorId);\nif (!monitor) return null; // or fallback rect\n","handlingStrategy":"validation","validationCode":"const monitorId = Widget.getCurrent().decoded.monitorId;\nif (!monitorId || !monitors.value.some((m) => m.id === monitorId)) {\n  // skip rendering or re-request the monitor before using widgetRect\n}","typeGuard":"function hasValidMonitor(id: string | undefined): id is string {\n  return !!id && monitors.value.some((m) => m.id === id);\n}","tryCatchPattern":"try {\n  const rect = widgetRect.value;\n} catch (e) {\n  if ((e as Error).message === \"Current monitor not found\") {\n    // re-fetch monitor list, then retry once\n  } else throw e;\n}","preventionTips":["Don't trust stale `decoded.monitorId!`; re-resolve on monitor changes.","Wait for the monitors signal to load before first derivation.","Validate the widget URL's monitorId at widget creation time."],"tags":["monitors","window-manager","race-condition","svelte"],"backgroundTag":"monitor-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"}