Skip to content

Commit bbd1c07

Browse files
authored
fix(app): fix flicker and navigation when collapsing/expanding projects (anomalyco#6658)
1 parent 8e9a0c4 commit bbd1c07

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

packages/app/src/components/session/session-header.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createEffect, createMemo, createResource, Show } from "solid-js"
1+
import { createMemo, createResource, Show } from "solid-js"
22
import { A, useNavigate, useParams } from "@solidjs/router"
33
import { useLayout } from "@/context/layout"
44
import { useCommand } from "@/context/command"
@@ -20,6 +20,7 @@ import { DialogSelectServer } from "@/components/dialog-select-server"
2020
import { SessionLspIndicator } from "@/components/session-lsp-indicator"
2121
import { SessionMcpIndicator } from "@/components/session-mcp-indicator"
2222
import type { Session } from "@opencode-ai/sdk/v2/client"
23+
import { same } from "@/utils/same"
2324

2425
export function SessionHeader() {
2526
const globalSDK = useGlobalSDK()
@@ -36,6 +37,7 @@ export function SessionHeader() {
3637
const sessions = createMemo(() => (sync.data.session ?? []).filter((s) => !s.parentID))
3738
const currentSession = createMemo(() => sessions().find((s) => s.id === params.id))
3839
const shareEnabled = createMemo(() => sync.data.config.share !== "disabled")
40+
const worktrees = createMemo(() => layout.projects.list().map((p) => p.worktree), [], { equals: same })
3941

4042
function navigateToProject(directory: string) {
4143
navigate(`/${base64Encode(directory)}`)
@@ -60,7 +62,7 @@ export function SessionHeader() {
6062
<div class="flex items-center gap-2 min-w-0">
6163
<div class="hidden xl:flex items-center gap-2">
6264
<Select
63-
options={layout.projects.list().map((project) => project.worktree)}
65+
options={worktrees()}
6466
current={sync.project?.worktree ?? projectDirectory()}
6567
label={(x) => getFilename(x)}
6668
onSelect={(x) => (x ? navigateToProject(x) : undefined)}

packages/app/src/context/layout.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useGlobalSDK } from "./global-sdk"
66
import { useServer } from "./server"
77
import { Project } from "@opencode-ai/sdk/v2"
88
import { persisted } from "@/utils/persist"
9+
import { same } from "@/utils/same"
910

1011
const AVATAR_COLOR_KEYS = ["pink", "mint", "orange", "purple", "cyan", "lime"] as const
1112
export type AvatarColorKey = (typeof AVATAR_COLOR_KEYS)[number]
@@ -23,13 +24,6 @@ export function getAvatarColors(key?: string) {
2324
}
2425
}
2526

26-
function same<T>(a: readonly T[] | undefined, b: readonly T[] | undefined) {
27-
if (a === b) return true
28-
if (!a || !b) return false
29-
if (a.length !== b.length) return false
30-
return a.every((x, i) => x === b[i])
31-
}
32-
3327
type SessionTabs = {
3428
active?: string
3529
all: string[]

packages/app/src/pages/session.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ import {
4848
NewSessionView,
4949
} from "@/components/session"
5050
import { usePlatform } from "@/context/platform"
51-
52-
function same<T>(a: readonly T[], b: readonly T[]) {
53-
if (a === b) return true
54-
if (a.length !== b.length) return false
55-
return a.every((x, i) => x === b[i])
56-
}
51+
import { same } from "@/utils/same"
5752

5853
type DiffStyle = "unified" | "split"
5954

packages/app/src/utils/same.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function same<T>(a: readonly T[] | undefined, b: readonly T[] | undefined) {
2+
if (a === b) return true
3+
if (!a || !b) return false
4+
if (a.length !== b.length) return false
5+
return a.every((x, i) => x === b[i])
6+
}

0 commit comments

Comments
 (0)