Repository navigation
fix(undo): restore deleted blocks with inner refs - #13458
Conversation
|
The same Verified with a repro on this branch: create today's journal with two top-level blocks x and y where
Suggestion: route (Also heads-up: this PR currently has a merge conflict with master.) |
d7cc7e1 to
1be2a41
Compare
1be2a41 to
d28a8d5
Compare
tiensonqin
left a comment
There was a problem hiding this comment.
Can reproduce the issue and the PRs works great! 🚢 👍
The inverse of a block delete restores each selected root with its own insert op. When a block of one op refers to a block that a later op restores (a node property value, a used template), the insert fails on the missing lookup ref, the replay reports :error and undo clears the history. Take those refs out of the insert payloads and set them with save-block ops after all inserts.
d28a8d5 to
6adabc7
Compare
|
Confirmed on master: undoing the delete of today's journal or of a tag page whose blocks refer to each other is refused and clears the history. Fixed in #13528 (logseq/db-test#1379). |
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
logseq#13476, logseq#13462 and logseq#13458 are in upstream master e2ca31b. logseq#13528 joins.
What changes
Undo of a block delete did nothing when one deleted block referred to another deleted block, and it cleared the undo history. The property-based test that found the bugs of #13444 found it: random sequences of outliner operations applied through
outliner-op/apply-ops!with the worker's undo history recording, each undone and compared with the graph before it. Both cases below have a regression test infrontend.worker.undo-redo-testthat fails on master.Graph in the steps below: page 1 holds a, b (children b1, b2), c. Page 2 holds d and tmpl (tagged Template, child "tmpl child"). A journal holds e. Selections of blocks that are not neighbors come from Ctrl/Cmd+click, which adds 1 block at a time in click order.
Steps
used-templatepoints at tmpl. Ctrl+click the copy, then tmpl, and delete. Undo: nothing comes back.After either undo, the undo history is empty, so no further undo works.
Cause
The inverse of
:delete-blocks(build-inverse-delete-blocks,construct.cljc:795) restores each selected root with its own:insert-blocksop, in selection order. A restored block's payload keeps its ref values as[:block/uuid ...]lookups. When a block in one op refers to a block that a later op restores, the first insert fails with "Nothing found for entity id". In case 1, a'srelatedvalue is b1, which comes back with b. In case 2, the copy'sused-templateis tmpl. Refs inside 1 op resolve, becauseinsert-blockstransacts every inserted uuid first (core.cljs:1032). The replay (apply-history-action!) fails with reason:error, and undo clears the history (undo_redo.cljs:241).Reordering the ops cannot fix case 1. b's restore target is its old left sibling a, so a must come back before b, while a's value needs b1.
Fix
build-inverse-delete-blocksremoves from the insert payloads every ref value that points at a block restored by a later insert op. After all the inserts,:save-blockops set those values again (defer-refs-to-later-plans). For a many-valued property, only the values that point at later blocks move. The other values stay in the insert. The inverse of a delete without such refs is unchanged.Related: logseq/db-test#1302 covers a different case, where a block that survives keeps a reference to a deleted block and undo does not restore it. I found no db-test report of this bug. I searched for "undo delete", "undo delete template", "undo delete property reference", "undo delete multiple blocks", "undo delete blocks node property", "undo does nothing delete", "used-template" and "undo selected blocks".
Tests
frontend.worker.undo-redo-test: 2 new tests,undo-delete-of-blocks-referring-to-each-other-test(it also redoes and undoes again) andundo-delete-of-template-and-its-applied-copy-test. On master they have 13 failures in 17 assertions. With the fix they pass: the namespace ran 31 tests with 184 assertions and 0 failures.TZ=Etc/GMT+12,frontend.undo-redo-test,logseq.outliner.op-construct-test(copied into the main test build for the run) andfrontend.modules.outliner.core-testhad 0 failures.frontend.worker.db-sync-testran 231 tests with 1 failure. That failure isoutliner-upload-chunks-preserve-entities-and-acknowledgment-test, an intermittent upload-chunking failure that also happens on master. This change doesn't touch upload.TZ=Etc/GMT+12(2478 tests, 12424 assertions) and the time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1448 tests, 8998 assertions): the only failures are the zone-dependent tests that fix(test): build test dates in local time #13430 fixes, the upload-chunks flake that fix(sync): keep value replacements in one request #13432 fixes, and the CPU-time bound ofcombine-results-large-result-benchmark(Unit tests: assert on work done instead of elapsed time #13446), all of which fail on master too.Allow edits from maintainers.