Skip to content

fix(views): a references view isn't created for a node that is gone - #13852

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/view-for-gone-page
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/view-for-gone-page

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

Problem

A page's linked/unlinked references section creates its view block the first time it renders (create-view! in src/main/frontend/components/views.cljs, outliner op :create-view). When the page is removed while its section is still mounted, e.g. an undo chain that removes a page just made by a paste, the section creates a view whose :logseq.property/view-for is the gone page, and the worker refuses the write: DB worker API failed: :thread-api/apply-outliner-ops Error: DB write failed with invalid data, with the view entity's :logseq.property/view-for "should be a node with a title". A local key fuzzer (random editor keys, Ctrl+K navigation and undo/redo chains, sent with no wait) hit it four times in one run of 24.

Cause

create-view! builds the view from view-parent, the entity the component last rendered, and never checks that it still exists before sending api-insert-new-block!.

Fix

create-view! reads the parent by its uuid first (db-async/<get-block) and creates no view when it is gone. A parent that exists gets its view as before.

Tests

  • New frontend.components.views-test/create-view-skips-a-parent-that-is-gone-test: create-view! for a parent the db no longer returns sends no insert (before the change it inserted the view), for a parent that exists one insert. Fails without the change, passes with it.
  • frontend.components.views-test passes; CI's whole unit suite (pnpm cljs:run-test) passes apart from frontend.db.query-dsl-test/block-property-query-performance, a 40 ms timing check that took 43 ms on a loaded machine and passes on its own; lint (kondo, large vars, typos) is clean.

A page's linked/unlinked references section creates its view block the
first time it renders (create-view!, :outliner-op :create-view). When the
page was removed while its section was still mounted (an undo chain
removing a page just created, e.g. by a paste), the section created a view
whose :logseq.property/view-for is the gone page. The worker refused the
write ("DB write failed with invalid data", view-for "should be a node
with a title"). A local key fuzzer hit it four times in one run of 24.

create-view! now reads the view's parent by uuid first and creates no
view when it is gone. Views for a parent that exists are created as
before.

create-view-skips-a-parent-that-is-gone-test runs create-view! for a
parent the db no longer returns (no insert; before the change it inserted
the view) and for one that exists (one insert).
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Superseded by #13782, which closes this in the db worker instead of the client: a client check reads the client's own copy of the db, so a write can still reach the worker after its target is gone. #13782 drops such writes in the worker (property writes from the app's apply-outliner-ops, and view blocks whose node is gone), with tests that fail on master. Closing to keep the fixes for this race in one place.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/view-for-gone-page branch November 17, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant