Compare commits

..

1 Commits

Author SHA1 Message Date
Mark Tolmacs b4078b1589 Add automatic issue staleness tracking 2025-07-28 13:07:59 +02:00
6 changed files with 59 additions and 266 deletions
+23
View File
@@ -0,0 +1,23 @@
name: Close inactive issues
on:
schedule:
- cron: "30 1 * * *"
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: read
steps:
- uses: actions/stale@v9
with:
days-before-issue-stale: 90
days-before-issue-close: 180
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 90 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 180 days since being marked as stale."
exempt-issue-assignees: "dwelle,ryan-di,Mrazator,ad1992,zsviczian,mtolmacs"
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
+3 -18
View File
@@ -112,9 +112,7 @@ import {
import { updateStaleImageStatuses } from "./data/FileManager";
import {
importFromLocalStorage,
importFromIndexedDB,
importUsernameFromLocalStorage,
migrateFromLocalStorageToIndexedDB,
} from "./data/localStorage";
import { loadFilesFromFirebase } from "./data/firebase";
@@ -220,15 +218,7 @@ const initializeScene = async (opts: {
);
const externalUrlMatch = window.location.hash.match(/^#url=(.*)$/);
// migrate from localStorage to IndexedDB if needed
await migrateFromLocalStorageToIndexedDB();
// try to load from IndexedDB first, fallback to localStorage
let localDataState = await importFromIndexedDB();
if (!localDataState.elements.length && !localDataState.appState) {
// fallback to localStorage if IndexedDB is empty
localDataState = importFromLocalStorage();
}
const localDataState = importFromLocalStorage();
let scene: RestoredDataState & {
scrollToContent?: boolean;
@@ -514,7 +504,7 @@ const ExcalidrawWrapper = () => {
TITLE_TIMEOUT,
);
const syncData = debounce(async () => {
const syncData = debounce(() => {
if (isTestEnv()) {
return;
}
@@ -524,12 +514,7 @@ const ExcalidrawWrapper = () => {
) {
// don't sync if local state is newer or identical to browser state
if (isBrowserStorageStateNewer(STORAGE_KEYS.VERSION_DATA_STATE)) {
// try to load from IndexedDB first, fallback to localStorage
let localDataState = await importFromIndexedDB();
if (!localDataState.elements.length && !localDataState.appState) {
// fallback to localStorage if IndexedDB is empty
localDataState = importFromLocalStorage();
}
const localDataState = importFromLocalStorage();
const username = importUsernameFromLocalStorage();
setLangCode(getPreferredLanguage());
excalidrawAPI.updateScene({
+5 -17
View File
@@ -21,23 +21,11 @@ type StorageSizes = { scene: number; total: number };
const STORAGE_SIZE_TIMEOUT = 500;
const getStorageSizes = debounce(async (cb: (sizes: StorageSizes) => void) => {
try {
const [scene, total] = await Promise.all([
getElementsStorageSize(),
getTotalStorageSize(),
]);
cb({
scene,
total,
});
} catch (error) {
console.error("Failed to get storage sizes:", error);
cb({
scene: 0,
total: 0,
});
}
const getStorageSizes = debounce((cb: (sizes: StorageSizes) => void) => {
cb({
scene: getElementsStorageSize(),
total: getTotalStorageSize(),
});
}, STORAGE_SIZE_TIMEOUT);
type Props = {
+11 -69
View File
@@ -65,7 +65,7 @@ class LocalFileManager extends FileManager {
};
}
const saveDataStateToIndexedDB = async (
const saveDataStateToLocalStorage = (
elements: readonly ExcalidrawElement[],
appState: AppState,
) => {
@@ -79,15 +79,17 @@ const saveDataStateToIndexedDB = async (
_appState.openSidebar = null;
}
// save to IndexedDB
await Promise.all([
ElementsIndexedDBAdapter.save(clearElementsForLocalStorage(elements)),
AppStateIndexedDBAdapter.save(_appState),
]);
localStorage.setItem(
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
JSON.stringify(clearElementsForLocalStorage(elements)),
);
localStorage.setItem(
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
JSON.stringify(_appState),
);
updateBrowserStateVersion(STORAGE_KEYS.VERSION_DATA_STATE);
} catch (error: any) {
// unable to access IndexedDB
// Unable to access window.localStorage
console.error(error);
}
};
@@ -102,7 +104,7 @@ export class LocalData {
files: BinaryFiles,
onFilesSaved: () => void,
) => {
await saveDataStateToIndexedDB(elements, appState);
saveDataStateToLocalStorage(elements, appState);
await this.fileStorage.saveFiles({
elements,
@@ -254,63 +256,3 @@ export class LibraryLocalStorageMigrationAdapter {
localStorage.removeItem(STORAGE_KEYS.__LEGACY_LOCAL_STORAGE_LIBRARY);
}
}
/** IndexedDB Adapter for storing app state */
export class AppStateIndexedDBAdapter {
/** IndexedDB database and store name */
private static idb_name = "excalidraw-app-state";
/** app state data store key */
private static key = "appStateData";
private static store = createStore(
`${AppStateIndexedDBAdapter.idb_name}-db`,
`${AppStateIndexedDBAdapter.idb_name}-store`,
);
static async load() {
const IDBData = await get<Partial<AppState>>(
AppStateIndexedDBAdapter.key,
AppStateIndexedDBAdapter.store,
);
return IDBData || null;
}
static save(data: Partial<AppState>): MaybePromise<void> {
return set(
AppStateIndexedDBAdapter.key,
data,
AppStateIndexedDBAdapter.store,
);
}
}
/** IndexedDB Adapter for storing elements */
export class ElementsIndexedDBAdapter {
/** IndexedDB database and store name */
private static idb_name = "excalidraw-elements";
/** elements data store key */
private static key = "elementsData";
private static store = createStore(
`${ElementsIndexedDBAdapter.idb_name}-db`,
`${ElementsIndexedDBAdapter.idb_name}-store`,
);
static async load() {
const IDBData = await get<ExcalidrawElement[]>(
ElementsIndexedDBAdapter.key,
ElementsIndexedDBAdapter.store,
);
return IDBData || null;
}
static save(data: ExcalidrawElement[]): MaybePromise<void> {
return set(
ElementsIndexedDBAdapter.key,
data,
ElementsIndexedDBAdapter.store,
);
}
}
+10 -133
View File
@@ -9,11 +9,6 @@ import type { AppState } from "@excalidraw/excalidraw/types";
import { STORAGE_KEYS } from "../app_constants";
import {
AppStateIndexedDBAdapter,
ElementsIndexedDBAdapter,
} from "./LocalData";
export const saveUsernameToLocalStorage = (username: string) => {
try {
localStorage.setItem(
@@ -79,146 +74,28 @@ export const importFromLocalStorage = () => {
return { elements, appState };
};
export const importFromIndexedDB = async () => {
let savedElements = null;
let savedState = null;
export const getElementsStorageSize = () => {
try {
savedElements = await ElementsIndexedDBAdapter.load();
savedState = await AppStateIndexedDBAdapter.load();
const elements = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS);
const elementsSize = elements?.length || 0;
return elementsSize;
} catch (error: any) {
// unable to access IndexedDB
console.error(error);
}
let elements: ExcalidrawElement[] = [];
if (savedElements) {
try {
elements = clearElementsForLocalStorage(savedElements);
} catch (error: any) {
console.error(error);
}
}
let appState = null;
if (savedState) {
try {
appState = {
...getDefaultAppState(),
...clearAppStateForLocalStorage(savedState),
};
} catch (error: any) {
console.error(error);
}
}
return { elements, appState };
};
export const migrateFromLocalStorageToIndexedDB = async () => {
try {
// check if we have data in localStorage
const savedElements = localStorage.getItem(
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
);
const savedState = localStorage.getItem(
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
);
if (savedElements || savedState) {
// parse and migrate elements
if (savedElements) {
try {
const elements = JSON.parse(savedElements);
await ElementsIndexedDBAdapter.save(elements);
} catch (error) {
console.error("Failed to migrate elements:", error);
}
}
// parse and migrate app state
if (savedState) {
try {
const appState = JSON.parse(savedState);
await AppStateIndexedDBAdapter.save(appState);
} catch (error) {
console.error("Failed to migrate app state:", error);
}
}
// clear localStorage after successful migration
localStorage.removeItem(STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS);
localStorage.removeItem(STORAGE_KEYS.LOCAL_STORAGE_APP_STATE);
}
} catch (error) {
console.error("Migration failed:", error);
}
};
/**
* Get the size of elements stored in IndexedDB (with localStorage fallback)
* @returns Promise<number> - Size in bytes
*/
export const getElementsStorageSize = async () => {
try {
const elements = await ElementsIndexedDBAdapter.load();
if (elements) {
// calculate size by stringifying the data
const elementsString = JSON.stringify(elements);
return elementsString.length;
}
return 0;
} catch (error: any) {
console.error("Failed to get elements size from IndexedDB:", error);
// fallback to localStorage
try {
const elements = localStorage.getItem(
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
);
return elements?.length || 0;
} catch (localStorageError: any) {
console.error(
"Failed to get elements size from localStorage:",
localStorageError,
);
return 0;
}
}
};
/**
* Get the total size of all data stored in IndexedDB and localStorage
* @returns Promise<number> - Size in bytes
*/
export const getTotalStorageSize = async () => {
export const getTotalStorageSize = () => {
try {
const appState = await AppStateIndexedDBAdapter.load();
const appState = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_APP_STATE);
const collab = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_COLLAB);
const appStateSize = appState ? JSON.stringify(appState).length : 0;
const appStateSize = appState?.length || 0;
const collabSize = collab?.length || 0;
const elementsSize = await getElementsStorageSize();
return appStateSize + collabSize + elementsSize;
return appStateSize + collabSize + getElementsStorageSize();
} catch (error: any) {
console.error("Failed to get total storage size from IndexedDB:", error);
// fallback to localStorage
try {
const appState = localStorage.getItem(
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
);
const collab = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_COLLAB);
const appStateSize = appState?.length || 0;
const collabSize = collab?.length || 0;
const elementsSize = await getElementsStorageSize();
return appStateSize + collabSize + elementsSize;
} catch (localStorageError: any) {
console.error(
"Failed to get total storage size from localStorage:",
localStorageError,
);
return 0;
}
console.error(error);
return 0;
}
};
+7 -29
View File
@@ -4,13 +4,7 @@ import {
supported as nativeFileSystemSupported,
} from "browser-fs-access";
import {
EVENT,
MIME_TYPES,
debounce,
isIOS,
isAndroid,
} from "@excalidraw/common";
import { EVENT, MIME_TYPES, debounce } from "@excalidraw/common";
import { AbortError } from "../errors";
@@ -19,8 +13,6 @@ import type { FileSystemHandle } from "browser-fs-access";
type FILE_EXTENSION = Exclude<keyof typeof MIME_TYPES, "binary">;
const INPUT_CHANGE_INTERVAL_MS = 500;
// increase timeout for mobile devices to give more time for file selection
const MOBILE_INPUT_CHANGE_INTERVAL_MS = 2000;
export const fileOpen = <M extends boolean | undefined = false>(opts: {
extensions?: FILE_EXTENSION[];
@@ -49,22 +41,13 @@ export const fileOpen = <M extends boolean | undefined = false>(opts: {
mimeTypes,
multiple: opts.multiple ?? false,
legacySetup: (resolve, reject, input) => {
const isMobile = isIOS || isAndroid;
const intervalMs = isMobile
? MOBILE_INPUT_CHANGE_INTERVAL_MS
: INPUT_CHANGE_INTERVAL_MS;
const scheduleRejection = debounce(reject, intervalMs);
const scheduleRejection = debounce(reject, INPUT_CHANGE_INTERVAL_MS);
const focusHandler = () => {
checkForFile();
// on mobile, be less aggressive with rejection
if (!isMobile) {
document.addEventListener(EVENT.KEYUP, scheduleRejection);
document.addEventListener(EVENT.POINTER_UP, scheduleRejection);
scheduleRejection();
}
document.addEventListener(EVENT.KEYUP, scheduleRejection);
document.addEventListener(EVENT.POINTER_UP, scheduleRejection);
scheduleRejection();
};
const checkForFile = () => {
// this hack might not work when expecting multiple files
if (input.files?.length) {
@@ -72,15 +55,12 @@ export const fileOpen = <M extends boolean | undefined = false>(opts: {
resolve(ret as RetType);
}
};
requestAnimationFrame(() => {
window.addEventListener(EVENT.FOCUS, focusHandler);
});
const interval = window.setInterval(() => {
checkForFile();
}, intervalMs);
}, INPUT_CHANGE_INTERVAL_MS);
return (rejectPromise) => {
clearInterval(interval);
scheduleRejection.cancel();
@@ -89,9 +69,7 @@ export const fileOpen = <M extends boolean | undefined = false>(opts: {
document.removeEventListener(EVENT.POINTER_UP, scheduleRejection);
if (rejectPromise) {
// so that something is shown in console if we need to debug this
console.warn(
"Opening the file was canceled (legacy-fs). This may happen on mobile devices.",
);
console.warn("Opening the file was canceled (legacy-fs).");
rejectPromise(new AbortError());
}
};