Repository navigation
Conversation
Deleting a block retracts it with :db/retractEntity, which also retracts ref values other blocks hold on it, such as a node property value. The undo inverse only reinserted the deleted subtree, so those values stayed empty. Restore them from the retracted datoms with :save-block. Fixes logseq/db-test#1302
A history action can hold several :delete-blocks ops whose deleted blocks share a reference holder. Restore the retracted ref values once, after all inverse ops, instead of inside each delete inverse, so the restore never depends on the order the deleted blocks are reinserted.
b4686d5 to
c60ebaa
Compare
Review: fix looks correct for its intended path — one Important gapThe approach is sound: Important (pre-existing on master, but same bug class)When a deleted holder block references another deleted block, undo still fails entirely. The holder's The new deferred Reproduced with a worker test (delete holder + its property target in a single action) on both this branch and master — identical failure, so this is not a regression, but it leaves a common case of this bug class unfixed. Suggested direction: strip ref attrs whose values intersect Minor / questions
Verified: both new tests pass; no overlap with the recently merged undo fixes (#13335's |
|
Two issues with 1. The trigger misses Verified with a repro on this branch: holder block Suggestion: trigger on the tx-data instead of the op name — e.g. only gate on 2. Over-restore on mixed txs (Minor). The restore op writes the holder's attr to the full |
:delete-page hard-deletes blocks too, e.g. when it truncates today's journal page or deletes a class or property page, which retracts the ref values other blocks hold on them. Run the inbound ref restore for :delete-page as well as :delete-blocks.
A delete can also add values to the attr it retracts a ref from, e.g. a child class extends Root after its parent class is deleted. The restore :save-block added the old values next to them, so undo left the child extending both classes. Retract the restored attrs first.
Fixes logseq/db-test#1302
Problem
Deleting a block retracts it with
:db/retractEntity(-delindeps/outliner/src/logseq/outliner/core.cljs), which also retracts every ref value other blocks hold on it, such as a node property value. The undo inverse (build-inverse-delete-blocksindeps/outliner/src/logseq/outliner/op/construct.cljc) only reinserts the deleted subtree, so those values stay empty. Steps: set a node property (e.g.related) on block B to block A, delete A, undo. A comes back but B no longer has the related property at all.Fix
build-inverse-delete-blocksnow also receives the delete'stx-data. A newinbound-ref-restore-opscollects the retracted ref datoms whose value is a deleted block and whose entity is outside the deleted subtree, then appends one:save-blockper such entity that restores those attributes fromdb-before, the same waybuild-inverse-save-blockrestores attributes. The ops run after the:insert-blocks, so the restored block exists when the values are set. This covers:oneand:manycardinalities and any ref attribute, not only one property.Testing
Added
undo-delete-block-restores-node-property-values-pointing-at-it-testinfrontend.worker.undo-redo-test. It sets:oneand:manynode properties on a block to another block, deletes that block, undoes, and asserts both values point at the restored block again, then redoes and asserts the value is gone. It fails on master (both values empty after undo).deps/outlinertests: 135 tests, 0 failures:app): with the steps above, after Ctrl+Z therelatedvalue points at the restored block again; redo removes it and a second undo restores it again. No console errors.relatednode property on a block to another block, deleted that block, pressed Ctrl+Z. The deleted block came back and therelatedproperty reappeared under the other block, pointing at the restored block. Before the fix, the deleted block came back but the other block no longer showed therelatedproperty at all.Root cause analysis and fix drafted with Claude Code assistance