Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/vscode-ext/__tests__/superdoc-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('SuperDoc API contract', () => {
});

it('has export() method', () => {
// webview/main.js: editor.export({ format: 'docx' })
// webview/main.js: editor.export({ exportType: ['docx'], triggerDownload: false })
expect(superdocClassSrc).toMatch(/async\s+export\s*\(/);
});

Expand Down
35 changes: 35 additions & 0 deletions apps/vscode-ext/__tests__/webview-autosave.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Regression test for #3768.
*
* The webview autosave must export the document *silently*. SuperDoc's
* `export()` defaults `triggerDownload: true`, which opens a browser
* "Save File" dialog (via `showSaveFilePicker`). Because the debounced
* autosave and the Cmd/Ctrl+S handler both call `saveDocument()`, the dialog
* popped on essentially every edit. Passing `triggerDownload: false` makes
* `export()` return the Blob directly — which is what the `postMessage` save
* path consumes.
*
* Uses static analysis of the source (no webview/DOM runtime needed), matching
* the approach in superdoc-contract.test.ts.
*/
import { describe, it, expect } from 'vitest';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';

const webviewSrc = readFileSync(resolve(import.meta.dirname, '..', 'webview', 'main.js'), 'utf-8');
const exportCall = webviewSrc.match(/editor\.export\(\s*\{[^}]*\}\s*\)/)?.[0] ?? null;

describe('webview autosave export (#3768)', () => {
it('calls editor.export() in the save path', () => {
expect(exportCall, 'expected an editor.export({ ... }) call in webview/main.js').not.toBeNull();
});

it('passes triggerDownload: false so autosave does not open a Save File dialog', () => {
expect(exportCall ?? '').toMatch(/triggerDownload:\s*false/);
});

it('does not pass the unsupported `format` option', () => {
// `format` is not a recognized export() option; the correct key is `exportType`.
expect(exportCall ?? '').not.toMatch(/\bformat:/);
});
});
2 changes: 1 addition & 1 deletion apps/vscode-ext/webview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function saveDocument() {
try {
debug('Starting document save...');

const blob = await editor.export({ format: 'docx' });
const blob = await editor.export({ exportType: ['docx'], triggerDownload: false });
if (!blob) {
debug('Failed to export - no blob returned');
return;
Expand Down
Loading