Skip to content

Commit 731b0c7

Browse files
committed
fix(pdf-server): reload PDF after successful save instead of rebasing in place
Rebasing baselines while keeping the old pdfDocument drifts: subsequent renders rasterize annotations that were just stripped from disk, and the field/widget split pdf-lib's save can create isn't visible until reload. Reload makes 'viewer == disk' an invariant. localStorage cleared first; file_changed echo suppressed by lastSavedMtime as before.
1 parent 1a44564 commit 731b0c7

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

examples/pdf-server/src/mcp-app.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,19 +3124,6 @@ async function savePdf(): Promise<void> {
31243124
const sc = result.structuredContent as { mtimeMs?: number } | undefined;
31253125
lastSavedMtime = sc?.mtimeMs ?? null;
31263126

3127-
// Rebase: the file on disk now contains our annotations + form values.
3128-
// Update the baseline so future diffs are relative to what was saved.
3129-
pdfBaselineAnnotations = [...annotationMap.values()].map((t) => ({
3130-
...t.def,
3131-
}));
3132-
pdfBaselineFormValues.clear();
3133-
for (const [k, v] of formFieldValues) pdfBaselineFormValues.set(k, v);
3134-
3135-
setDirty(false); // → updateSaveBtn() disables button
3136-
// Panel diffs against the baselines we just rebased — re-render so the
3137-
// "edited" badges and pending-change list go away.
3138-
updateAnnotationsBadge();
3139-
renderAnnotationPanel();
31403127
const key = annotationStorageKey();
31413128
if (key) {
31423129
try {
@@ -3145,6 +3132,13 @@ async function savePdf(): Promise<void> {
31453132
/* ignore */
31463133
}
31473134
}
3135+
// Reload from the bytes we just wrote. The previous approach (rebase
3136+
// baselines but keep the old pdfDocument) drifts: subsequent renders
3137+
// still rasterize stripped annotations from the old bytes, and the
3138+
// field/widget split that pdf-lib's save can create isn't reflected
3139+
// until reload anyway. Reload makes "what you see = what's on disk"
3140+
// an invariant. (file_changed echo is suppressed by lastSavedMtime.)
3141+
await reloadPdf();
31483142
}
31493143
} catch (err) {
31503144
log.error("Save failed:", err);

0 commit comments

Comments
 (0)