Skip to content

Slash command / node-type conversion throws state_unsafe_mutation — node disappears, Task creation fails in UI, app goes unresponsive #1578

Closed

Description

@malibio

Summary

Typing / in a node (or otherwise converting/creating a node type — e.g. creating a Task) throws a Svelte state_unsafe_mutation error, which wedges the reactivity flush. The edited node visually disappears, node-type creation fails in the UI, and the app becomes sluggish/unresponsive to further interaction.

This is the /-disappears symptom originally reported as step 1 of #1564. That issue bundled four symptoms; the fix that closed it (314b709f, PR #1565) addressed only the date-navigation symptoms (atomic tab-title/content write + stale-hydration guard) and did not touch the slash / node-type-conversion path. So this symptom was closed but never actually fixed.

Environment

Reproduces in both the Tauri webview (bun run dev:tauri) and browser/proxy mode (bun run dev:browser) — it is shared frontend code, not environment-specific.

Root cause (diagnosed)

The daemon and data layer are not at fault. Verified directly:

  • nodespace schema list → 25ms; node get → 9ms.
  • nodespace node create --type task --content "…" --parent <date> → 91ms, succeeds, node persisted with correct {"task":{"status":"open"}} properties.

So task creation works end-to-end at the daemon; the failure is purely in the frontend render path. The perceived "slow daemon communication" is actually the state_unsafe_mutation breaking the Svelte flush, not backend latency.

The offending path is in packages/desktop-app/src/lib/design/components/base-node-viewer.svelte, in the inline on:slashCommandSelected and on:nodeTypeChanged handlers (they appear twice — the lazy-loaded-component branch and the fallback BaseNode branch). Two synchronous reactive-state writes run during what becomes a render flush:

  1. focusManager.focusNodeFromTypeConversion(node.id, …) — called synchronously at the top of every handler (lines ~1519, ~1548, ~1744, ~1802). It writes three $state fields in focus-manager.svelte.ts (_editingNodeId, _editingPaneId, _cursorPosition — declared $state at lines 66/70/73).

  2. Non-placeholder branch: sharedNodeStore.updateNode(node.id, updatePayload, …) — called synchronously (lines ~1624, ~1878). When node.id is no longer in the store (e.g. a placeholder just promoted / superseded), this logs the observed warning Cannot update non-existent node: <id> (shared-node-store.svelte.ts:1036).

Why it's inconsistent (the tell)

The placeholder-promotion branch already guards against exactly this: it defers its store + focus mutations to tick().then(...) with the comment "CRITICAL FIX (#681): Defer store mutations to next tick … If called during template render, Svelte throws state_unsafe_mutation" (lines ~1478/1480 and ~1591, and mirrored ~1703/1705, ~1845). But the top-level focus write and the non-placeholder updateNode were left un-deferred. So the fix pattern exists in the file — it just wasn't applied to these two call sites.

Component stack from the thrown error (confirms origin under the date viewer, not authored in date-node-viewer.svelte itself, whose own $deriveds are pure):

in <unknown>
in date-node-viewer.svelte
in pane-content.svelte
in tab-system.svelte
in pane-manager.svelte
…

Steps to reproduce

  1. Open a date page (Daily Journal).
  2. In the empty/active node, type some text then / — the slash palette opens, but the node disappears and the console throws state_unsafe_mutation (+ often Cannot update non-existent node: <id>).
  3. Or: type /task and select Task — the conversion fails to render and the app goes sluggish.

Expected

Typing / opens the slash palette without the node disappearing; selecting a type (Task, etc.) converts/creates the node and keeps focus, with no state_unsafe_mutation and no Cannot update non-existent node warning.

Proposed fix

Apply the same tick() deferral the placeholder branch uses to the two un-deferred reactive-state writes on the slash / type-conversion path — the top-level focusManager.focusNodeFromTypeConversion(...) and the non-placeholder sharedNodeStore.updateNode(...) — so no reactive $state is written synchronously during the render flush triggered by the keystroke. Also verify the non-placeholder updateNode is not firing against an already-promoted/removed node.id (guard or resolve the current id), which is the source of the Cannot update non-existent node warning. Confirm the fix aligns with the ADR-049 rule (reactive state written from event handlers / store methods, never inside a render/derived path).

Acceptance criteria

  • Typing / in a node no longer makes the node disappear; slash palette opens normally.
  • Creating/converting to Task (and other types) via / works in the UI and keeps cursor/focus.
  • No state_unsafe_mutation error on the slash / node-type-conversion path.
  • No Cannot update non-existent node warning during slash-command node creation.
  • App remains responsive after these interactions (no flush wedge).
  • Verified in both dev:tauri and dev:browser.

Activity

  1. added
    bug
    on Jul 7, 2026
  2. malibio commented on Jul 7, 2026

    @malibio
    CollaboratorAuthor

    Split out from #1564. That issue's step-1 symptom (/ makes the node disappear) was closed alongside the date-navigation fix (314b709f, #1565), but that fix only covered the date-nav symptoms — it did not touch the slash / node-type-conversion path, so this symptom survived. Diagnosed this session: daemon + data layer verified healthy via CLI (task node creates in 91ms and persists correctly); the failure is purely the frontend state_unsafe_mutation wedging the Svelte flush.

  3. malibio commented on Jul 7, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 150 test files passed, 3944 tests passed.

  4. self-assigned this
    on Jul 7, 2026
  5. added a commit that references this issue on Jul 7, 2026
    149508f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfrontendhigh-priorityui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions