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

Algolia search modal appears when entering a keyboard shortcut to use a browser's "Find" function #10333

Closed
6 of 7 tasks
josh-wong opened this issue Jul 23, 2024 · 8 comments · Fixed by #10342
Closed
6 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: search Related to the search feature, usually Algolia

Comments

@josh-wong
Copy link
Contributor

josh-wong commented Jul 23, 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

When using Algolia search, if a user selects an anchor link (links that show # or ) in the search modal, the modal is displayed again when the user enters a keyboard shortcut (⌘ + F on macOS; Ctrl + F on Windows) to use the browser's "Find" function. The issue doesn't occur when selecting a link to a page without an anchor (pages with the page icon).

Note

We are currently on Docusaurus 3.2.1 in production and want to upgrade to Docusaurus 3.4.0, which fixes #10162 that we had encountered. But we have halted upgrading for now because both 3.2.1 and 3.4.0 have different issues related to the Algolia search modal, which is why I don't have an environment for this. However, this issue can be reproduced on the latest version (3.4.0) of the Docusaurus docs site, as shown in the video below. (Sorry for the low-quality video; GitHub requires videos to be 10 MB or less.)

docusaurus-algolia-search-find-function-bug-480p.mov

In addition, when the user presses ⌘ + F on macOS; Ctrl + F on Windows, an f is added to the search, which causes f to appear as a keyword that has been searched for in the Algolia dashboard.

Reproducible demo

See attached video.

Steps to reproduce

  1. Select the Algolia search bar. When the modal opens, enter a search phrase.
  2. Select an anchor link (# or ) to navigate to that page.
  3. On that page, press ⌘ + F on macOS or Ctrl + F on Windows. The page will open the Algolia search modal instead of the browser's "Find" function and add an f to the search.
  4. Close the modal.
  5. Press ⌘ + F on macOS or Ctrl + F on Windows again. The page will open the browser's "Find" function as expected.

Expected behavior

After selecting an anchor link (links that show # or ) in the search modal, pressing ⌘ + F on macOS or Ctrl + F on Windows should display the browser's "Find" function instead of the Algolia modal.

Actual behavior

After selecting an anchor link (links that show # or ) in the search modal, the modal is displayed again when the user uses the browser's "Find" function (⌘ + F on macOS; Ctrl + F on Windows).

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@josh-wong josh-wong 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 Jul 23, 2024
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Jul 23, 2024

Hmmm, can reproduce. This looks like an Algolia bug since we don't maintain this component at all—I think.

@shortcuts any ideas?

@Josh-Cena Josh-Cena added external This issue is caused by an external dependency and not Docusaurus. domain: search Related to the search feature, usually Algolia labels Jul 23, 2024
@shortcuts
Copy link
Contributor

shortcuts commented Jul 23, 2024

Hey, I've managed to reproduce on the Docusaurus website indeed, but not on https://docsearch.algolia.com/docs/what-is-docsearch/ which is also running Docusaurus website (2.x.y older version) but in the latest DocSearch version. Since there was no changes made on DocSearch lately, I doubt there is a regression on our side.

I found an easier way to reproduce, but it seems like on the Docusaurus website, you don't have the visual feedback when a DocSearch key is pressed so I recommend trying on our other website which runs 3.4.0

  1. Go to any page
  2. Press any meta+key browser native shortcut e.g. cmd+f, cmd+p
  3. Escape to close the browser native window
  4. See the meta key remaining on pressed state in the search box (cf. image)
  5. Try to press any key, the modal keeps opening, the meta key is trapped in an toggled state
Screenshot 2024-07-23 at 18 56 57

@shortcuts
Copy link
Contributor

shortcuts commented Jul 23, 2024

Maybe this is related? 0ce7c13

@Josh-Cena
Copy link
Collaborator

Oh! Good find. It's likely.

@Josh-Cena Josh-Cena removed status: needs triage This issue has not been triaged by maintainers external This issue is caused by an external dependency and not Docusaurus. labels Jul 23, 2024
@slorber
Copy link
Collaborator

slorber commented Aug 2, 2024

See the meta key remaining on pressed state in the search box (cf. image)

@shortcuts is this new? I never seen that on our own website and still don't see it now even trying hard to see the search button showing the key pressed 😅

image

I found an easier way to reproduce, but it seems like on the Docusaurus website, you don't have the visual feedback when a DocSearch key is pressed so I recommend trying on our other website which runs 3.4.0

Why don't we have this visual feedback? And why do you have in on your websites?

I found an easier way to reproduce

Try to press any key, the modal keeps opening, the meta key is trapped in an toggled state

I see the meta key being stuck yes

But pressing any key does not change anything to me, I don't see the algolia modal opening, and the only way for me to reproduce involves the initial repro steps (clicking on an anchor, then ctrl+f)


Maybe this is related? 0ce7c13

Probably, but I don't see anything suspicious about this code. We don't handle the meta key state ourselves as far as I know and not mounting/remounting the dialog container shouldn't lead to such a bug IMHO.

I believe it's an Algolia issue that only appeared due to our recent change. The solution @mxschmitt provided in #10342 works, and we could merge it today to move on, but that seems more like a workaround than the ideal proper solution. Let me know if you plan to fix it, otherwise we'll merge @mxschmitt PR.

@shortcuts
Copy link
Contributor

shortcuts commented Aug 5, 2024

@shortcuts is this new? I never seen that on our own website and still don't see it now even trying hard to see the search button showing the key pressed 😅

It wasn't there when I was still working on DocSearch, so it should be at most 1 years old cc @8bittitan @levimichael

Why don't we have this visual feedback? And why do you have in on your websites?

That's a great question, I guess keypress event listeners from both sides clashing? In any case, I think it's best for you to go with the workaround in the meantime (if possible), until the DocSearch team tackles the issue

EDIT: the feature has been added in this PR

@slorber
Copy link
Collaborator

slorber commented Aug 5, 2024

Thanks @shortcuts , we'll merge the PR in the meantime then 👍

@francoischalifour
Copy link
Contributor

Reviewing the code of DocSearch's useDocSearchKeyboardEvents(), I believe the issue happens because it calls your handleInput() function on the "keydown" event. Thus, if you press Ctrlf and release Ctrl before releasing f, the search input will capture the character f.

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 domain: search Related to the search feature, usually Algolia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants