Conversation
When the app is closed and set as default browser, clicking a link in another app caused two windows to appear: one from the URL handler and one from session restore. This happened because processInitialUrl() / open-url and restoreSession() both independently detected zero windows and created their own. Queue external URLs received during startup instead of handling them immediately. After session restore (or initial window creation) completes, flush the queue so the URL opens as a new tab in the already-restored window. Also fixes restoreSession() not being awaited in the onboarding flow, which could have caused further timing issues.
Contributor
Build artifacts for all platforms are ready! 🚀Download the artifacts for: One-line installer (Unstable):bunx flow-debug-build --open 22586327955(execution 22586327955 / attempt 1) |
Greptile SummaryThis PR fixes a race condition where opening an external URL during cold start created two windows instead of one. The fix introduces a queueing mechanism: URLs received before startup completes are queued and then flushed after the initial window (either onboarding or session restore) is created, ensuring they open as tabs in the existing window. Key changes:
The solution elegantly coordinates two previously-independent async paths ( Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as Command Line / OS
participant URL as urls.ts
participant OB as onboarding.ts
participant WC as Window Controller
Note over CLI,WC: Before Fix (Race Condition)
CLI->>URL: processInitialUrl()
CLI->>OB: runOnboardingOrInitialWindow()
par Parallel Execution
URL->>WC: handleOpenUrl() sees 0 windows
WC->>WC: Create Window #1 for URL
and
OB->>WC: restoreSession()
WC->>WC: Create Window #2 from session
end
Note over CLI,WC: Result: 2 windows created
Note over CLI,WC: After Fix (Coordinated)
CLI->>URL: processInitialUrl()
CLI->>OB: runOnboardingOrInitialWindow()
URL->>URL: handleOpenUrl() checks startupComplete=false
URL->>URL: Queue URL in pendingStartupUrls
OB->>WC: await restoreSession()
WC->>WC: Create Window from session
OB->>URL: flushPendingUrls()
URL->>URL: Set startupComplete=true
URL->>WC: Open queued URLs as tabs in existing window
Note over CLI,WC: Result: 1 window with URL as tab
Last reviewed commit: a150491 |
Replace flushPendingUrls() with discardPendingUrls() in the onboarding code paths so no browser windows are created while onboarding is active. The new helper marks startup as complete (so subsequent open-url events work normally) but drops any queued URLs silently.
Previously only queued startup URLs were discarded; URLs arriving after discardPendingUrls() (via open-url, continue-activity, etc.) would still create browser windows alongside the onboarding window. Add an onboardingActive flag that causes handleOpenUrl() to silently drop every incoming URL while onboarding is in progress. The flag is cleared in the onboarding:finish IPC handler so normal URL handling resumes once the user completes onboarding.
…tive flag Replace the manual onboardingActive flag and setOnboardingComplete() with a check against the existing hasCompletedOnboarding() in handleOpenUrl(). This leverages the cached onboarding state that is already the source of truth elsewhere, removing redundant state and the need to hook into the onboarding:finish IPC handler.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a bug where opening a link from another app (while Flow is set as default browser and is closed) creates two windows instead of opening the URL as a tab in the restored session window.
Root Cause
When the app cold-starts via an external URL, two independent async paths race with no coordination in
browser.ts:processInitialUrl()(or macOSopen-urlevent) →handleOpenUrl()sees 0 windows → creates Window Custom Page Load Error #1runOnboardingOrInitialWindow()→restoreSession()→ creates Window Redesign #2 from persisted tabsBoth run concurrently, neither knows about the other, and both independently create windows.
Fix
src/main/app/urls.ts: Added a startup URL queue. During cold start (startupComplete === false),handleOpenUrl()queues URLs instead of creating windows immediately. NewflushPendingUrls()function sets the flag and opens all queued URLs using the already-existing restored windows.src/main/app/onboarding.ts: After session restore completes, callsflushPendingUrls()so queued URLs open as new tabs in the restored window. Also properlyawaitscreateInitialWindow()which was previously fire-and-forget.Behavior After Fix
startupCompleteis alreadytrue)