Skip to content

Global search: Indexer watches for change#406

Merged
elmarburke merged 8 commits intomainfrom
global-search/index-changes
Sep 2, 2025
Merged

Global search: Indexer watches for change#406
elmarburke merged 8 commits intomainfrom
global-search/index-changes

Conversation

@elmarburke
Copy link
Copy Markdown
Contributor

@elmarburke elmarburke commented Sep 1, 2025

Description

Watch for changes in the current root node and index them. That will allow for real time index updates while the plugin is open.

  • Adds the project name to the database name for easier identification in the development process
  • Runs the indexer for nodes and collections now in parallel
  • And as a bonus to this change: the current canvas indexes first
  • The indexer spinner is shown

Testing

  • Edit something on the canvas as you search for something in the same node: it updates automatically
  • Do the same as above, but delete the node: it's gone from the index
  • The spinner is shown for a sensible time before hiding, signalling "i've updated everything"

@elmarburke elmarburke force-pushed the global-search/index-changes branch 2 times, most recently from b7b2c47 to 5516a6e Compare September 2, 2025 11:21
@elmarburke elmarburke requested a review from Copilot September 2, 2025 11:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements real-time indexing for the global search plugin by watching for changes in the current canvas root node. The goal is to provide automatic index updates while the plugin is open, improving the user experience by keeping search results current without manual intervention.

  • Adds canvas root node change detection and automatic re-indexing
  • Implements a minimum duration hook for improved spinner UX
  • Enhances the database with better identification and incremental update capabilities

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
plugins/global-search/src/utils/useMinimumDuration.ts New React hook to ensure boolean values stay true for minimum duration
plugins/global-search/src/utils/useMinimumDuration.test.ts Comprehensive test coverage for the minimum duration hook
plugins/global-search/src/utils/indexer/indexer.ts Core indexer logic enhanced with canvas root watching and parallel processing
plugins/global-search/src/utils/indexer/IndexerProvider.tsx Provider updated to handle canvas root change events and accept project name
plugins/global-search/src/utils/db.ts Database schema updated with compound index for efficient incremental updates
plugins/global-search/src/components/SearchScene.tsx UI updated to use minimum duration hook for better spinner behavior
plugins/global-search/src/App.tsx App component updated to pass project name to IndexerProvider

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread plugins/global-search/src/utils/indexer/indexer.ts Outdated
if (this.abortRequested) break
await this.db.upsertEntries(batch)
}
this.canvasSubscription ??= framer.subscribeToCanvasRoot(rootNode => {
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

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

The canvas subscription is only created once using the nullish coalescing assignment operator (??=). If the indexer is restarted multiple times, this could lead to multiple subscriptions being active simultaneously, causing duplicate event handling. The subscription should be properly cleaned up before creating a new one.

Suggested change
this.canvasSubscription ??= framer.subscribeToCanvasRoot(rootNode => {
// Always clean up any existing canvas subscription before creating a new one
if (this.canvasSubscription) {
this.canvasSubscription();
this.canvasSubscription = null;
}
this.canvasSubscription = framer.subscribeToCanvasRoot(rootNode => {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

with the nullish coalescing assignment (what a word to type) there should only be ever one around, when it starts again, the active one is good to be re-used.

Comment thread plugins/global-search/src/utils/db.ts
@elmarburke elmarburke force-pushed the global-search/index-changes branch from 5516a6e to 17dd2f9 Compare September 2, 2025 11:29
@elmarburke elmarburke marked this pull request as ready for review September 2, 2025 11:36
@elmarburke elmarburke requested a review from niekert September 2, 2025 11:36
Copy link
Copy Markdown
Member

@niekert niekert left a comment

Choose a reason for hiding this comment

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

Nice work 👏

LGTM besides some non-blocking nice to have nits

Comment thread plugins/global-search/src/utils/db.ts
Comment thread plugins/global-search/src/utils/db.ts
Comment thread plugins/global-search/src/utils/indexer/indexer.ts Outdated
Comment thread plugins/global-search/src/utils/indexer/indexer.ts
@elmarburke elmarburke force-pushed the global-search/index-changes branch from ef94ed4 to 02a8e04 Compare September 2, 2025 14:49
@elmarburke elmarburke enabled auto-merge September 2, 2025 14:49
@elmarburke elmarburke added this pull request to the merge queue Sep 2, 2025
Merged via the queue into main with commit 6f07ce6 Sep 2, 2025
6 checks passed
@elmarburke elmarburke deleted the global-search/index-changes branch September 2, 2025 14:53
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.

3 participants