Repository navigation
fix(query): a {{function}} child keeps its parent query's result after a re-render - #13879
yuxi-liu-wired wants to merge 2 commits into
Conversation
…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
| ;; 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))) |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| 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) |
There was a problem hiding this comment.
…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.
|
|
Combined into #13871 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there. |
Fixes #12949.
Each render of a block made a new
:query-resultatom when its config had none (build-configincomponents/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 tobuild-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.