Skip to content

Commit 1a5be72

Browse files
committed
fix: prefer provider doc over empty dialog sub-doc
when duplicating rows
1 parent 2205f35 commit 1a5be72

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

  • src/application/database-yjs/dispatch

src/application/database-yjs/dispatch/row.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,24 @@ export function useDuplicateRowDispatch() {
578578
if (sourceDocId) {
579579
// Check the dialog sub-doc cache first, then fall back to the
580580
// IndexedDB provider cache (used by full-page row editors).
581-
const cachedDoc = getCachedRowSubDoc(sourceDocId) ?? getCachedProviderDoc(sourceDocId);
581+
// Important: the dialog sub-doc may be an empty shell if the user
582+
// typed content in full-page mode — in that case prefer the
583+
// provider doc which has the actual content.
584+
let cachedDoc = getCachedRowSubDoc(sourceDocId);
585+
586+
if (cachedDoc) {
587+
// Verify the sub-doc has real document content, not just empty structure
588+
const subDocRoot = cachedDoc.getMap(YjsEditorKey.data_section);
589+
const subDocDocument = subDocRoot?.get(YjsEditorKey.document) as Y.Map<unknown> | undefined;
590+
const subDocBlocks = subDocDocument?.get(YjsEditorKey.blocks) as Y.Map<unknown> | undefined;
591+
592+
if (!subDocBlocks || subDocBlocks.size <= 2) {
593+
// Dialog sub-doc is empty — try the provider doc instead
594+
cachedDoc = getCachedProviderDoc(sourceDocId) ?? cachedDoc;
595+
}
596+
} else {
597+
cachedDoc = getCachedProviderDoc(sourceDocId) ?? null;
598+
}
582599

583600
if (cachedDoc) {
584601
const docState = Y.encodeStateAsUpdate(cachedDoc);

0 commit comments

Comments
 (0)