Skip to content

fix(query): a {{function}} child keeps its parent query's result after a re-render - #13879

Closed
yuxi-liu-wired wants to merge 2 commits into
logseq:masterfrom
yuxi-liu-wired:fix/query-function-rerender
Closed

yuxi-liu-wired wants to merge 2 commits into
logseq:masterfrom
yuxi-liu-wired:fix/query-function-rerender

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #12949.

Each render of a block made a new :query-result atom when its config had none (build-config in components/block.cljs). The query component fills the atom of the parent's latest render, while a {{function ...}} child can still hold the atom from an earlier render; that one stays nil and the child falls back to the raw yellow macro text. It happens mostly after a reload, when the query block renders again before its rows arrive, which matches the report (works when first created, fails after a reload, scrolling "rerolls" it).

The block container now keeps one atom per mounted block (hooks/use-memo) and passes it to build-config, so every render of the query block, and every child, shares it.

Test: frontend.components.block.macros-test/function-macro-child-sees-query-result-after-parent-rerender: a child holding the first render's config sees the rows published after the second render. It fails without the change.


Devin Review

…lt after a re-render

Each render of a block made a new `:query-result` atom when the incoming config had none. The query component filled the atom of the parent's latest render, while a `{{function ...}}` child still held the atom from an earlier render, so it stayed nil and fell back to the raw yellow macro text. It happened mostly after a reload, when the query block renders again before its rows arrive.

The block container now keeps one atom per mounted block and passes it to `build-config`.

Fixes logseq#12949

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment thread src/main/frontend/components/block.cljs Outdated
;; would otherwise wait on an atom the query no longer fills.
(nil? (:query-result config))
(assoc :query-result (atom nil))
(assoc :query-result (or *query-result (atom nil)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Missing query atom silently creates orphan state

When build-config receives no *query-result, it creates a fresh atom on every call. That masks an invalid call and leaves earlier children watching an atom later renders cannot fill.

Learn more

The block container creates the atom with hooks/use-memo and passes it to build-config. The new fallback accepts an omitted atom, so a caller error silently returns to the original per-render behavior. The repository requires fail-fast behavior instead of defaults that hide invalid state.

Example: If a caller invokes build-config twice with {} as its options, the first child keeps atom A while the second query render fills atom B. The child stays on its warning text.

Recommended fix: Remove the fallback and require *query-result at the controlled call site. Assert that it is present if build-config must diagnose malformed internal calls.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +111 to +119
build-config #'block/build-config
;; The block container keeps one atom per mounted block (a use-memo) and passes it on
*query-result (atom nil)
;; First render of the query block: children capture this config
first-render-config (build-config {} block {:*query-result *query-result})
;; The query block re-renders (e.g. while its query is still loading)
;; and the query component publishes its rows to the config it received
second-render-config (build-config {} block {:*query-result *query-result})]
(reset! (:query-result second-render-config) rows)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Regression test skips the mounted container

The test supplies one atom to build-config twice, bypassing the mounted container's hooks/use-memo. It cannot detect a break in the container-to-child wiring that caused the reported failure.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

…hout a per-call fallback

Its only caller, the block container, always passes the atom it keeps for the mounted block; a fresh atom per call was the behaviour that lost the result.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author
  • Fallback atom: agreed, removed in the latest commit; build-config takes the atom its only caller, the block container, keeps for the mounted block.
  • Test scope: the test pins the part that was wrong, that every render of the query block hands its children the same atom; the container's side is a single hooks/use-memo with empty deps, which holds by React's contract. Rendering the whole block container needs the full DB and renderer stack, which this unit test avoids.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined into #13871 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/query-function-rerender 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.

Query functions in Advanced Queries sometimes do not render

1 participant