-
Notifications
You must be signed in to change notification settings - Fork 33
fix(folder-picker): show loading state to fix dead clicks on repo selector #2473
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
Merged
charlesvien
merged 1 commit into
main
from
posthog-code/fix-dead-clicks-on-repo-selector
Jun 4, 2026
+117
−5
Merged
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
90 changes: 90 additions & 0 deletions
90
apps/code/src/renderer/features/folder-picker/components/FolderPicker.test.tsx
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,90 @@ | ||
| import { Theme } from "@radix-ui/themes"; | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const selectDirectoryQuery = vi.fn(); | ||
| const addFolder = vi.fn().mockResolvedValue(undefined); | ||
|
|
||
| vi.mock("@renderer/trpc", () => ({ | ||
| trpcClient: { | ||
| os: { selectDirectory: { query: () => selectDirectoryQuery() } }, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("@features/folders/hooks/useFolders", () => ({ | ||
| useFolders: () => ({ | ||
| getRecentFolders: () => [], | ||
| getFolderDisplayName: () => null, | ||
| addFolder, | ||
| updateLastAccessed: vi.fn(), | ||
| getFolderByPath: vi.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@utils/logger", () => ({ | ||
| logger: { scope: () => ({ error: vi.fn() }) }, | ||
| })); | ||
|
|
||
| import { FolderPicker } from "./FolderPicker"; | ||
|
|
||
| /** A promise we resolve by hand, to hold the picker open mid-flight. */ | ||
| function deferred<T>() { | ||
| let resolve!: (value: T) => void; | ||
| const promise = new Promise<T>((r) => { | ||
| resolve = r; | ||
| }); | ||
| return { promise, resolve }; | ||
| } | ||
|
|
||
| function renderPicker() { | ||
| const onChange = vi.fn(); | ||
| render( | ||
| <Theme> | ||
| <FolderPicker variant="field" value="" onChange={onChange} /> | ||
| </Theme>, | ||
| ); | ||
| return { onChange, trigger: screen.getByRole("button") }; | ||
| } | ||
|
|
||
| describe("FolderPicker", () => { | ||
| afterEach(() => vi.clearAllMocks()); | ||
|
|
||
| it("shows feedback synchronously while the dialog is open, then commits the path", async () => { | ||
| // The synchronous "Opening..." state both reassures the user and gives | ||
| // PostHog a DOM mutation, so the open native dialog stops being logged as a | ||
| // dead click. | ||
| const user = userEvent.setup(); | ||
| const pending = deferred<string | null>(); | ||
| selectDirectoryQuery.mockReturnValue(pending.promise); | ||
| const { onChange, trigger } = renderPicker(); | ||
|
|
||
| await user.click(trigger); | ||
|
|
||
| expect(trigger).toHaveTextContent("Opening..."); | ||
| expect(trigger).toBeDisabled(); | ||
|
|
||
| pending.resolve("/Users/me/code/posthog"); | ||
|
|
||
| await waitFor(() => | ||
| expect(onChange).toHaveBeenCalledWith("/Users/me/code/posthog"), | ||
| ); | ||
| expect(addFolder).toHaveBeenCalledTimes(1); | ||
| expect(trigger).not.toBeDisabled(); | ||
| }); | ||
|
|
||
| it("ignores re-clicks while a dialog is already open", async () => { | ||
| const user = userEvent.setup(); | ||
| const pending = deferred<string | null>(); | ||
| selectDirectoryQuery.mockReturnValue(pending.promise); | ||
| const { trigger } = renderPicker(); | ||
|
|
||
| await user.click(trigger); | ||
| await user.click(trigger); | ||
|
|
||
| expect(selectDirectoryQuery).toHaveBeenCalledTimes(1); | ||
|
|
||
| pending.resolve(null); | ||
| await waitFor(() => expect(trigger).not.toBeDisabled()); | ||
| }); | ||
| }); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.