Skip to content

Pass custom transformSearchClient to a swizzled but Wrapped SearchBar #11580

@hugohaggmark

Description

@hugohaggmark

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionstatus: needs triageThis issue has not been triaged by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions