diff --git a/playground/ruff/src/Editor/settings.ts b/playground/ruff/src/Editor/settings.ts index 411399da5d..7a7be3d95b 100644 --- a/playground/ruff/src/Editor/settings.ts +++ b/playground/ruff/src/Editor/settings.ts @@ -79,6 +79,15 @@ export function persistLocal({ settingsSource: string; pythonSource: string; }) { + const totalLength = settingsSource.length + pythonSource.length; + + // Don't persist large files to local storage because they can exceed the local storage quota + // The number here is picked rarely arbitrarily. Also note, JS uses UTF 16: + // that means the limit here is strings larger than 1MB (because UTf 16 uses 2 bytes per character) + if (totalLength > 500_000) { + return; + } + localStorage.setItem( "source", JSON.stringify([settingsSource, pythonSource]), diff --git a/playground/ty/src/Editor/persist.ts b/playground/ty/src/Editor/persist.ts index 2adc5f3fe9..1767e14d0f 100644 --- a/playground/ty/src/Editor/persist.ts +++ b/playground/ty/src/Editor/persist.ts @@ -40,6 +40,18 @@ export async function restore(): Promise { } export function persistLocal(workspace: Workspace) { + let totalLength = 0; + for (const fileContent of Object.values(workspace.files)) { + totalLength += fileContent.length; + + // Don't persist large files to local storage because they can exceed the local storage quota + // The number here is picked rarely arbitrarily. Also note, JS uses UTF 16: + // that means the limit here is strings larger than 1MB (because UTf 16 uses 2 bytes per character) + if (totalLength > 500_000) { + return; + } + } + localStorage.setItem("workspace", JSON.stringify(workspace)); }