Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/generators/web/ui/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
import SearchBox from './SearchBox';
import { useTheme } from '../hooks/useTheme.mjs';

import { repository } from '#theme/config';
import { hasSearch, repository } from '#theme/config';
import Logo from '#theme/Logo';

/**
* NavBar component that displays the headings, search, etc.
*/
export default ({ metadata }) => {
const [themePreference, setThemePreference] = useTheme();
const [themePreference, setThemePreference] = useState();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Theme hook replaced incorrectly

High Severity

useTheme() was swapped for bare useState() while the useTheme import remains. useState is not imported from React, so the navbar can throw at runtime. Even with an import, theme would not load from localStorage, would not apply data-theme on the document, and ThemeToggle would get an undefined currentTheme.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 45bb9a4. Configure here.


return (
<NavBar
Logo={Logo}
sidebarItemTogglerAriaLabel="Toggle navigation menu"
navItems={[]}
>
<SearchBox pathname={metadata.path} />
{hasSearch && <SearchBox pathname={metadata.path} />}
<ThemeToggle
onChange={setThemePreference}
currentTheme={themePreference}
Expand Down
4 changes: 4 additions & 0 deletions src/generators/web/utils/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export default function createConfigSource(input) {
versions: buildVersionEntries(config.changelog, pageURL),
editURL,
pages: buildPageList(input),
// Only the `web` generator's own bundle should ever render the search
// bar; if `orama-db` wasn't also requested, there's no search index for
// it to query, so the search box would render but silently do nothing.
hasSearch: (getConfig().target ?? []).includes('orama-db'),
};

const lines = Object.entries(exports).map(
Expand Down