Repository navigation
fix(web): new-thread shortcuts work outside chat routes #23459
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
Closed
Changes from all commits
Commits
Show all changes
2 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/AppSidebarLayout.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 { EnvironmentId, ProjectId } from "@t3tools/contracts"; | ||
| import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; | ||
| import { expect, it, vi } from "vite-plus/test"; | ||
| import { userEvent } from "vite-plus/test/browser"; | ||
|
|
||
| import { render } from "../../test/render"; | ||
| import { | ||
| clearComposerDraftsEnvironment, | ||
| DraftId, | ||
| useComposerDraftStore, | ||
| } from "../composerDraftStore"; | ||
| import { primaryServerKeybindingsAtom } from "../state/server"; | ||
| import { AppSidebarLayout } from "./AppSidebarLayout"; | ||
|
|
||
| const environmentId = EnvironmentId.make("shortcut-environment"); | ||
| const projectId = ProjectId.make("shortcut-project"); | ||
| const projects = [ | ||
| { | ||
| environmentId, | ||
| id: projectId, | ||
| title: "Shortcut project", | ||
| defaultModelSelection: null, | ||
| defaultThreadEnvMode: "local" as const, | ||
| workspaceRoot: "/workspace/shortcut-project", | ||
| createdAt: "2026-01-01T00:00:00.000Z", | ||
| updatedAt: "2026-01-01T00:00:00.000Z", | ||
| scripts: [], | ||
| }, | ||
| ]; | ||
|
|
||
| // Keep draft creation and routing real; the sidebar's thread list is unrelated to shortcuts. | ||
| vi.mock("./Sidebar", () => ({ default: () => null })); | ||
| vi.mock("./LegacySidebar", () => ({ default: () => null })); | ||
| vi.mock(import("../state/entities"), async (original) => ({ | ||
| ...(await original()), | ||
| useProjects: () => projects, | ||
| readProjects: () => projects, | ||
| readProject: () => projects[0] ?? null, | ||
| readThreadShells: () => [], | ||
| useQuietThreadShell: () => null, | ||
| })); | ||
| vi.mock(import("@effect/atom-react"), async (original) => { | ||
| const actual = await original(); | ||
| return { | ||
| ...actual, | ||
| useAtomValue: ((atom: Parameters<typeof actual.useAtomValue>[0]) => | ||
| atom === primaryServerKeybindingsAtom | ||
| ? DEFAULT_RESOLVED_KEYBINDINGS | ||
| : actual.useAtomValue(atom)) as typeof actual.useAtomValue, | ||
| }; | ||
| }); | ||
| vi.mock("../lib/t3ProjectFileDefaults", () => ({ readT3ProjectFile: async () => null })); | ||
|
|
||
| it.each([ | ||
| ["/usage", "Linux x86_64", "{Control>}{Shift>}n{/Shift}{/Control}"], | ||
| ["/usage", "MacIntel", "{Meta>}{Shift>}n{/Shift}{/Meta}"], | ||
| ["/usage", "MacIntel", "{Meta>}{Shift>}o{/Shift}{/Meta}"], | ||
| ["/usage", "Linux x86_64", "{Control>}{Shift>}o{/Shift}{/Control}"], | ||
| ["/settings/general", "Linux x86_64", "{Control>}{Shift>}n{/Shift}{/Control}"], | ||
| ["/projects/shortcut-project", "Linux x86_64", "{Control>}{Shift>}n{/Shift}{/Control}"], | ||
| ])("opens a project draft from %s on %s with %s", async (path, platform, shortcut) => { | ||
| clearComposerDraftsEnvironment(environmentId); | ||
| using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue(platform); | ||
| await using screen = await render(<AppSidebarLayout>{null}</AppSidebarLayout>, { router: path }); | ||
|
|
||
| await userEvent.keyboard(shortcut); | ||
|
|
||
| await vi.waitFor(() => expect(screen.router?.state.location.pathname).toMatch(/^\/draft\//)); | ||
| const draftId = screen.router!.state.location.pathname.slice("/draft/".length); | ||
| expect(useComposerDraftStore.getState().getDraftSession(DraftId.make(draftId))).toMatchObject({ | ||
| environmentId, | ||
| projectId, | ||
| }); | ||
| }); | ||
|
|
||
| it.each(["keybinding capture", "terminal", "command palette"])( | ||
| "leaves new-thread shortcuts alone during %s", | ||
| async (context) => { | ||
| clearComposerDraftsEnvironment(environmentId); | ||
| using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("Linux x86_64"); | ||
| await using screen = await render( | ||
| <AppSidebarLayout> | ||
| <input | ||
| aria-label="Focused control" | ||
| data-keybinding-capture={context === "keybinding capture" ? "" : undefined} | ||
| data-terminal-owner={context === "terminal" ? "drawer" : undefined} | ||
| data-command-palette={context === "command palette" ? "" : undefined} | ||
| /> | ||
| </AppSidebarLayout>, | ||
| { router: "/usage" }, | ||
| ); | ||
| await screen.getByRole("textbox", { name: "Focused control" }).click(); | ||
|
|
||
| await userEvent.keyboard("{Control>}{Shift>}n{/Shift}{/Control}"); | ||
|
|
||
| expect(screen.router?.state.location.pathname).toBe("/usage"); | ||
| expect( | ||
| Object.values(useComposerDraftStore.getState().draftThreadsByThreadKey).filter( | ||
| (draft) => draft.environmentId === environmentId, | ||
| ), | ||
| ).toEqual([]); | ||
| }, | ||
| ); |
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 24687
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 16208
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 25342
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 41878
Preserve the selected project scope on project pages.
/projects/$projectKeyredirects to/settings/projects?project=$projectKey, where the settings scope represents the selected project group and optional environment.NewThreadShortcutsignores that scope. With no active thread or draft,chat.newLocaluses the globaldefaultProjectRef, andchat.newWithoutProjectuses the primary environment. For a selected project outside that default context, the shortcuts can target the wrong project or environment.Resolve the settings scope to the appropriate project member and environment before invoking these actions. Handle grouped projects explicitly because one project key can represent multiple environment members.
🤖 Prompt for AI Agents