{"record":{"id":"c0055a5271998031","repo":"eythaann/Seelen-UI","slug":"widget-was-not-initialized-before-ready","errorCode":null,"errorMessage":"Widget was not initialized before ready","messagePattern":"Widget was not initialized before ready","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libs/core/src/state/widget/mod.ts","lineNumber":294,"sourceCode":"\n    if (options.disableCssAnimations ?? true) {\n      await disableAnimationsOnPerformanceMode();\n    } else {\n      console.trace(\"Animations won't be disabled because widget configuration\");\n    }\n  }\n\n  /**\n   * Will mark the widget as `ready` and pool pending triggers.\n   *\n   * If the widget is not lazy this will inmediately show the widget.\n   * Lazy widget should be shown on trigger action.\n   */\n  public async ready(options: ReadyWidgetOptions = {}): Promise<void> {\n    const { show = !this.def.lazy } = options;\n\n    if (!this.runtimeState.initialized) {\n      throw new Error(`Widget was not initialized before ready`);\n    }\n\n    if (this.runtimeState.ready) {\n      console.warn(`Widget is already ready`);\n      return;\n    }\n\n    this.runtimeState.ready = true;\n    await this.autoSizer?.execute();\n\n    if (show && !(await this.window.isVisible())) {\n      await this.show();\n    }\n\n    // this will mark the widget as ready, and send pending trigger event if exists\n    await invoke(SeelenCommand.SetCurrentWidgetStatus, { status: WidgetStatus.Ready });\n  }\n","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/libs/core/src/state/widget/mod.ts#L276-L312","documentation":"Widget.ready() signals that a widget finished setup and can be shown (unless lazy, where it is shown on a trigger action). The library requires the lifecycle to start with initialization (which computes the decoded webview label and config); calling ready() on an instance whose runtimeState.initialized flag is false means ready() was called out of order, so it throws instead of proceeding with an unconfigured widget.","triggerScenarios":"Calling widget.ready() before the widget's init step completed; forgetting `await` on init and calling ready() synchronously; creating a second Widget instance manually (bypassing the initialized getCurrent() singleton) and calling ready() on it; calling ready() from module top-level code that races the async init.","commonSituations":"Restructuring widget entry code and accidentally moving ready() above init; dropping an await during a refactor; using new Widget(...) directly; init triggered by an event that has not fired yet.","solutions":["Await init before ready(): await Widget.getCurrent().init(...) then await widget.ready().","Use the singleton from Widget.getCurrent() rather than constructing Widget manually.","Gate ready() on a flag or a promise that resolves after initialization.","Log runtimeState before ready() when debugging order issues."],"exampleFix":"// before: const widget = Widget.getCurrent(); widget.ready(); // throws\n// after: const widget = Widget.getCurrent(); await widget.init(); await widget.ready();","handlingStrategy":"validation","validationCode":"// track init completion in your bootstrap: let initialized = false; await widget.init(); initialized = true; if (!initialized) throw new Error('call init() before ready()');","typeGuard":"function isInitialized(w: Widget): boolean { return (w as unknown as { runtimeState: { initialized: boolean } }).runtimeState.initialized; }","tryCatchPattern":"try { await widget.ready(); } catch (e) { if (e instanceof Error && e.message.startsWith('Widget was not initialized')) { await widget.init(); await widget.ready(); } else { throw e; } }","preventionTips":["Always await init() before ready() in the widget entry point.","Use the Widget.getCurrent() singleton instead of constructing Widget manually.","Never call ready() from top-level code that may run before init.","Keep init/ready ordering in one bootstrap function to make the lifecycle auditable."],"tags":["lifecycle","initialization","async"],"backgroundTag":"method-called-before-init","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"}