Full document, spreadsheet, slideshow, and diagram tooling
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'fix: force immediate save after import to prevent data loss on refresh' (#96) from fix/import-save-on-refresh into main

scott 9813589a ba0d4667

+24 -7
+11 -5
src/docs/main.ts
··· 952 952 // Convert data URL back to a File object 953 953 fetch(pending.data) 954 954 .then(r => r.blob()) 955 - .then(blob => { 955 + .then(async blob => { 956 956 const file = new File([blob], pending.name, { type: blob.type }); 957 - handleImportedFile(file); 957 + await handleImportedFile(file); 958 958 }) 959 - .finally(() => { 959 + .finally(async () => { 960 960 window.__importInProgress = false; 961 + // Force save now that import flag is cleared 962 + await provider._saveSnapshot(); 961 963 }); 962 964 } catch { 963 965 window.__importInProgress = false; ··· 1027 1029 } 1028 1030 1029 1031 // --- Import functions --- 1030 - function handleImportedFile(file: File): void { 1032 + async function handleImportedFile(file: File): Promise<void> { 1031 1033 const ext = file.name.split('.').pop().toLowerCase(); 1032 1034 1033 1035 // Handle .docx files via mammoth 1034 1036 if (ext === 'docx') { 1035 - importDocx(file, editor, showToast); 1037 + await importDocx(file, editor, showToast); 1038 + // Force immediate save so imported data survives a refresh 1039 + await provider._saveSnapshot(); 1036 1040 return; 1037 1041 } 1038 1042 ··· 1050 1054 editor.commands.insertContent(content); 1051 1055 } 1052 1056 showToast(`Imported "${file.name}" successfully`, 3000); 1057 + // Force immediate save so imported data survives a refresh 1058 + provider._saveSnapshot(); 1053 1059 }; 1054 1060 reader.readAsText(file); 1055 1061 }
+13 -2
src/sheets/main.ts
··· 2933 2933 const file = new File([blob], pending.name, { type: blob.type }); 2934 2934 await handleImportFile(file); 2935 2935 }) 2936 - .finally(() => { 2936 + .finally(async () => { 2937 2937 window.__importInProgress = false; 2938 + // Force save now that import flag is cleared — handleImportFile's save 2939 + // was blocked by __importInProgress, so we need to save here 2940 + await provider._saveSnapshot(); 2938 2941 }); 2939 2942 } catch { 2940 2943 window.__importInProgress = false; ··· 3119 3122 DEFAULT_ROWS, 3120 3123 DEFAULT_COLS, 3121 3124 }); 3125 + // Force immediate save so imported data survives a refresh — the debounced 3126 + // save won't fire for 500ms, and the emergency sendBeacon path may send 3127 + // stale pre-import data if the user refreshes before the debounce fires. 3128 + await provider._saveSnapshot(); 3122 3129 return; 3123 3130 } 3124 3131 3125 3132 // Handle text-based files (CSV, TSV, TXT) 3126 3133 const reader = new FileReader(); 3127 - reader.onload = () => importFileContent(reader.result, file.name); 3134 + reader.onload = () => { 3135 + importFileContent(reader.result, file.name); 3136 + // Force immediate save — same reason as xlsx import above 3137 + provider._saveSnapshot(); 3138 + }; 3128 3139 reader.readAsText(file); 3129 3140 } 3130 3141