···952952 // Convert data URL back to a File object
953953 fetch(pending.data)
954954 .then(r => r.blob())
955955- .then(blob => {
955955+ .then(async blob => {
956956 const file = new File([blob], pending.name, { type: blob.type });
957957- handleImportedFile(file);
957957+ await handleImportedFile(file);
958958 })
959959- .finally(() => {
959959+ .finally(async () => {
960960 window.__importInProgress = false;
961961+ // Force save now that import flag is cleared
962962+ await provider._saveSnapshot();
961963 });
962964 } catch {
963965 window.__importInProgress = false;
···10271029}
1028103010291031// --- Import functions ---
10301030-function handleImportedFile(file: File): void {
10321032+async function handleImportedFile(file: File): Promise<void> {
10311033 const ext = file.name.split('.').pop().toLowerCase();
1032103410331035 // Handle .docx files via mammoth
10341036 if (ext === 'docx') {
10351035- importDocx(file, editor, showToast);
10371037+ await importDocx(file, editor, showToast);
10381038+ // Force immediate save so imported data survives a refresh
10391039+ await provider._saveSnapshot();
10361040 return;
10371041 }
10381042···10501054 editor.commands.insertContent(content);
10511055 }
10521056 showToast(`Imported "${file.name}" successfully`, 3000);
10571057+ // Force immediate save so imported data survives a refresh
10581058+ provider._saveSnapshot();
10531059 };
10541060 reader.readAsText(file);
10551061}
+13-2
src/sheets/main.ts
···29332933 const file = new File([blob], pending.name, { type: blob.type });
29342934 await handleImportFile(file);
29352935 })
29362936- .finally(() => {
29362936+ .finally(async () => {
29372937 window.__importInProgress = false;
29382938+ // Force save now that import flag is cleared — handleImportFile's save
29392939+ // was blocked by __importInProgress, so we need to save here
29402940+ await provider._saveSnapshot();
29382941 });
29392942 } catch {
29402943 window.__importInProgress = false;
···31193122 DEFAULT_ROWS,
31203123 DEFAULT_COLS,
31213124 });
31253125+ // Force immediate save so imported data survives a refresh — the debounced
31263126+ // save won't fire for 500ms, and the emergency sendBeacon path may send
31273127+ // stale pre-import data if the user refreshes before the debounce fires.
31283128+ await provider._saveSnapshot();
31223129 return;
31233130 }
3124313131253132 // Handle text-based files (CSV, TSV, TXT)
31263133 const reader = new FileReader();
31273127- reader.onload = () => importFileContent(reader.result, file.name);
31343134+ reader.onload = () => {
31353135+ importFileContent(reader.result, file.name);
31363136+ // Force immediate save — same reason as xlsx import above
31373137+ provider._saveSnapshot();
31383138+ };
31283139 reader.readAsText(file);
31293140}
31303141