@devries-cameron20 / t3code Mirror · read-only / commits / 473b4d717d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 04:15 UTC

fix(desktop): preview annotations no longer replace each other after a reload (#14360)

Co-authored-by: notcompromised <peyton.lamb111@gmail.com>

not-compromised committed Oct 18, 2026 at 14:11 UTC 473b4d717dee02ce20431ff33c115e2fc0a01468
3 files changed +45 -5
apps/desktop/src/preview/AnnotationIds.test.ts new
+25
@@ -0,0 +1,25 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { createAnnotationIdSource } from "./AnnotationIds.ts";
4 +
5 +describe("createAnnotationIdSource", () => {
6 + it("gives annotations picked on separate page loads distinct ids", () => {
7 + // The picker preload runs afresh on every page load, while the composer
8 + // keeps earlier annotations keyed by id.
9 + const firstLoad = createAnnotationIdSource();
10 + firstLoad("element");
11 + const firstAnnotation = firstLoad("annotation");
12 +
13 + const secondLoad = createAnnotationIdSource();
14 + secondLoad("element");
15 + const secondAnnotation = secondLoad("annotation");
16 +
17 + expect(secondAnnotation).not.toBe(firstAnnotation);
18 + });
19 +
20 + it("never repeats an id within one page load", () => {
21 + const nextId = createAnnotationIdSource();
22 + const ids = Array.from({ length: 1_000 }, () => nextId("annotation"));
23 + expect(new Set(ids).size).toBe(ids.length);
24 + });
25 +});
apps/desktop/src/preview/AnnotationIds.ts new
+18
@@ -0,0 +1,18 @@
1 +/**
2 + * Id source for picker annotations and their targets, one per page load.
3 + *
4 + * The composer keeps annotations keyed by id across preview reloads, and this
5 + * preload restarts on every page load, so a bare counter reissues ids that a
6 + * draft already holds. `getRandomValues` rather than `randomUUID`, because
7 + * plain-http previews (LAN, tailnet) are not secure contexts.
8 + */
9 +export function createAnnotationIdSource(): (prefix: string) => string {
10 + const pageLoad = Array.from(crypto.getRandomValues(new Uint32Array(2)), (part) =>
11 + part.toString(36),
12 + ).join("");
13 + let sequence = 0;
14 + return (prefix) => {
15 + sequence += 1;
16 + return `${prefix}_${pageLoad}_${sequence.toString(36)}`;
17 + };
18 +}
apps/desktop/src/preview/PickPreload.ts
+2 -5
@@ -14,6 +14,7 @@ import type {
14 PreviewAnnotationSubmission,
15 } from "@t3tools/contracts";
16
17 +import { createAnnotationIdSource } from "./AnnotationIds.ts";
18 import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts";
19 import { previewAnnotationStyles } from "./AnnotationStyles.generated.ts";
20 import { installRecordingCursor } from "./RecordingCursor.ts";
@@ -133,7 +134,6 @@ interface AnnotationSession {
134 }
135
136 let activeSession: AnnotationSession | null = null;
136 -let idSequence = 0;
137 let annotationTheme: DesktopPreviewAnnotationTheme | null = null;
138
139 const applyAnnotationTheme = (
@@ -220,10 +220,7 @@ window.addEventListener("mousedown", suppressNavigationButton, true);
220 window.addEventListener("mouseup", requestNavigationForButton, true);
221 window.addEventListener("auxclick", suppressNavigationButton, true);
222
223 -const nextId = (prefix: string): string => {
224 - idSequence += 1;
225 - return `${prefix}_${idSequence.toString(36)}`;
226 -};
223 +const nextId = createAnnotationIdSource();
224
225 const rectFromDomRect = (rect: DOMRect): PreviewAnnotationRect => ({
226 x: rect.left,