docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Pass custom transformSearchClient to a swizzled but Wrapped SearchBar

Open hugohaggmark opened this issue 1 month ago • 0 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [x] I'm using the latest version of Docusaurus.
  • [x] I have tried the npm run clear or yarn clear command.
  • [x] I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • [x] I have tried creating a repro with https://new.docusaurus.io.
  • [ ] I have read the console error message carefully (if applicable).

Description

I'm trying to add custom search tracking to the SearchBar by extending the transformSearchClient function in docusaurus.config.ts but according to https://docusaurus.io/docs/advanced/architecture only serializable values are passed along. So that leaves me with the option to swizzle @docusaurus/theme-search-algolia.

I've swizzled @docusaurus/theme-search-algolia with the command npm run swizzle @docusaurus/theme-search-algolia and then I choose to Wrap the component. Unfortunately there is no way to pass transformSearchClient because this https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx#L315 doesn't pass props to the DocSearch component.

I think it should be possible to pass a custom transformSearchClient to a wrapped SearchBar component because that would allow for fewer breaking changes moving forward.

Reproducible demo

https://stackblitz.com/edit/github-pyvgb77t?file=src%2Ftheme%2FSearchBar%2Findex.tsx

Steps to reproduce

  1. add algolia search config
  2. swizzle @docusaurus/theme-search-algolia and choose to Wrap the component

Expected behavior

Be able to pass transformSearchClient as props to SearchBar

Actual behavior

Passed props are ignored

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • [x] I'd be willing to fix this bug myself.

hugohaggmark avatar Nov 28 '25 09:11 hugohaggmark