fix: restore :ref/default-open-blocks-level 0 behavior in DB graphs (re-fix after #12228 regressed)#12501
fix: restore :ref/default-open-blocks-level 0 behavior in DB graphs (re-fix after #12228 regressed)#12501VictorVow wants to merge 1 commit intologseq:masterfrom
Conversation
Three related fixes to make `:ref/default-open-blocks-level 0` work correctly in the DB version: 1. Collapse the entire "Linked References" section by default when the configured level is 0, matching the previous file-graph behavior where level 0 meant "show no expanded references". 2. Propagate :block.temp/has-children? on the top-level fetched block in get-block-and-children, not just on its children. The list-view loads linked-reference blocks with :children? false, so (:block/_parent …) is always nil in the client DB. Without this flag the collapse check in block-default-collapsed? could never fire for those blocks. 3. Use :block.temp/has-children? as a fallback when computing has-child? in block-container-inner-aux. This makes the collapse arrow render for blocks whose children exist in the worker DB but haven't been lazily loaded into the client DB yet (e.g. linked-reference blocks). Clicking the arrow calls expand-block! which loads the children on demand. The :ref/default-open-blocks-level 0 → (int? …) state.cljs fix from PR logseq#12228 is already present on this branch.
a0ee132 to
a6c4ab7
Compare
There was a problem hiding this comment.
Pull request overview
Restores :ref/default-open-blocks-level 0 behavior for DB graphs after regressions introduced by list-view and lazy child loading, ensuring linked references collapse correctly and blocks still show expand/collapse affordances.
Changes:
- Collapse the entire “Linked References” view by default when
:ref/default-open-blocks-levelis0. - Propagate
:block.temp/has-children?onto the top-level fetched block inget-block-and-children. - Render the collapse arrow for lazily-loaded blocks by using
:block.temp/has-children?as a fallback for child detection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/main/frontend/components/reference.cljs |
Uses get-ref-open-blocks-level to default-collapse the linked references view when level is 0. |
src/main/frontend/components/block.cljs |
Uses :block.temp/has-children? to detect children even when they aren’t pulled into the client DB yet. |
deps/db/src/logseq/db/common/initial_data.cljs |
Ensures the top-level fetched block includes :block.temp/has-children? so default-collapse logic can apply. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| :else | ||
| :self)))] | ||
| :self) | ||
| :block.temp/has-children? (some? (:block/_parent block))))] |
There was a problem hiding this comment.
:block.temp/has-children? is computed via (:block/_parent block) for the top-level entity. In DataScript, reading a reverse ref can materialize the full child entity set; for blocks with many children this can add noticeable overhead even when children? is false. Consider switching this existence check to a lightweight indexed datoms lookup (e.g. seq (d/datoms db :avet :block/parent (:db/id block))) so you only scan until the first child datom instead of realizing all children entities.
| :self) | ||
| :block.temp/has-children? (some? (:block/_parent block))))] |
There was a problem hiding this comment.
This change is fixing a regression by relying on :block.temp/has-children? being present even when fetching a block without its children. There doesn’t appear to be coverage for common-initial-data/get-block-and-children returning this flag on the top-level block; adding a regression test in deps/db/test/logseq/db/common/initial_data_test.cljs (or a new test ns nearby) would help prevent this from breaking again.
Problem
PR #12228 fixed
default-open-blocks-level 0but subsequent changes to the DB graph codebase (new list-view, lazy child loading) broke it again in three distinct ways.Root causes & fixes
1. Linked References section not collapsed (
reference.cljs)The
references-auxcomponent was not readingopen-blocks-levelat all. Added:foldable-options {:default-collapsed? true}when the configured level is0, so the entire "Linked References" section collapses by default — matching the original file-graph behavior where level0meant "show no expanded references".2.
block.temp/has-children?not propagated to top-level blocks (initial_data.cljs)get-block-and-childrenalready set:block.temp/has-children?on child blocks, but not on the top-level fetched block itself. The list-view loads linked-reference blocks with:children? false, meaning(:block/_parent …)is alwaysnilin the client DB for those blocks. Without this flag theblock-default-collapsed?check could never fire for them.3. Collapse arrow missing for lazily-loaded blocks (
block.cljs)has-child?inblock-container-inner-auxused only(:block/_parent …)— which isnilfor blocks whose children live in the worker DB but haven't been pulled into the client DB yet. Added:block.temp/has-children?as a fallback so the collapse arrow renders correctly, and clicking it callsexpand-block!which loads the children on demand.Testing
:ref/default-open-blocks-level 0in config.