{"record":{"id":"de2aa28f35dfc509","repo":"jlcodes99/cockpit-tools","slug":"failed-to-apply-startup-page-preference","errorCode":null,"errorMessage":"Failed to apply startup page preference:","messagePattern":"Failed to apply startup page preference:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/App.tsx","lineNumber":820,"sourceCode":"      console.warn('Failed to save active page to localStorage:', e);\n    }\n  }, [page]);\n\n  // 冷启动：若设置了固定启动页，则覆盖 localStorage 中的上次页面\n  useEffect(() => {\n    let disposed = false;\n    const applyStartupPagePreference = async () => {\n      try {\n        const config = await invoke<{ startup_page?: string }>('get_general_config');\n        if (disposed) {\n          return;\n        }\n        const preferred = normalizeStartupPagePreference(config.startup_page);\n        if (preferred !== 'last') {\n          setPage(preferred);\n        }\n      } catch (error) {\n        console.warn('Failed to apply startup page preference:', error);\n      }\n    };\n    void applyStartupPagePreference();\n    return () => {\n      disposed = true;\n    };\n  }, []);\n\n  // 冷启动：根据用户配置自动恢复 Codex 代理接管状态\n  useEffect(() => {\n    void useCodexAccountStore.getState().restoreActiveTakeoverIfNeeded();\n  }, []);\n\n  // 主窗口切到某平台页（如 Grok）时，同步悬浮窗/菜单栏当前平台，避免一直停在默认 antigravity\n  useEffect(() => {\n    const platformId = resolvePlatformIdFromPage(page);\n    if (!platformId) {\n      return;","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/App.tsx#L802-L838","documentation":"MainApp applies the persisted startup_page configuration via normalizeStartupPagePreference and setPage; if reading or processing the preference throws, this warning is logged and the app falls back to its default page. It is non-fatal by design: a bad preference should never block app startup.","triggerScenarios":"The async config load rejects (Tauri store/backend read failure, config file corrupt or missing), or config.startup_page contains a value normalizeStartupPagePreference doesn't recognize and downstream code assumptions break.","commonSituations":"Hand-edited or migrated config files with an unexpected startup_page value; permission errors reading the config dir; backend store plugin not ready at first render.","solutions":["Log the caught error's contents to see whether it is an IO error or a parse error","Validate/normalize startup_page against the known enum before use; normalizeStartupPagePreference should already coerce unknown values — check its input isn't undefined/null in an unexpected shape","Repair or reset the config file / persisted store holding startup_page","Ensure the config backend (Tauri store plugin) is initialized before this effect runs"],"exampleFix":"// before\nconst preferred = normalizeStartupPagePreference(config.startup_page);\nif (preferred !== 'last') setPage(preferred);\n// after\nconst preferred = normalizeStartupPagePreference(config?.startup_page);\nif (preferred && preferred !== 'last') setPage(preferred);","handlingStrategy":"validation","validationCode":"const STARTUP_PAGES = ['home', 'accounts', 'settings', 'last'] as const;\ntype StartupPage = typeof STARTUP_PAGES[number];\nfunction isValidStartupPage(v: unknown): v is StartupPage {\n  return typeof v === 'string' && (STARTUP_PAGES as readonly string[]).includes(v);\n}","typeGuard":"function isStartupPageConfig(v: unknown): v is { startup_page: StartupPage } {\n  return isPlainObject(v) && isValidStartupPage((v as { startup_page?: unknown }).startup_page);\n}","tryCatchPattern":"try {\n  const config = await loadConfig();\n  const preferred = normalizeStartupPagePreference(config?.startup_page);\n  if (preferred !== 'last') setPage(preferred);\n} catch (error) {\n  console.warn('Failed to apply startup page preference:', error);\n  // keep default page\n}","preventionTips":["Validate config values against the allowed enum at load time","Coerce unknown startup_page values to the default instead of trusting raw config","Guard against null/undefined config objects","Write config through a typed writer so invalid values can't be persisted"],"tags":["config","startup","react"],"backgroundTag":"invalid-config-value","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}