From d7f392ce7924442678865867208da7941eec242b Mon Sep 17 00:00:00 2001 From: koen1711 Date: Sun, 22 Sep 2024 19:27:41 +0200 Subject: [PATCH] fix: remove all uses of crypto.randomUUID with a better counter system --- src/lib/state/popup.svelte.ts | 4 +++- src/lib/state/workspace.svelte.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/state/popup.svelte.ts b/src/lib/state/popup.svelte.ts index bb5b86d..e854fd2 100644 --- a/src/lib/state/popup.svelte.ts +++ b/src/lib/state/popup.svelte.ts @@ -25,6 +25,7 @@ export interface PopupState { function createPopups() { const { subscribe, update, set } = writable([]); + let count = 0; return { subscribe, @@ -32,13 +33,14 @@ function createPopups() { let onclose: (value: any) => void; const promise = new Promise((resolve) => (onclose = resolve)); const state: PopupState = { - id: crypto.randomUUID(), + id: `${count++}`, position: { x: 0, y: 0 }, popup, onclose, anchor: Anchor.Center, ...initialState, }; + if (count > 1000) count = 0; update((popups) => { if ( popups.find( diff --git a/src/lib/state/workspace.svelte.ts b/src/lib/state/workspace.svelte.ts index 10524d3..9f209a1 100644 --- a/src/lib/state/workspace.svelte.ts +++ b/src/lib/state/workspace.svelte.ts @@ -33,6 +33,7 @@ export enum Prompt { export class ConnectionFailedError {} interface LogItem { + id: string; date: Date; content: string; } @@ -67,6 +68,7 @@ let writer: WritableStreamDefaultWriter; function createLogState() { const { subscribe, update, set } = writable([]); let buffer = ""; + let count = 0; return { subscribe, @@ -95,11 +97,13 @@ function createLogState() { [ ...log, ...items.map((content) => ({ + id: `${count}`, date: new Date(), content, })), ].slice(-100), ); + if (count > 100) count = 0; } }, };