{"record":{"id":"b44049b59d883857","repo":"eythaann/Seelen-UI","slug":"context-menu-has-no-target-to-emit-to","errorCode":null,"errorMessage":"Context menu has no target to emit to","messagePattern":"Context menu has no target to emit to","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/ui/svelte/context-menu/MenuItem.svelte","lineNumber":24,"sourceCode":"\n  interface MenuItemProps {\n    item: Extract<ContextMenuItem, { type: \"Item\" }>;\n  }\n\n  let { item }: MenuItemProps = $props();\n\n  // Optimistic state for checked\n  let internalChecked = $state(false);\n\n  $effect.pre(() => {\n    internalChecked = item.checked!!;\n  });\n\n  function handleClick() {\n    let target = gState.forwardTo || gState.owner;\n\n    if (!target) {\n      console.warn(\"Context menu has no target to emit to\");\n      return;\n    }\n\n    if (item.disabled) {\n      return;\n    }\n\n    if (item.checked !== null) {\n      // Toggle optimistic state\n      internalChecked = !internalChecked;\n    }\n\n    emitTo<ContextMenuCallbackPayload>(target, item.callbackEvent, {\n      key: item.key,\n      value: item.value,\n      checked: item.checked !== null ? internalChecked : null,\n      meta: gState.data?.meta,\n    });","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/src/ui/svelte/context-menu/MenuItem.svelte#L6-L42","documentation":"In the context-menu widget, MenuItem's handleClick() forwards the selected item's event to the menu's target: gState.forwardTo if set, otherwise gState.owner. When neither is set there is no webview/window to emit the selection to, so the click is ignored with this warning — the menu was opened without a proper owner/forward target.","triggerScenarios":"A context menu was shown (via the context-menu widget) without the emitting side passing an owner or forwardTo target — e.g. menu opened programmatically with incomplete state, the owner webview closed before the item was clicked, or state not hydrated when the menu is triggered from a detached/preloaded webview.","commonSituations":"Showing a context menu from custom widget code that omits the target in the open payload; the original window that opened the menu was destroyed while the menu stayed open; race where menu item is clicked before gState is populated; theme/plugin triggering the menu without wiring a listener for the emitted event.","solutions":["Ensure the code opening the menu passes a valid target (owner webview label or forwardTo) in the context-menu state/payload.","Verify a listener exists in the target window for the menu's emitted event (e.g. subscribe to the context-menu result event) and that the target is still alive when items are clicked.","Close/reopen the menu if its originating window was destroyed — stale menus have no target.","In the target widget, confirm the menu state was hydrated before user interaction (wait for the state/ready event)."],"exampleFix":"// before (opener side)\nshowContextMenu({ items }); // no target -> \"no target to emit to\"\n\n// after\nshowContextMenu({ items, forwardTo: currentWebviewLabel });\n// or in the menu, guard and close when orphaned:\nif (!gState.forwardTo && !gState.owner) {\n  console.warn(\"Context menu has no target to emit to\");\n  closeMenu();\n  return;\n}","handlingStrategy":"validation","validationCode":"if (!menuState.forwardTo && !menuState.owner) {\n  throw new Error(\"Cannot open context menu without an owner or forwardTo target\");\n}\nshowContextMenu(menuState);","typeGuard":"function hasMenuTarget(s: { forwardTo?: string | null; owner?: string | null }):\n  s is { forwardTo: string; owner?: string | null } | { forwardTo?: string | null; owner: string } {\n  return Boolean(s.forwardTo || s.owner);\n}","tryCatchPattern":"// in the target widget\ntry {\n  await subscribe(ContextMenuEvent, handler);\n} catch (err) {\n  console.error(\"Menu target is not listening for selections\", err);\n}","preventionTips":["Always pass owner (or forwardTo) when opening a context menu programmatically.","Close menus when their originating webview/window is destroyed.","Verify the target window subscribes to the menu result event before opening the menu.","Auto-close orphaned menus (no target) instead of leaving them clickable."],"tags":["context-menu","event","svelte","missing-target"],"backgroundTag":"event-target-missing","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"}