Skip to content

Commit b8ee159

Browse files
committed
Fix theme hydration and sidebar file tree behavior
- add a stable server snapshot for `useTheme` - make chat header preview toggle safe when missing - update tests for the sidebar file tree shortcut and Git rebase flow
1 parent 451669c commit b8ee159

4 files changed

Lines changed: 26 additions & 23 deletions

File tree

apps/server/src/git/Layers/GitManager.test.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -787,19 +787,12 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
787787
Effect.gen(function* () {
788788
const repoDir = yield* makeTempDir("okcode-git-manager-");
789789
yield* initRepo(repoDir);
790-
const remoteDir = yield* createBareRemote();
791-
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
792-
yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
793790
yield* runGit(repoDir, ["checkout", "-b", "feature/rebase-before-commit"]);
794-
795-
const updaterDir = yield* makeTempDir("okcode-git-manager-updater-");
796-
yield* runGit(updaterDir, ["clone", "--branch", "main", remoteDir, "."]);
797-
yield* runGit(updaterDir, ["config", "user.email", "test@example.com"]);
798-
yield* runGit(updaterDir, ["config", "user.name", "Test User"]);
799-
fs.writeFileSync(path.join(updaterDir, "base.txt"), "remote main update\n");
800-
yield* runGit(updaterDir, ["add", "base.txt"]);
801-
yield* runGit(updaterDir, ["commit", "-m", "Remote main update"]);
802-
yield* runGit(updaterDir, ["push", "origin", "main"]);
791+
yield* runGit(repoDir, ["checkout", "main"]);
792+
fs.writeFileSync(path.join(repoDir, "base.txt"), "local main update\n");
793+
yield* runGit(repoDir, ["add", "base.txt"]);
794+
yield* runGit(repoDir, ["commit", "-m", "Local main update"]);
795+
yield* runGit(repoDir, ["checkout", "feature/rebase-before-commit"]);
803796

804797
fs.writeFileSync(path.join(repoDir, "README.md"), "hello\nrebased feature work\n");
805798

@@ -812,15 +805,14 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
812805
});
813806

814807
expect(result.commit.status).toBe("created");
815-
816-
const remoteMainSha = yield* runGit(repoDir, ["rev-parse", "origin/main"]).pipe(
808+
const mainSha = yield* runGit(repoDir, ["rev-parse", "main"]).pipe(
817809
Effect.map((gitResult) => gitResult.stdout.trim()),
818810
);
819-
const mergeBase = yield* runGit(repoDir, ["merge-base", "HEAD", "origin/main"]).pipe(
811+
const mergeBase = yield* runGit(repoDir, ["merge-base", "HEAD", "main"]).pipe(
820812
Effect.map((gitResult) => gitResult.stdout.trim()),
821813
);
822814

823-
expect(mergeBase).toBe(remoteMainSha);
815+
expect(mergeBase).toBe(mainSha);
824816
}),
825817
30_000,
826818
);

apps/web/src/components/Sidebar.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { readFileSync } from "node:fs";
22
import { resolve } from "node:path";
33
import { describe, expect, it } from "vitest";
44

5-
describe("Sidebar file tree mounting", () => {
6-
it("keeps the workspace file tree mounted when the files section is collapsed", () => {
5+
describe("Sidebar file tree shortcut", () => {
6+
it("opens the right-panel file tree instead of mounting the tree inline", () => {
77
const src = readFileSync(resolve(import.meta.dirname, "./Sidebar.tsx"), "utf8");
88

9-
expect(src).toContain("<WorkspaceFileTree");
10-
expect(src).toContain('className={cn(filesCollapsedByProject.has(project.id) && "hidden")}');
11-
expect(src).not.toContain("!filesCollapsedByProject.has(project.id) && (");
9+
expect(src).toContain('aria-label="Open file tree"');
10+
expect(src).toContain('useRightPanelStore.getState().open("files")');
11+
expect(src).not.toContain("<WorkspaceFileTree");
1212
});
1313
});

apps/web/src/components/chat/ChatHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export const ChatHeader = memo(function ChatHeader({
265265
previewAvailable={previewAvailable}
266266
previewOpen={previewOpen}
267267
onToggleTerminal={onToggleTerminal}
268-
onTogglePreview={onTogglePreview}
268+
onTogglePreview={onTogglePreview ?? (() => {})}
269269
/>
270270
)}
271271
</div>

apps/web/src/hooks/useTheme.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ const FONT_FAMILY_STORAGE_KEY = "okcode:font-family";
4444
const MEDIA_QUERY = "(prefers-color-scheme: dark)";
4545
export const DEFAULT_COLOR_THEME: ColorTheme = "carbon";
4646

47+
const SERVER_SNAPSHOT: ThemeSnapshot = {
48+
theme: "system",
49+
systemDark: false,
50+
colorTheme: DEFAULT_COLOR_THEME,
51+
fontFamily: "inter",
52+
};
53+
4754
let listeners: Array<() => void> = [];
4855
let lastSnapshot: ThemeSnapshot | null = null;
4956
let lastDesktopTheme: Theme | null = null;
@@ -209,6 +216,10 @@ function getSnapshot(): ThemeSnapshot {
209216
return lastSnapshot;
210217
}
211218

219+
function getServerSnapshot(): ThemeSnapshot {
220+
return SERVER_SNAPSHOT;
221+
}
222+
212223
function subscribe(listener: () => void): () => void {
213224
listeners.push(listener);
214225

@@ -241,7 +252,7 @@ function subscribe(listener: () => void): () => void {
241252
}
242253

243254
export function useTheme() {
244-
const snapshot = useSyncExternalStore(subscribe, getSnapshot);
255+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
245256
const theme = snapshot.theme;
246257
const colorTheme = snapshot.colorTheme;
247258
const fontFamily = snapshot.fontFamily;

0 commit comments

Comments
 (0)