File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,15 @@ export function persistLocal({
7979 settingsSource : string ;
8080 pythonSource : string ;
8181} ) {
82+ const totalLength = settingsSource . length + pythonSource . length ;
83+
84+ // Don't persist large files to local storage because they can exceed the local storage quota
85+ // The number here is picked rarely arbitrarily. Also note, JS uses UTF 16:
86+ // that means the limit here is strings larger than 1MB (because UTf 16 uses 2 bytes per character)
87+ if ( totalLength > 500_000 ) {
88+ return ;
89+ }
90+
8291 localStorage . setItem (
8392 "source" ,
8493 JSON . stringify ( [ settingsSource , pythonSource ] ) ,
Original file line number Diff line number Diff line change @@ -40,6 +40,18 @@ export async function restore(): Promise<Workspace | null> {
4040}
4141
4242export function persistLocal ( workspace : Workspace ) {
43+ let totalLength = 0 ;
44+ for ( const fileContent of Object . values ( workspace . files ) ) {
45+ totalLength += fileContent . length ;
46+
47+ // Don't persist large files to local storage because they can exceed the local storage quota
48+ // The number here is picked rarely arbitrarily. Also note, JS uses UTF 16:
49+ // that means the limit here is strings larger than 1MB (because UTf 16 uses 2 bytes per character)
50+ if ( totalLength > 500_000 ) {
51+ return ;
52+ }
53+ }
54+
4355 localStorage . setItem ( "workspace" , JSON . stringify ( workspace ) ) ;
4456}
4557
You can’t perform that action at this time.
0 commit comments