Repository navigation
fix(mobile): sidebar no longer re-registers shortcuts every render #22135
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
Closed
+167
−81
Closed
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
56 changes: 56 additions & 0 deletions
56
apps/mobile/src/features/keyboard/threadKeyboardShortcuts.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,56 @@ | ||
| import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; | ||
| import { act } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import type { ThreadListV2ListItem } from "../threads/threadListV2"; | ||
| import { | ||
| dispatchHardwareKeyboardCommand, | ||
| getHardwareKeyboardCommandRegistrationVersion, | ||
| } from "./hardwareKeyboardCommands"; | ||
| import { useThreadJumpShortcuts } from "./threadKeyboardShortcuts"; | ||
|
|
||
| function threadItem(id: string): ThreadListV2ListItem { | ||
| const thread = { environmentId: "environment-1", id } as unknown as EnvironmentThreadShell; | ||
| return { | ||
| type: "v2-thread", | ||
| key: id, | ||
| item: { thread, variant: "card", snoozed: false, pinned: false, isLast: false, wokeAt: null }, | ||
| snoozeWakeLabelText: undefined, | ||
| timeLabel: "", | ||
| snoozePresetMinute: undefined, | ||
| showTrailingDivider: false, | ||
| hasQueuedMessages: false, | ||
| canMoveUp: false, | ||
| canMoveDown: false, | ||
| }; | ||
| } | ||
|
|
||
| function Probe(props: { | ||
| readonly items: ReadonlyArray<ThreadListV2ListItem>; | ||
| readonly onSelectThread: (thread: EnvironmentThreadShell) => void; | ||
| }) { | ||
| useThreadJumpShortcuts(props.items, props.onSelectThread); | ||
| return null; | ||
| } | ||
|
|
||
| describe("useThreadJumpShortcuts", () => { | ||
| it("registers once and jumps within the latest list", () => { | ||
| (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; | ||
| const root = createRoot(document.createElement("div")); | ||
| act(() => root.render(<Probe items={[threadItem("first")]} onSelectThread={vi.fn()} />)); | ||
| const registrationVersion = getHardwareKeyboardCommandRegistrationVersion(); | ||
|
|
||
| const onSelectThread = vi.fn(); | ||
| for (const id of ["second", "third"]) { | ||
| act(() => root.render(<Probe items={[threadItem(id)]} onSelectThread={onSelectThread} />)); | ||
| } | ||
|
|
||
| expect(getHardwareKeyboardCommandRegistrationVersion()).toBe(registrationVersion); | ||
| expect(dispatchHardwareKeyboardCommand("thread.jump.1")).toBe(true); | ||
| expect(onSelectThread).toHaveBeenCalledExactlyOnceWith( | ||
| expect.objectContaining({ id: "third" }), | ||
| ); | ||
| act(() => root.unmount()); | ||
| }); | ||
| }); |
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
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
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.
Script executed:
git diff fa31b66bbb2ae5234205a8628a78e038d917202f e710e382ff737e340ce2c8f0baf3f0f1783b9d8b -- apps/mobile/src/features/keyboard/threadKeyboardShortcuts.ts apps/mobile/src/features/keyboard/hardwareKeyboardCommands.ts rg -n 'useThreadJumpShortcuts|dispatchHardwareKeyboardCommand|registerHardwareKeyboardCommand' apps/mobile/srcRepository: pingdotgg/t3code
Length of output: 6898
Script executed:
Repository: pingdotgg/t3code
Length of output: 25867
Script executed:
Repository: pingdotgg/t3code
Length of output: 10035
Script executed:
Repository: pingdotgg/t3code
Length of output: 41910
Script executed:
Repository: pingdotgg/t3code
Length of output: 42058
Script executed:
Repository: pingdotgg/t3code
Length of output: 41927
Script executed:
Repository: pingdotgg/t3code
Length of output: 17568
Script executed:
Repository: pingdotgg/t3code
Length of output: 13350
Script executed:
Repository: pingdotgg/t3code
Length of output: 17469
Script executed:
Repository: pingdotgg/t3code
Length of output: 10308
Make shortcut priority follow the active pane.
When Home mounts with the sidebar closed, the sidebar handler registers first and the Home handler registers later. Dispatch tries the Home handler first because the registry uses reverse registration order. Opening the sidebar changes
props.visible, but the new mount-only effect does not re-register the sidebar handler.The visible sidebar can therefore lose to the Home list. A jump may select a thread from the wrong list, or the Home handler may return
truewithout a target and swallow the command. The base hook re-registered when the handler changed, so a sidebar visibility render moved its handler to the active position. Track active-pane or route state in registration without restoring list-driven re-registration.