Skip to content

warm search indexes on search intent#8903

Open
CodingRule wants to merge 8 commits into
nodejs:mainfrom
CodingRule:main
Open

warm search indexes on search intent#8903
CodingRule wants to merge 8 commits into
nodejs:mainfrom
CodingRule:main

Conversation

@CodingRule
Copy link
Copy Markdown
Contributor

Description

  • warm the Orama search indexes before the first query runs
  • trigger warm-up when the user shows search intent through hover, focus, pointer down, or Ctrl/Cmd+K
  • reuse one cached warm-up promise so the search data is not loaded more than once
  • add unit tests for the cached warm-up path and the modal warm-up triggers

Validation

  • the first search interaction should feel faster because index loading now starts before the first typed query

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

Signed-off-by: Elure <ioumih32@gmail.com>
Signed-off-by: Elure <ioumih32@gmail.com>
Signed-off-by: Elure <ioumih32@gmail.com>
Signed-off-by: Elure <ioumih32@gmail.com>
Signed-off-by: Elure <ioumih32@gmail.com>
Signed-off-by: Elure <ioumih32@gmail.com>
Signed-off-by: Elure <ioumih32@gmail.com>
Copilot AI review requested due to automatic review settings May 18, 2026 12:03
@CodingRule CodingRule requested a review from a team as a code owner May 18, 2026 12:03
@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodejs-org Ready Ready Preview May 18, 2026 0:23am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 18, 2026

PR Summary

Medium Risk
Changes search index loading timing and adds global/event-driven warmup triggers, which could affect search responsiveness and introduce unexpected network/activity before the modal opens.

Overview
Preloads Orama search indexes earlier by introducing a cached warmup() path and ensuring index fetch/insert runs only once before the first search() call.

Propagates an optional onWarmup callback through SearchBox/SearchModal and triggers it on search intent (hover/focus/pointer down and Ctrl/Cmd+K), with error-safe handling.

Adds unit tests covering URL prefixing, single-flight warmup behavior, and the new modal warmup triggers.

Reviewed by Cursor Bugbot for commit c2080fa. Bugbot is set up for automated code reviews on this repo. Configure here.

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 improves perceived search responsiveness by preloading (warming) the Orama search indexes when the user shows “search intent” (hover/focus/pointerdown or Ctrl/Cmd+K) and by reusing a single cached warm-up promise so index data is only loaded once.

Changes:

  • Add onWarmup plumbing through SearchBoxSearchModal and trigger warm-up from intent events + global Ctrl/Cmd+K.
  • Refactor Orama setup into createOramaClient() that exposes both { client, warmup }, caching the warm-up promise.
  • Add unit tests covering warm-up triggers and the “warm only once” cached warm-up path.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/ui-components/src/Common/Search/Modal/index.tsx Adds warm-up triggers (hover/focus/pointerdown + global shortcut) via new onWarmup prop.
packages/ui-components/src/Common/Search/Modal/tests/index.test.jsx Adds tests ensuring warm-up is triggered by intent events and keyboard shortcut.
packages/ui-components/src/Common/Search/index.tsx Wires new onWarmup prop from SearchBox into SearchModal.
apps/site/components/withSearch.tsx Introduces createOramaClient() with cached warmup() and passes warm-up into SearchBox.
apps/site/components/tests/withSearch.test.jsx Adds tests for URL prefixing and ensuring warm-up executes only once.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ui-components/src/Common/Search/Modal/index.tsx Outdated
Comment on lines +45 to +65
global.fetch = mock.fn(async url => ({
json: async () => ({
docs: {
docs: {
[String(url)]: { href: '/result', title: 'Node.js' },
},
},
}),
}));

const { client, warmup } = createOramaClient({
'/docs': 'https://example.com/docs.json',
'/learn': 'https://example.com/learn.json',
});

await Promise.all([warmup(), warmup()]);
await client.search({ term: 'node' });

assert.equal(global.fetch.mock.callCount(), 2);
assert.equal(insertMultipleMock.mock.callCount(), 2);
assert.equal(searchMock.mock.callCount(), 1);
Copy link
Copy Markdown
Member

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

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

Why is this needed? What real difference does this make?

@CodingRule
Copy link
Copy Markdown
Contributor Author

I believe search should feel more responsive, so this change starts loading the Orama indexes as soon as the user shows search intent. It makes the first search feel faster on slower networks.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Elure <ioumih32@gmail.com>
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