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
10 changes: 8 additions & 2 deletions src/generators/web/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ export default createLazyGenerator({

dependsOn: 'jsx-ast',

defaultConfiguration: {
/**
* @param {import('../../utils/configuration/types').Configuration} config
*/
defaultConfiguration: config => ({
templatePath: join(import.meta.dirname, 'template.html'),
project: 'Node.js',
title: '{project} {version} Documentation',
useAbsoluteURLs: false,
editURL: `${GITHUB_EDIT_URL}/doc/api{path}.md`,
pageURL: '{baseURL}/latest-{version}/api{path}.html',
remoteConfigUrl: 'https://nodejs.org/site.json',
// By default, the search box is only shown when we are _also_ building search data
showSearchBox:
Array.isArray(config.target) && config.target.includes('orama-db'),

// Project-specific document `<head>` contents. `meta` and `links` are
// arrays of attribute bags (boolean `true` renders a valueless attribute,
Expand Down Expand Up @@ -97,5 +103,5 @@ export default createLazyGenerator({
// Options merged into the Rolldown build (client and server), e.g. extra
// `plugins`. See the README for the merge semantics.
rolldown: {},
},
}),
});
4 changes: 2 additions & 2 deletions src/generators/web/ui/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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 { repository, showSearchBox } from '#theme/config';
import Logo from '#theme/Logo';

/**
Expand All @@ -21,7 +21,7 @@ export default ({ metadata }) => {
sidebarItemTogglerAriaLabel="Toggle navigation menu"
navItems={[]}
>
<SearchBox pathname={metadata.path} />
{showSearchBox && <SearchBox pathname={metadata.path} />}
<ThemeToggle
onChange={setThemePreference}
currentTheme={themePreference}
Expand Down
12 changes: 9 additions & 3 deletions src/utils/configuration/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ import { deepMerge, lazy } from '../misc.mjs';
/**
* Get's the default configuration
*/
export const getDefaultConfig = lazy(() =>
export const getDefaultConfig = lazy(config =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lazy cache ignores config argument

Medium Severity

getDefaultConfig is still wrapped in lazy, which memoizes the first call and ignores later arguments. After making defaults depend on config, a second createRunConfiguration in the same process reuses the first config's dynamic values (for example showSearchBox) instead of recomputing them.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 288d7d9. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. createRunConfiguration is only called once per thread, most of the time
  2. config doesn't change

Object.keys(allGenerators).reduce(
(acc, k) => {
acc[k] = allGenerators[k].defaultConfiguration ?? {};
acc[k] =
'defaultConfiguration' in allGenerators[k]
? typeof allGenerators[k].defaultConfiguration === 'function'
? allGenerators[k].defaultConfiguration(config)
: allGenerators[k].defaultConfiguration
: {};

return acc;
},
/** @type {import('./types').Configuration} */ ({
Expand Down Expand Up @@ -138,7 +144,7 @@ export const createRunConfiguration = async options => {
const merged = deepMerge(
config,
createConfigFromCLIOptions(options),
getDefaultConfig()
getDefaultConfig(config)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CLI targets ignored for defaults

Medium Severity

Dynamic defaults such as showSearchBox are computed from the config-file object alone, before CLI options are merged. When target comes from --target (the project's usual path), orama-db is never visible to defaultConfiguration, so the search box stays hidden even when search data is being built.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 288d7d9. Configure here.

);

// These need to be coerced
Expand Down
Loading