Skip to content

Conversation

@dylantientcheu
Copy link
Contributor

@dylantientcheu dylantientcheu commented Jan 5, 2026

Summary

  • Exposes an imperative instance API for @docsearch/js and @docsearch/sidepanel-js (open/close/destroy, plus state getters).
  • Adds lifecycle callbacks (ready/open/close) for both modal and sidepanel.
  • Wires this through @docsearch/core / @docsearch/react via forwarded refs + useImperativeHandle.

Motivation

Integrations (e.g. VitePress) currently resort to DOM polling to know when DocSearch/Sidepanel are ready and to open them programmatically. This adds a first-class programmatic API.

API changes

@docsearch/js

  • docsearch(...) now returns a DocSearchInstance with:
    • open(), close(), openAskAi(), openSidepanel(), destroy()
    • isReady, isOpen, isSidepanelOpen
  • New callbacks: onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose

@docsearch/sidepanel-js

  • sidepanel(...) now returns a SidepanelInstance with:
    • open(), close(), openWithMessage(), destroy()
    • isReady, isOpen
  • New callbacks: onReady, onOpen, onClose

BREAKING CHANGE

Yes: docsearch() and sidepanel() no longer return a bare cleanup function.

Migration:

// Before
const cleanup = docsearch(opts)
cleanup()

// After
const instance = docsearch(opts)
instance.destroy()

Tests

  • Added unit coverage for the new imperative handle + lifecycle callbacks (packages/docsearch-react/src/__tests__/imperative.test.tsx).

@netlify
Copy link

netlify bot commented Jan 5, 2026

Deploy Preview for docsearch-demo failed.

Name Link
🔨 Latest commit 04b054b
🔍 Latest deploy log https://app.netlify.com/projects/docsearch-demo/deploys/695fdeda3216520008e272e1

@netlify
Copy link

netlify bot commented Jan 5, 2026

Deploy Preview for docsearch ready!

Name Link
🔨 Latest commit 04b054b
🔍 Latest deploy log https://app.netlify.com/projects/docsearch/deploys/695fdeda98cf180008bd2430
😎 Deploy Preview https://deploy-preview-2826--docsearch.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dylantientcheu dylantientcheu removed the request for review from shortcuts January 5, 2026 15:04
@dylantientcheu dylantientcheu changed the title feat(js): expose instance API + lifecycle callbacks feat(js)!: expose instance API + lifecycle callbacks Jan 5, 2026
@dylantientcheu dylantientcheu self-assigned this Jan 5, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68a2151dd2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- openSidepanel() now no-ops if sidepanel view hasn't been registered
- Added isSidepanelSupported getter to check before calling
- Prevents stuck state when calling openSidepanel() on modal-only instance
@8bittitan
Copy link
Contributor

8bittitan commented Jan 6, 2026

Could we add an example of this to examples/demo-js?

@dylantientcheu dylantientcheu merged commit 283ff35 into main Jan 8, 2026
10 of 11 checks passed
@dylantientcheu dylantientcheu deleted the feat/instance-api branch January 8, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants