-
Notifications
You must be signed in to change notification settings - Fork 537
fix: trial not starting during onboarding #3805
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
Open
devin-ai-integration
wants to merge
1
commit into
main
Choose a base branch
from
devin/1770687658-fix-trial-onboarding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import type { Session } from "@supabase/supabase-js"; | ||
|
|
||
| import { commands as authCommands } from "@hypr/plugin-auth"; | ||
|
|
||
| const INITIAL_DELAY_MS = 1000; | ||
| const MAX_DELAY_MS = 5000; | ||
| const BACKOFF_FACTOR = 1.5; | ||
| const MAX_ATTEMPTS = 10; | ||
|
|
||
| export type PollResult = | ||
| | { status: "activated"; session: Session } | ||
| | { status: "timeout" } | ||
| | { status: "aborted" }; | ||
|
|
||
| type PollOptions = { | ||
| refreshSession: () => Promise<Session | null>; | ||
| signal?: AbortSignal; | ||
| }; | ||
|
|
||
| export async function pollForTrialActivation( | ||
| options: PollOptions, | ||
| ): Promise<PollResult> { | ||
| let delay = INITIAL_DELAY_MS; | ||
|
|
||
| for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) { | ||
| if (options.signal?.aborted) { | ||
| return { status: "aborted" }; | ||
| } | ||
|
|
||
| try { | ||
| await new Promise<void>((resolve, reject) => { | ||
| const timer = setTimeout(resolve, delay); | ||
| if (options.signal) { | ||
| const onAbort = () => { | ||
| clearTimeout(timer); | ||
| reject(new DOMException("Aborted", "AbortError")); | ||
| }; | ||
| options.signal.addEventListener("abort", onAbort, { once: true }); | ||
| } | ||
| }); | ||
| } catch (e) { | ||
| if (e instanceof DOMException && e.name === "AbortError") { | ||
| return { status: "aborted" }; | ||
| } | ||
| throw e; | ||
| } | ||
|
|
||
| if (options.signal?.aborted) { | ||
| return { status: "aborted" }; | ||
| } | ||
|
|
||
| try { | ||
| const session = await options.refreshSession(); | ||
| if (session) { | ||
| const result = await authCommands.decodeClaims(session.access_token); | ||
| if (result.status === "ok") { | ||
| const entitlements = result.data.entitlements ?? []; | ||
| if (entitlements.includes("hyprnote_pro")) { | ||
| return { status: "activated", session }; | ||
| } | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.warn( | ||
| `Trial activation poll attempt ${attempt + 1} failed:`, | ||
| error, | ||
| ); | ||
| } | ||
|
|
||
| delay = Math.min(delay * BACKOFF_FACTOR, MAX_DELAY_MS); | ||
| } | ||
|
|
||
| return { status: "timeout" }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 AbortController cleanup + hasHandledRef causes infinite loading in React StrictMode
In development mode with React StrictMode (enabled at
apps/desktop/src/main.tsx:133), the component gets stuck on the loading screen forever.Root Cause: StrictMode double-mount interacts badly with hasHandledRef + AbortController
React StrictMode unmounts and re-mounts components to surface side-effect bugs. The sequence is:
hasHandledRef.currentset totrue→handle()starts async → cleanup function returnedabortController.abort()→ the in-flighthandle()will see the aborthasHandledRef.currentis stilltrue(refs persist across StrictMode remounts) → returns early without starting any work or returning a cleanup functionThe
handle()from step 1 reachespollForTrialActivationwhich detects the aborted signal and returns{ status: "aborted" }. Back inhandle()at line 66,if (result.status === "aborted") return;causes it to return without callingsetIsLoading(false). The second mount never starts a newhandle()becausehasHandledRefblocks it.Result:
isLoadingremainstrueforever, and the user sees the spinner indefinitely.Impact: Developers working on the onboarding flow in dev mode will be unable to proceed past the final step. This doesn't affect production builds since StrictMode effects only double-fire in development.
The fix should either: (a) remove
hasHandledRefand rely solely on theAbortControllercleanup (letting StrictMode re-run the effect properly on remount), or (b) resethasHandledRef.current = falsein the cleanup function so the second mount can re-execute.(Refers to lines 38-83)
Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.