Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apify-docs-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"docusaurus-gtm-plugin": "^0.0.2",
"postcss-preset-env": "^10.1.3",
"prism-react-renderer": "^2.4.1",
"react-hotkeys-hook": "^5.1.0",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"unified": "^11.0.5",
Expand Down
18 changes: 17 additions & 1 deletion apify-docs-theme/src/theme/SearchBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import RouterLink from '@docusaurus/Link';
// import { useHistory, useLocation } from '@docusaurus/router';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import clsx from 'clsx';
// import React, { useCallback } from 'react';
import React, { useEffect, useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';

// import { ApifySearch } from '@apify/docs-search-modal';
import { ControlKeyIcon, SearchIcon } from '@apify/docs-search-modal/dist/utils/icons';
Expand Down Expand Up @@ -82,6 +82,7 @@ export function Link(props) {

export default function SearchBar({ onClick }) {
const [variant, setVariant] = useState(null);
const [opened, setOpened] = useState(false);
const { siteConfig } = useDocusaurusContext();
const { inkeepApiKey } = siteConfig.customFields;

Expand All @@ -98,9 +99,18 @@ export default function SearchBar({ onClick }) {
}, []);

onClick = () => {
if (opened) {
return;
}

setOpened(true);

if (variant === 'kapa') {
if (window.Kapa && typeof window.Kapa.open === 'function') {
window.Kapa.open();
window.Kapa('onModalClose', () => {
setOpened(false);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Kapa.ai Integration Causes Search Bar Issues

The search bar component exhibits two issues related to the Kapa.ai integration:

  1. Opening the Kapa modal repeatedly registers new onModalClose event listeners, leading to multiple setOpened(false) calls and potential memory leaks when the modal closes.
  2. If the Kapa.ai widget is unavailable, the opened state is set to true but never reset to false, permanently preventing any subsequent attempts to open the search modal.
Fix in Cursor Fix in Web

} else {
console.error('Kapa.ai widget is not available.');
}
Expand Down Expand Up @@ -178,11 +188,13 @@ export default function SearchBar({ onClick }) {
},
],
},
defaultView: 'chat',
};
const modal = window.Inkeep.ModalSearchAndChat(config);

function handleOpenChange(newOpen) {
modal.update({ modalSettings: { isOpen: newOpen } });
setOpened(newOpen);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: SearchBar Prop Ignored, State Not Reset

The SearchBar component reassigns its onClick prop, effectively ignoring any onClick handler passed from parent components. Additionally, the opened state, which prevents multiple modal openings, is not reset to false if the Kapa or Inkeep search widgets fail to open. This leaves the search bar permanently unresponsive until the page is refreshed.

Fix in Cursor Fix in Web

}

modal.update({ modalSettings: { isOpen: true } });
Expand All @@ -200,6 +212,10 @@ export default function SearchBar({ onClick }) {
}
}, []);

useHotkeys('mod+k, /', () => {
onClick();
}, { preventDefault: true });

return (
<BrowserOnly>
{() => (
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.