Repository navigation
fix(web): thread navigation shortcuts honor previewFocus and previewOpen conditions #29678
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
maria-rcks
merged 3 commits into
pingdotgg:main
from
saphid:fix/sidebar-thread-nav-preview-context
Nov 9, 2026
+113
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
103 changes: 103 additions & 0 deletions
103
apps/web/src/components/Sidebar.shortcuts.browser.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,103 @@ | ||
| import { createMemoryHistory } from "@tanstack/react-router"; | ||
| import { scopeThreadRef } from "@t3tools/client-runtime/environment"; | ||
| import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; | ||
| import type * as Context from "effect/Context"; | ||
| import { expect, it, vi } from "vite-plus/test"; | ||
| import { page, userEvent } from "vite-plus/test/browser"; | ||
|
|
||
| import { AppRoot } from "~/AppRoot"; | ||
| // The thread route loads ChatView lazily; its first transform would eat the test's timeout. | ||
| import "~/components/ChatView"; | ||
| import { __setClientSettingsForTests } from "~/hooks/useSettings"; | ||
| import { useRightPanelStore } from "~/rightPanelStore"; | ||
| import { getRouter } from "~/router"; | ||
| import { | ||
| ENVIRONMENT_ID, | ||
| installFakeEnvironment, | ||
| threadWithHistory, | ||
| type FakeDriver, | ||
| } from "../../test/fakeEnvironment"; | ||
| import { act, render } from "../../test/render"; | ||
|
|
||
| // The socket is the only fake layer; see test/appScenarios.renders.tsx. | ||
| vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => { | ||
| const [actual, { fakeDriver }, Layer] = await Promise.all([ | ||
| importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(), | ||
| import("../../test/fakeEnvironment"), | ||
| import("effect/Layer"), | ||
| ]); | ||
| return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) }; | ||
| }); | ||
|
|
||
| vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({ | ||
| ...(await original()), | ||
| trackRpcRequestSent: () => {}, | ||
| })); | ||
|
|
||
| vi.mock(import("~/state/server"), async (original) => { | ||
| const actual = await original(); | ||
| const { Atom } = await import("effect/reactivity"); | ||
| const { compileResolvedKeybindingsConfig } = await import("@t3tools/shared/keybindings"); | ||
| const keybindings = compileResolvedKeybindingsConfig([ | ||
| { key: "mod+shift+]", command: "thread.next", when: "!previewFocus && !previewOpen" }, | ||
| { key: "mod+1", command: "thread.jump.1", when: "!previewFocus" }, | ||
| ]); | ||
| return { ...actual, primaryServerKeybindingsAtom: Atom.make(keybindings) }; | ||
| }); | ||
|
|
||
| it("leaves thread shortcuts and their hints to the preview when their rules exclude it", async () => { | ||
| const [first, second] = [threadWithHistory("thread-a", 1), threadWithHistory("thread-b", 1)]; | ||
| using _environment = installFakeEnvironment([first, second]); | ||
| using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("Linux x86_64"); | ||
| __setClientSettingsForTests({ | ||
| ...DEFAULT_CLIENT_SETTINGS, | ||
| onboardingCompletedAt: "2026-01-01T00:00:00.000Z", | ||
| }); | ||
| await page.viewport(1400, 900); | ||
| const router = getRouter( | ||
| createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${first.id}`] }), | ||
| ); | ||
| await router.load(); | ||
| await using _app = await render(<AppRoot router={router} />, { | ||
| // AppRoot brings its own router. | ||
| router: false, | ||
| }); | ||
| await expect.element(page.getByText(`Thread ${second.id}`).first()).toBeVisible(); | ||
|
|
||
| const previewChrome = document.createElement("div"); | ||
| previewChrome.dataset.previewPanelMode = "browser"; | ||
| previewChrome.innerHTML = '<button type="button">Reload</button>'; | ||
| document.body.append(previewChrome); | ||
| using _chrome = { [Symbol.dispose]: () => previewChrome.remove() }; | ||
|
|
||
| const press = () => userEvent.keyboard("{Control>}{Shift>}]{/Shift}{/Control}"); | ||
| const jumpHint = () => document.querySelector("[data-jump-hint]"); | ||
| const whileHoldingControl = async (assertJumpHints: () => void) => { | ||
| // Every deadline reads as due on subscribe, so hints skip the hold delay. | ||
| let now = Date.parse("2026-01-01T00:00:00.000Z"); | ||
| using _clock = vi.spyOn(Date, "now").mockImplementation(() => (now += 1000)); | ||
| await userEvent.keyboard("{Control>}"); | ||
| await act(() => {}); | ||
| await vi.waitFor(assertJumpHints); | ||
| await userEvent.keyboard("{/Control}"); | ||
| }; | ||
| const firstPath = `/${ENVIRONMENT_ID}/${first.id}`; | ||
|
|
||
| await userEvent.click(page.getByRole("button", { name: "Reload" })); | ||
| await press(); | ||
| expect(router.history.location.pathname).toBe(firstPath); | ||
| await whileHoldingControl(() => expect(jumpHint()).toBeNull()); | ||
|
|
||
| const firstRef = scopeThreadRef(ENVIRONMENT_ID, first.id); | ||
| await act(() => useRightPanelStore.getState().openBrowser(firstRef, null)); | ||
| if (document.activeElement instanceof HTMLElement) document.activeElement.blur(); | ||
| await press(); | ||
| expect(router.history.location.pathname).toBe(firstPath); | ||
|
|
||
| await act(() => useRightPanelStore.getState().close(firstRef)); | ||
| await press(); | ||
| await vi.waitFor(() => | ||
| expect(router.history.location.pathname).toBe(`/${ENVIRONMENT_ID}/${second.id}`), | ||
| ); | ||
| await whileHoldingControl(() => expect(jumpHint()).not.toBeNull()); | ||
| }); |
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.