Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMissingResultsUrl not supported by algolia options in docusaurus config #10737

Open
6 of 7 tasks
jharrell opened this issue Dec 2, 2024 · 3 comments
Open
6 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: wontfix A fix will bring significant overhead, or is out of scope (for feature requests)

Comments

@jharrell
Copy link

jharrell commented Dec 2, 2024

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

Hello there!

I'm trying to add a message at the bottom of Algolia search results that prompts the user to open a GitHub issue if no results are found. The Docusaurus documentation pointed me to the Algolia DocSearch documentation which references a getMissingResultsUrl option. That option isn't available on the algolia config type but I tried anyway as I thought it might still work.

Unfortunately, it doesn't. So I'm guessing the search component used inside Docusaurus doesn't take this option into account.

Reproducible demo

https://stackblitz.com/edit/github-kv4zyn?file=docusaurus.config.ts

Steps to reproduce

  1. Update algolia.appId and algolia.apiKey with valid values
  2. Use the search functionality to find something that doesn't exist (I use thisissomethingthatdoesntexist)
  3. See that a "missing results" blurb is not present (as seen here)

Expected behavior

The "missing results" blurb should be visible and editable.

Actual behavior

There is no "missing results" sentence, nor does one appear if the getMissingResultsUrl option is set.

Your environment

No response

Self-service

  • I'd be willing to fix this bug myself.
@jharrell jharrell added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Dec 2, 2024
@jharrell jharrell changed the title not supported by algolia options in docusaurus config getMissingResultsUrl not supported by algolia options in docusaurus config Dec 2, 2024
@slorber
Copy link
Collaborator

slorber commented Dec 30, 2024

Unfortunately it doesn't work and there's no easy way to support this.

The config file runs in Node.js, while the getMissingResultsUrl is a callback that runs in the browser. It's not really possible to "serialize" a callback from the config file to the browser app. We can only forward to the React DocSearch component what can be serialized.

If you want to use getMissingResultsUrl(), the only way to achieve that would be to swizzle the React @theme/SearchBar component and override our own logic to write your own client-side getMissingResultsUrl prop. Unfortunately, this component is quite messy and makes you copy a lot of our code to achieve a tiny change. I plan to refactor that in the future.

@slorber slorber added closed: wontfix A fix will bring significant overhead, or is out of scope (for feature requests) and removed status: needs triage This issue has not been triaged by maintainers labels Dec 30, 2024
@slorber
Copy link
Collaborator

slorber commented Dec 30, 2024

BTW @jharrell you already swizzled it, so you can add a getMissingResultsUrl prop here:

https://github.com/prisma/docs/blob/main/src/theme/SearchBar/index.tsx#L214

@slorber
Copy link
Collaborator

slorber commented Dec 30, 2024

BTW curious @jharrell, you are using v3.6 but didn't turn Docusaurus Faster on, is there any reason why?

https://docusaurus.io/blog/releases/3.6#docusaurus-faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: wontfix A fix will bring significant overhead, or is out of scope (for feature requests)
Projects
None yet
Development

No branches or pull requests

2 participants