Skip to content

Reactively add externally-created nodes to an open QueryNodeViewer - #2019

Merged
mstomar125 merged 2 commits into
mainfrom
issue-1996-queryviewer-reactive
Aug 10, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-1996-queryviewer-reactive

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

An open type/query view (QueryNodeViewer) loaded its results once and never listened for new nodes, so a node created via the CLI, an agent tool call, or another tab/window didn't appear until the view was remounted (tab switch). Closes #1996.

Change

The daemon's node:created event is already hydrated into sharedNodeStore by tauri-sync-listener (which drops non-active-database events). The viewer now subscribes (sharedNodeStore.subscribeAll) on mount and appends nodes that belong to the current view, unsubscribing on teardown.

The decision is a pure, exported helper — shouldShowCreatedNode(node, gate) in query-node-model.ts — so the subscription handler stays a one-liner and the logic is unit-testable. A node is folded in only when:

  • the view has settled (queryState === 'success') — this guards against O(n²) self-appends during the view's own load (whose setNode loop fires the subscription) and against injecting into a view mid-switch (the fresh query reconciles it);
  • it isn't already shown (dedup; also covers the view's own "+New");
  • its type matches the view (targetType, or '*' for an all-types saved query);
  • it passes the query's client-side filters (a default type view has none).

Works for all three view modes (List/Table/Kanban) since they render from the same loadedNodeIds.

Tests

+7 unit tests for shouldShowCreatedNode in query-node-model.test.ts (settled+matching → integrate; wrong type; already-shown; still-loading; no targetType; '*' all-types; and filter pass/fail). Follows the project pattern of testing extracted logic directly rather than rendering the component. Full frontend suite green (192 files / 4459 tests); eslint + svelte-check clean; pre-push gate passed.

Non-goals honored

node:updated/node:deleted row reactivity (already via sharedNodeStore row lookups) and the "+New" self-append are unchanged.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits August 10, 2026 12:20
An open type/query view loaded its results once and never listened for new
nodes, so a node created via the CLI, an agent tool call, or another tab/window
didn't appear until the view was remounted (tab switch).

Subscribe the viewer to sharedNodeStore (which tauri-sync-listener already
hydrates from the daemon's node:created event, dropping non-active-database
events) and append nodes that belong to the current view. The decision is a pure
shouldShowCreatedNode() helper: only once the view has settled (guards against
O(n^2) self-appends during the view's own load and against injecting into a view
mid-switch), not already shown, type matches the view ('*' = all-types saved
query), and the node passes the query's client-side filters. Works for all three
view modes since they render from the same loadedNodeIds.

Closes #1996.

Co-Authored-By: Claude <[email protected]>
setNode now fires the new wildcard subscription synchronously, so in a default
type view the just-created node is already appended to loadedNodeIds by the
subscription before handleCreateInstance's own append runs — producing a
duplicate id and crashing the keyed #each in all three views. Guard the +New
append with !loadedNodeIds.includes(). A saved query whose filters the new node
fails is not appended by the (filter-aware) subscription, so this append still
shows it, as before.

Severity: 🔴 addressed. Reviewer: pragmatic-code-review on PR #2019.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review + /address-review

Independent review verdict was REQUEST CHANGES on one blocking issue; addressed:

🔴 +New duplicate row → keyed-#each crash (default type view). Real bug — handleCreateInstance calls setNode(created), which now fires the wildcard subscription synchronously and appends created.id; the handler's own append then duplicated it. Fixed: guarded the +New append with !loadedNodeIds.includes(created.id). Both append sites (the subscription and +New) are now idempotent, so a duplicate is structurally impossible. The +New append stays filter-agnostic: a saved query whose filters the new node fails isn't appended by the filter-aware subscription, so this append still shows it — unchanged behavior.

🟢 confirmed sound by the review: the load-time O(n²)/self-append guard (queryState==='success' blocks appends during the setNode loop, which runs while 'loading'); staleness (tauri-sync-listener's isActiveDatabaseEvent filter + viewer unmount-on-DB-switch tears down the subscription before new-DB hydration + reload resets to 'loading'); subscription lifecycle (unsubscribe returned from onMount); filter correctness.

🟡 non-blocking, evaluated & kept: the wildcard also fires on node:updated (add-only — a node edited to newly match appears, never removed). This is the node:updated reactivity the issue lists as a non-goal; adding a now-matching node is reasonable, and removal-on-stops-matching is out of scope. Left as-is.

Test note: the 🔴 was a component-interaction bug the pure-function tests couldn't reach. A full QueryNodeViewer render harness doesn't exist and building one for this single interaction is disproportionate (heavy deps; this suite has demonstrated fork-ordering fragility — see #2020). The fix is a structural idempotency guarantee at both append sites; full frontend suite green (192 files / 4459 tests), eslint + svelte-check clean.

Re-Review Decision: RE-REVIEW NEEDED — a behavior fix to the +New path. Running /pragmatic-code-review on the new commit once the gate passes.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review — Re-Review (delta 15099200..ce97792d)

🔴 duplicate-id crash — RESOLVED. Traced the chain: setNode → notifySubscribers iterates wildcard subs in a synchronous loop, so the subscription's append runs to completion before the guarded +New append reads loadedNodeIds — the guard sees the id present and skips. Default view → shown once. Filtered saved query where the node fails filters → subscription doesn't append, so the filter-agnostic +New append still shows it (preserved). No path leaves the node in neither. No regression to the previously-🟢 items.

Verdict: APPROVE.

Re-Review Decision: NO RE-REVIEW NEEDED — minimal, verified fix.

@mstomar125
mstomar125 merged commit e42a527 into main Aug 10, 2026
@mstomar125
mstomar125 deleted the issue-1996-queryviewer-reactive branch August 10, 2026 10:47
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.

QueryNodeViewer doesn't reactively add externally-created nodes matching its query

1 participant