mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-03 21:24:29 +00:00
[ty] Fix playground crash for very large files (#20934)
This commit is contained in:
parent
64edfb6ef6
commit
a21cde8a5a
2 changed files with 21 additions and 0 deletions
|
|
@ -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]),
|
||||
|
|
|
|||
|
|
@ -40,6 +40,18 @@ export async function restore(): Promise<Workspace | null> {
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue