Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(web): save document edits when the document ends with a list (#702)

Croff9689859f15db
diff --git a/apps/web/messages/ar/documents.json b/apps/web/messages/ar/documents.json
index fa6e3293..02afcd83 100644
--- a/apps/web/messages/ar/documents.json
+++ b/apps/web/messages/ar/documents.json
@@ -212,7 +212,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/en/documents.json b/apps/web/messages/en/documents.json
index 7813a689..93f4c649 100644
--- a/apps/web/messages/en/documents.json
+++ b/apps/web/messages/en/documents.json
@@ -212,7 +212,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/es-ES/documents.json b/apps/web/messages/es-ES/documents.json
index 3c25927c..d645bfea 100644
--- a/apps/web/messages/es-ES/documents.json
+++ b/apps/web/messages/es-ES/documents.json
@@ -212,7 +212,7 @@
"error": "Los cambios no se han sincronizado. Tu borrador se conserva en esta pestaña.",
"conflict": "El documento se restauró, se reemplazó o cambió el acceso. Guarda tu borrador antes de volver a unirte.",
"retry": "Reintentar",
- "recoveryConflict": "El documento del servidor fue reemplazado. Aquí se muestra tu texto sin guardar. Expórtalo antes de abrir la versión actual.",
+ "recoveryConflict": "Tus cambios sin guardar no encajan con la versión actual. Exporta el texto que se muestra aquí y luego abre la versión actual.",
"exportRecovery": "Exportar mi texto",
"discardRecovery": "Abrir la versión actual",
"discardConfirm": "¿Descartar esta copia sin guardar y abrir la versión actual del servidor? Exporta tu texto primero si lo necesitas."
diff --git a/apps/web/messages/fa/documents.json b/apps/web/messages/fa/documents.json
index 4f95eeca..9e55864b 100644
--- a/apps/web/messages/fa/documents.json
+++ b/apps/web/messages/fa/documents.json
@@ -212,7 +212,7 @@
"error": "تغییرات همگام‌سازی نشدند. پیش‌نویس شما در همین تب نگه داشته می‌شود.",
"conflict": "سند بازیابی یا جایگزین شد، یا دسترسی تغییر کرد. پیش از پیوستن دوباره، پیش‌نویس خود را نگه دارید.",
"retry": "تلاش دوباره",
- "recoveryConflict": "سند سرور جایگزین شد. متن ذخیره‌نشده شما اینجا نمایش داده می‌شود. پیش از باز کردن نسخه فعلی، آن را خروجی بگیرید.",
+ "recoveryConflict": "تغییرات ذخیره‌نشده شما با نسخه فعلی سازگار نیست. متن نمایش‌داده‌شده در اینجا را خروجی بگیرید، سپس نسخه فعلی را باز کنید.",
"exportRecovery": "خروجی گرفتن از متن من",
"discardRecovery": "باز کردن نسخه فعلی",
"discardConfirm": "این نسخه ذخیره‌نشده دور انداخته شود و نسخه فعلی سرور باز شود؟ اگر به آن نیاز دارید، ابتدا از متن خود خروجی بگیرید."
diff --git a/apps/web/messages/fr/documents.json b/apps/web/messages/fr/documents.json
index 33f21c63..d06a9e96 100644
--- a/apps/web/messages/fr/documents.json
+++ b/apps/web/messages/fr/documents.json
@@ -212,7 +212,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/id/documents.json b/apps/web/messages/id/documents.json
index 6392b04d..5a46c576 100644
--- a/apps/web/messages/id/documents.json
+++ b/apps/web/messages/id/documents.json
@@ -210,7 +210,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/ko/documents.json b/apps/web/messages/ko/documents.json
index 548d0484..054519cd 100644
--- a/apps/web/messages/ko/documents.json
+++ b/apps/web/messages/ko/documents.json
@@ -212,7 +212,7 @@
"error": "변경 사항이 동기화되지 않았습니다. 초안은 이 탭에 유지됩니다.",
"conflict": "문서가 복원 또는 교체되었거나 접근 권한이 변경되었습니다. 다시 연결하기 전에 초안을 보관하세요.",
"retry": "다시 시도",
- "recoveryConflict": "서버의 문서가 교체되었습니다. 저장하지 않은 내용이 여기에 표시됩니다. 현재 버전을 열기 전에 내보내세요.",
+ "recoveryConflict": "저장하지 않은 변경 사항이 현재 버전과 맞지 않습니다. 여기에 표시된 내용을 내보낸 후 현재 버전을 여세요.",
"exportRecovery": "내 내용 내보내기",
"discardRecovery": "현재 버전 열기",
"discardConfirm": "저장하지 않은 내용을 삭제하고 현재 서버 버전을 여시겠습니까? 필요한 경우 먼저 내용을 내보내세요."
diff --git a/apps/web/messages/pt-BR/documents.json b/apps/web/messages/pt-BR/documents.json
index 25c280be..79b63ccd 100644
--- a/apps/web/messages/pt-BR/documents.json
+++ b/apps/web/messages/pt-BR/documents.json
@@ -210,7 +210,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/ru/documents.json b/apps/web/messages/ru/documents.json
index 1efe45f7..487d5fd1 100644
--- a/apps/web/messages/ru/documents.json
+++ b/apps/web/messages/ru/documents.json
@@ -212,7 +212,7 @@
"error": "Изменения пока не отправлены. Черновик сохранён в этой вкладке.",
"conflict": "Документ восстановлен, заменён или доступ изменился. Сохраните свой черновик перед повторным подключением.",
"retry": "Повторить",
- "recoveryConflict": "Документ на сервере заменён. Здесь показан ваш несохранённый текст. Скачайте его перед открытием текущей версии.",
+ "recoveryConflict": "Несохранённые изменения не подходят к текущей версии. Скачайте показанный здесь текст, затем откройте текущую версию.",
"exportRecovery": "Скачать мой текст",
"discardRecovery": "Открыть текущую версию",
"discardConfirm": "Удалить несохранённую копию и открыть текущую версию с сервера? Сначала скачайте текст, если он нужен."
diff --git a/apps/web/messages/tr/documents.json b/apps/web/messages/tr/documents.json
index 082bf687..ba73f588 100644
--- a/apps/web/messages/tr/documents.json
+++ b/apps/web/messages/tr/documents.json
@@ -212,7 +212,7 @@
"error": "Değişiklikler eşitlenemedi. Taslağınız bu sekmede tutuluyor.",
"conflict": "Belge geri yüklendi, değiştirildi veya erişim hakları güncellendi. Yeniden katılmadan önce taslağınızı saklayın.",
"retry": "Tekrar dene",
- "recoveryConflict": "Sunucudaki belge değiştirildi. Kaydedilmemiş metniniz burada gösterilmektedir. Mevcut sürümü açmadan önce metninizi dışa aktarın.",
+ "recoveryConflict": "Kaydedilmemiş değişiklikleriniz mevcut sürümle uyuşmuyor. Burada gösterilen metni dışa aktarın, ardından mevcut sürümü açın.",
"exportRecovery": "Metnimi dışa aktar",
"discardRecovery": "Mevcut sürümü aç",
"discardConfirm": "Kaydedilmemiş bu kopya silinip mevcut sunucu sürümü açılsın mı? İhtiyacınız varsa önce metninizi dışa aktarın."
diff --git a/apps/web/messages/uk/documents.json b/apps/web/messages/uk/documents.json
index 33b6c884..7fcd5ea8 100644
--- a/apps/web/messages/uk/documents.json
+++ b/apps/web/messages/uk/documents.json
@@ -212,7 +212,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/zh-CN/documents.json b/apps/web/messages/zh-CN/documents.json
index fa1bbecc..8d469ba1 100644
--- a/apps/web/messages/zh-CN/documents.json
+++ b/apps/web/messages/zh-CN/documents.json
@@ -212,7 +212,7 @@
"error": "Changes have not synced. Your draft is kept in this tab.",
"conflict": "The document was restored, replaced, or access changed. Keep your draft before rejoining.",
"retry": "Retry",
- "recoveryConflict": "The server document was replaced. Your unsaved text is shown here. Export it before opening the current version.",
+ "recoveryConflict": "Your unsaved changes don't fit the current version. Export the text shown here, then open the current version.",
"exportRecovery": "Export my text",
"discardRecovery": "Open current version",
"discardConfirm": "Discard this unsaved copy and open the current server version? Export your text first if you need it."
diff --git a/apps/web/messages/zh-TW/documents.json b/apps/web/messages/zh-TW/documents.json
index ca356da0..539a7604 100644
--- a/apps/web/messages/zh-TW/documents.json
+++ b/apps/web/messages/zh-TW/documents.json
@@ -212,7 +212,7 @@
"error": "變更尚未同步。你的草稿保留在此分頁。",
"conflict": "文件已被還原、取代,或存取權限已變更。重新加入前請先保留你的草稿。",
"retry": "重試",
- "recoveryConflict": "伺服器上的文件已被取代,這裡顯示你未儲存的文字。開啟目前版本前請先匯出。",
+ "recoveryConflict": "未儲存的變更與目前版本不相符。請先匯出這裡顯示的文字,再開啟目前版本。",
"exportRecovery": "匯出我的文字",
"discardRecovery": "開啟目前版本",
"discardConfirm": "要捨棄這份未儲存的副本,開啟伺服器上的目前版本嗎?如果還需要,請先匯出你的文字。"
diff --git a/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts b/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts
index 8f0e9a0e..2a399c5a 100644
--- a/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts
+++ b/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts
@@ -485,6 +485,52 @@ describe('collaborative editor convergence', () => {
assert.equal(editor.getText(), 'One\n\nFirst\n\nTwo\n\nSecond');
editor.destroy();
});
+
+ it('sends every change to a document that ends with a list', async () => {
+ const { collab, sendableSteps } = await import('prosemirror-collab');
+ const editor = new Editor({
+ element: document.querySelector('#one') as HTMLElement,
+ extensions: documentEditorExtensions({
+ placeholder: '',
+ codeBlockLabel: 'Code',
+ tableLabel: 'Table',
+ }),
+ });
+ const served: JSONContent = {
+ type: 'doc',
+ content: [
+ {
+ type: 'paragraph',
+ attrs: { blockId: 'intro' },
+ content: [{ type: 'text', text: 'Intro' }],
+ },
+ {
+ type: 'bulletList',
+ attrs: { blockId: 'list' },
+ content: [
+ {
+ type: 'listItem',
+ content: [
+ {
+ type: 'paragraph',
+ attrs: { blockId: 'last' },
+ content: [{ type: 'text', text: 'Last' }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+ editor.commands.setContent(served, { emitUpdate: false });
+ let server = editor.schema.nodeFromJSON(served);
+ editor.registerPlugin(collab({ clientID: 'one' }));
+ editor.commands.setTextSelection(server.content.size - 3);
+ editor.commands.splitListItem('listItem');
+ for (const step of sendableSteps(editor.state)!.steps) server = step.apply(server).doc!;
+ assert.ok(server.eq(editor.state.doc));
+ editor.destroy();
+ });
});
describe('collaborative block anchors', () => {
diff --git a/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx b/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx
index 741badd0..11a5d17a 100644
--- a/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx
+++ b/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx
@@ -87,6 +87,8 @@ export function documentEditorExtensions(labels: EditorLabels) {
codeBlock: false,
link: false,
heading: { levels: [1, 2, 3, 4, 5, 6] },
+ // Its paragraph is added before collab starts, so the server copy never gets it.
+ trailingNode: false,
}),
CodeBlockLowlight.configure({ lowlight }),
Placeholder.configure({ placeholder: labels.placeholder }),
diff --git a/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx b/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx
index c841cc78..f9ae4bac 100644
--- a/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx
+++ b/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx
@@ -176,4 +176,54 @@ describe('useDocumentCollaboration', () => {
assert.equal(collaboration.ready, false);
assert.equal(collaboration.openFailed, true);
});
+
+ it('offers the stored changes for export when one of them no longer applies', async () => {
+ window.sessionStorage.setItem(
+ 'document-steps:user-1:SEKTA:42',
+ JSON.stringify({
+ epoch: 'e1',
+ version: 0,
+ clientId: 'client-1',
+ base: {
+ type: 'doc',
+ content: [
+ {
+ type: 'paragraph',
+ attrs: { blockId: 'saved' },
+ content: [{ type: 'text', text: 'Saved' }],
+ },
+ ],
+ },
+ steps: [
+ {
+ stepType: 'replace',
+ from: 6,
+ to: 6,
+ slice: { content: [{ type: 'text', text: '!' }] },
+ },
+ {
+ stepType: 'replaceAround',
+ from: 20,
+ to: 22,
+ gapFrom: 21,
+ gapTo: 21,
+ insert: 1,
+ slice: { content: [{ type: 'paragraph' }] },
+ structure: true,
+ },
+ ],
+ }),
+ );
+ await act(async () => {
+ root.render(
+ <QueryClientProvider client={queryClient}>
+ <Probe document={projectDocument(2, 'Saved')} />
+ </QueryClientProvider>,
+ );
+ });
+
+ assert.equal(collaboration.recoveryConflict, true);
+ assert.equal(collaboration.status, 'conflict');
+ assert.equal(editor.getText(), 'Saved!');
+ });
});
diff --git a/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts b/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts
index c4a4be81..ce003945 100644
--- a/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts
+++ b/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts
@@ -203,9 +203,16 @@ export function useDocumentCollaboration({
.run();
editor.unregisterPlugin('history');
editor.registerPlugin(history());
- if (recovery && !canRecover) {
- const tr = editor.state.tr;
- for (const json of recovery.steps) tr.step(Step.fromJSON(editor.schema, json));
+ const tr = editor.state.tr;
+ // A stored step that no longer applies can never be saved: the steps before it go to export.
+ const replayed = (recovery?.steps ?? []).every((json) => {
+ try {
+ return !tr.maybeStep(Step.fromJSON(editor.schema, json)).failed;
+ } catch {
+ return false;
+ }
+ });
+ if (recovery && (!canRecover || !replayed)) {
editor.view.dispatch(tr);
setRecoveryConflict(true);
setStatus('conflict');
@@ -217,8 +224,6 @@ export function useDocumentCollaboration({
);
state.current = { epoch: session.epoch, clientId, confirmed: base, snapshot: editor.state };
if (recovery) {
- const tr = editor.state.tr;
- for (const json of recovery.steps) tr.step(Step.fromJSON(editor.schema, json));
editor.view.dispatch(tr);
state.current.snapshot = editor.state;
}
@@ -244,8 +249,10 @@ export function useDocumentCollaboration({
useEffect(() => {
if (!editor || !ready) return;
let timer: ReturnType<typeof setTimeout> | undefined;
+ // A menu or selection update must not retry a refused save.
const changed = () => {
- if (!state.current || editor.isDestroyed) return;
+ if (!state.current || editor.isDestroyed || editor.state.doc === state.current.snapshot.doc)
+ return;
state.current.snapshot = editor.state;
if (!sendableSteps(editor.state)) return;
setStatus('saving');