Repository navigation
Add clientOptionsModule option to DocSearch plugin - #2822
Conversation
🦋 Changeset detectedLatest commit: cd7af21 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
HiDeoo
left a comment
There was a problem hiding this comment.
Not a complete review or request for some changes, but I left a few comments mostly regarding the JSDoc to start some discussion around the approach.
One other question coming to mind is if we should expose a defineDocSearchConfig helper just for the typings or something similar?
| */ | ||
| searchParameters: z.custom<SearchOptions>(), | ||
| /** | ||
| * A JavaScript module containing a default export. These options |
There was a problem hiding this comment.
I think this should specify what the default export should be.
delucis
left a comment
There was a problem hiding this comment.
Looking good @KianNH! Seconding @HiDeoo’s idea to make the option module all-or-nothing, so if you use that, you move all config there, unless there’s a reason not to do that anyone can see.
I also agree we should export something to help with typing the options module. Given this module will end up in client-side code, I might suggest just a type rather than a defineClientOptions() utility just to avoid the extra no-op function in the bundle. (Would also allow us to export it directly from @astrojs/starlight-docsearch rather than needing a dedicated file just for that.) That would help us assert that e.g. you shouldn’t set the container property which Starlight takes care of.
So something like:
import type docsearch from '@docsearch/js';
export type DocSearchClientOptions = Omit<Parameters<typeof docsearch>[0], 'container'>;And then users can write config as:
import type { DocSearchClientOptions } from '@astrojs/starlight-docsearch';
export default {
// ...
} satisfies DocSearchClientOptions;
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
Co-Authored-By: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>

Description
clientOptionsModuleoption to thestarlightDocSearchplugin.starlight/docsearch-configvirtual module.appId, the option in theclientOptionsModulefile will be used.Considerations
starlight/docs/src/content/docs/guides/site-search.mdx
Lines 111 to 118 in 66a4131
Whilst this is probably not a large enough package to warrant it, I did setup try out setting up Vitest for this package where
vitePluginDocSearchis passed invitest.config.tsbut since it would need a lot of work to setup a harness to teststarlightDocSearchI opted against including it.