Skip to content

Replace autocomplete and slash command effects with event-driven updates #626

Closed

Description

@malibio

Overview

Replace $effect blocks that watch state to update autocomplete/slash command results with direct function calls from the event handlers that change that state.

Problem Statement

Current implementation uses effects to react to state changes:

// Lines 267-277: Effect watches showAutocomplete and currentQuery
$effect(() => {
  if (showAutocomplete && nodeReferenceService) {
    if (services?.nodeManager) {
      performRealSearch(currentQuery);
    } else {
      autocompleteResults = generateMockResultsForTests(currentQuery);
    }
  }
});

// Lines 360-364: Effect watches showSlashCommands and currentSlashQuery  
$effect(() => {
  if (showSlashCommands) {
    slashCommands = slashCommandService.filterCommands(currentSlashQuery);
  }
});

This is the "effect as event handler" anti-pattern. When the user types, we should call the search function directly - not set state and watch for it to change.

Proposed Solution

Move the search/filter logic to the event handlers that trigger the state changes:

// In triggerDetected handler (or wherever currentQuery is set)
function handleTriggerDetected(data) {
  currentQuery = data.triggerContext.query;
  autocompletePosition = data.cursorPosition;
  showAutocomplete = true;
  
  // Direct call instead of effect
  updateAutocompleteResults(currentQuery);
}

function updateAutocompleteResults(query: string) {
  if (services?.nodeManager) {
    performRealSearch(query);
  } else {
    autocompleteResults = generateMockResultsForTests(query);
  }
}

Acceptance Criteria

  • Autocomplete search triggered directly from event handlers
  • Slash command filtering triggered directly from event handlers
  • Two $effect blocks eliminated from base-node.svelte
  • Autocomplete works identically (results appear, update on typing)
  • Slash commands work identically
  • Code passes bun run quality:fix
  • Tests pass (bun run test:all)

Technical Specifications

Files to Modify

  • base-node.svelte: packages/desktop-app/src/lib/design/components/base-node.svelte - Lines 267-277, 360-364

Events That Trigger State Changes

  1. triggerDetected - Sets currentQuery, showAutocomplete
  2. Keyboard input while autocomplete open - Updates currentQuery
  3. slashCommandDetected - Sets currentSlashQuery, showSlashCommands
  4. Keyboard input while slash commands open - Updates currentSlashQuery

Migration Steps

  1. Identify all places where currentQuery is set
  2. Add direct updateAutocompleteResults() call after each
  3. Identify all places where currentSlashQuery is set
  4. Add direct filterSlashCommands() call after each
  5. Remove the two $effect blocks

Testing Requirements

  • Type @ and verify autocomplete appears with results
  • Continue typing and verify results filter
  • Type / and verify slash commands appear
  • Continue typing and verify commands filter
  • Select items and verify they work

Related Issues

Activity

  1. self-assigned this
    on Nov 30, 2025
  2. malibio commented on Nov 30, 2025

    @malibio
    CollaboratorAuthor

    Test baseline: Frontend 1469 passed (74 files), Rust 531 passed (16 ignored)

  3. malibio commented on Nov 30, 2025

    @malibio
    CollaboratorAuthor

    This issue is already complete in the current codebase. Analysis:

    • Lines 269-274: Comment states 'REMOVED: Autocomplete effect now handled directly by triggerDetected event handler'
    • Line 344: Comment states 'REMOVED: Slash command effect now handled directly by slashCommandDetected event handler'
    • Lines 613-635: triggerDetected handler directly calls performRealSearch() or generateMockResultsForTests()
    • Lines 652-667: slashCommandDetected handler directly calls slashCommandService.filterCommands()
    • Only one $effect remains (line 742) for element initialization, not autocomplete/slash commands

    All acceptance criteria are met:

    • ✅ Autocomplete search triggered directly from event handlers
    • ✅ Slash command filtering triggered directly from event handlers
    • ✅ Two $effect blocks eliminated from base-node.svelte
    • ✅ Tests pass (1469 passed)
  4. malibio commented on Nov 30, 2025

    @malibio
    CollaboratorAuthor

    Closing as already complete - all acceptance criteria met in current codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions