-
Notifications
You must be signed in to change notification settings - Fork 906
fix(desktop): resolve v2 default from local db, not stale localStorage #4176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||||||||
| import { electronTrpc } from "renderer/lib/electron-trpc"; | ||||||||||||||||||||||||||||||||||||||||||
| import { useV2LocalOverrideStore } from "renderer/stores/v2-local-override"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export function V2DefaultResolver() { | ||||||||||||||||||||||||||||||||||||||||||
| const optInV2 = useV2LocalOverrideStore((s) => s.optInV2); | ||||||||||||||||||||||||||||||||||||||||||
| const isFreshInstall = useV2LocalOverrideStore((s) => s.isFreshInstall); | ||||||||||||||||||||||||||||||||||||||||||
| const setOptInV2 = useV2LocalOverrideStore((s) => s.setOptInV2); | ||||||||||||||||||||||||||||||||||||||||||
| const setIsFreshInstall = useV2LocalOverrideStore((s) => s.setIsFreshInstall); | ||||||||||||||||||||||||||||||||||||||||||
| const utils = electronTrpc.useUtils(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||
| if (optInV2 !== null && isFreshInstall !== null) return; | ||||||||||||||||||||||||||||||||||||||||||
| let cancelled = false; | ||||||||||||||||||||||||||||||||||||||||||
| void Promise.all([ | ||||||||||||||||||||||||||||||||||||||||||
| utils.workspaces.hasAny.fetch(), | ||||||||||||||||||||||||||||||||||||||||||
| utils.projects.hasAny.fetch(), | ||||||||||||||||||||||||||||||||||||||||||
| ]).then(([hasWorkspace, hasProject]) => { | ||||||||||||||||||||||||||||||||||||||||||
| if (cancelled) return; | ||||||||||||||||||||||||||||||||||||||||||
| const isFresh = !hasWorkspace && !hasProject; | ||||||||||||||||||||||||||||||||||||||||||
| const current = useV2LocalOverrideStore.getState(); | ||||||||||||||||||||||||||||||||||||||||||
| if (current.optInV2 === null) setOptInV2(isFresh); | ||||||||||||||||||||||||||||||||||||||||||
| if (current.isFreshInstall === null) setIsFreshInstall(isFresh); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle resolver fetch failures to avoid unhandled rejections. If either Suggested fix void Promise.all([
utils.workspaces.hasAny.fetch(),
utils.projects.hasAny.fetch(),
- ]).then(([hasWorkspace, hasProject]) => {
- if (cancelled) return;
- if (useV2LocalOverrideStore.getState().optInV2 !== null) return;
- setOptInV2(!hasWorkspace && !hasProject);
- });
+ ])
+ .then(([hasWorkspace, hasProject]) => {
+ if (cancelled) return;
+ if (useV2LocalOverrideStore.getState().optInV2 !== null) return;
+ setOptInV2(!hasWorkspace && !hasProject);
+ })
+ .catch(() => {
+ // Keep unresolved state on failure; retry on next mount.
+ });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+15
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/desktop/src/renderer/components/V2DefaultResolver/V2DefaultResolver.tsx
Line: 13-20
Comment:
**Unhandled rejection leaves `optInV2` permanently `null`**
The `Promise.all` is prefixed with `void`, which silences the unhandled-rejection warning but means a tRPC error (e.g., IPC hiccup on startup) causes both `hasAny` calls to throw, the `.then` callback never runs, and `optInV2` stays `null` forever for that session. Because `useIsV2CloudEnabled` treats `null` as `false`, a fresh-install user would see v1 indefinitely and never get the intended v2 default — even after the IPC channel recovers — until they manually restart or toggle.
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||||||||||||||
| cancelled = true; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| }, [optInV2, isFreshInstall, setOptInV2, setIsFreshInstall, utils]); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { V2DefaultResolver } from "./V2DefaultResolver"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { useV2LocalOverrideStore } from "renderer/stores/v2-local-override"; | ||
|
|
||
| /** Returns whether this install was empty when first detected, or null if still resolving. */ | ||
| export function useIsFreshInstall(): boolean | null { | ||
| return useV2LocalOverrideStore((s) => s.isFreshInstall); | ||
| } |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.