Skip to content

Commit

Permalink
perf(theme-default): reduce unnecessary lodash methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Nov 20, 2024
1 parent c35dc2c commit c3994e9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
3 changes: 0 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"@rspress/runtime": "workspace:*",
"@rspress/shared": "workspace:*",
"@rspress/theme-default": "workspace:*",
"copy-to-clipboard": "^3.3.3",
"enhanced-resolve": "5.17.1",
"github-slugger": "^2.0.0",
"hast-util-from-html": "^2.0.3",
Expand All @@ -64,7 +63,6 @@
"lodash-es": "^4.17.21",
"mdast-util-mdxjs-esm": "^1.3.1",
"node-fetch": "3.3.2",
"nprogress": "^0.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-helmet-async": "^1.3.0",
Expand All @@ -87,7 +85,6 @@
"@types/lodash-es": "^4.17.12",
"@types/mdast": "^4.0.4",
"@types/node": "^18.11.17",
"@types/nprogress": "^0.2.3",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"postcss": "8.4.49",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/node/mdx/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export function createCheckPageMetaUpdateFn() {

if (prevMeta !== deserializedMeta) {
setTimeout(async () => {
logger.info(
'⭐️ Page metadata changed, rspress will trigger page reload...',
);
logger.info('Page metadata changed, page reloading...');
await updateSiteDataRuntimeModule(modulePath, pageMeta);
});
}
Expand Down
17 changes: 14 additions & 3 deletions packages/theme-default/src/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-lines */
import { usePageData } from '@rspress/runtime';
import { type SearchOptions, isProduction } from '@rspress/shared';
import { debounce, groupBy } from 'lodash-es';
import { debounce } from 'lodash-es';
import { useCallback, useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import * as userSearchHooks from 'virtual-search-hooks';
Expand Down Expand Up @@ -310,8 +310,19 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {

const handleQueryChange = useDebounce(handleQueryChangedImpl);

const normalizeSuggestions = (suggestions: DefaultMatchResult['result']) =>
groupBy(suggestions, 'group');
const normalizeSuggestions = (suggestions: DefaultMatchResult['result']) => {
return suggestions.reduce(
(groups, item) => {
const group = item.group;
if (!groups[group]) {
groups[group] = [];
}
groups[group].push(item);
return groups;
},
{} as Record<string, DefaultMatchResult['result']>,
);
};

const renderSearchResult = (
result: MatchResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import SunSvg from '@theme-assets/sun';
import MoonSvg from '@theme-assets/moon';
import { SvgWrapper } from '../SvgWrapper';
import siteData from 'virtual-site-data';
import { isUndefined } from 'lodash-es';
import { flushSync } from 'react-dom';
import './index.scss';

const supportAppearanceTransition = () => {
return (
!isUndefined(document) &&
document.startViewTransition &&
document?.startViewTransition &&
!window.matchMedia('(prefers-reduced-motion: reduce)').matches
);
};
Expand Down
3 changes: 1 addition & 2 deletions packages/theme-default/src/logic/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isEqualPath } from '@rspress/runtime';
import htmr from 'htmr';
import { isNumber } from 'lodash-es';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import React from 'react';

Expand Down Expand Up @@ -33,7 +32,7 @@ export function renderHtmlOrText(str?: string | number | null) {
return '';
}

if (isNumber(str)) {
if (typeof str === 'number') {
return str;
}

Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

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

0 comments on commit c3994e9

Please sign in to comment.