Skip to content

fix: restore :ref/default-open-blocks-level 0 behavior in DB graphs (re-fix after #12228 regressed)#12501

Open
VictorVow wants to merge 1 commit intologseq:masterfrom
VictorVow:fix/open-blocks-config
Open

fix: restore :ref/default-open-blocks-level 0 behavior in DB graphs (re-fix after #12228 regressed)#12501
VictorVow wants to merge 1 commit intologseq:masterfrom
VictorVow:fix/open-blocks-config

Conversation

@VictorVow
Copy link
Copy Markdown
Contributor

Problem

PR #12228 fixed default-open-blocks-level 0 but 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-aux component was not reading open-blocks-level at all. Added :foldable-options {:default-collapsed? true} when the configured level is 0, so the entire "Linked References" section collapses by default — matching the original file-graph behavior where level 0 meant "show no expanded references".

2. block.temp/has-children? not propagated to top-level blocks (initial_data.cljs)

get-block-and-children already 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 always nil in the client DB for those blocks. Without this flag the block-default-collapsed? check could never fire for them.

3. Collapse arrow missing for lazily-loaded blocks (block.cljs)

has-child? in block-container-inner-aux used only (:block/_parent …) — which is nil for 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 calls expand-block! which loads the children on demand.

Testing

  1. Set :ref/default-open-blocks-level 0 in config.
  2. Open a page that has linked references.
  3. The "Linked References" section should be collapsed by default.
  4. Expanding the section and then individual blocks should show the collapse arrows and children load on demand.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-level is 0.
  • Propagate :block.temp/has-children? onto the top-level fetched block in get-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.

Comment on lines 269 to +271
:else
:self)))]
:self)
:block.temp/has-children? (some? (:block/_parent block))))]
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: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.

Copilot uses AI. Check for mistakes.
Comment on lines +270 to +271
:self)
:block.temp/has-children? (some? (:block/_parent block))))]
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants