Skip to content

Commit 28b690e

Browse files
authored
fix disappearing home sections on som navigation paths and theme change (#2120)
1 parent c5750f3 commit 28b690e

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

pages/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cloneDeep } from 'es-toolkit/object';
12
import { type NextPageContext } from 'next';
23

34
import HomeScene from '~/scenes/HomeScene';
@@ -7,7 +8,7 @@ import getApiUrl from '~/util/getApiUrl';
78
import urlWithQuery from '~/util/urlWithQuery';
89

910
function Index(props: HomePageProps) {
10-
return <HomeScene {...props} />;
11+
return <HomeScene {...cloneDeep(props)} />;
1112
}
1213

1314
const LIMIT = 8;
@@ -56,7 +57,7 @@ Index.getInitialProps = async (ctx: NextPageContext) => {
5657
);
5758

5859
const statisticResponse = await fetch(
59-
getApiUrl(urlWithQuery('/libraries/statistic', {}), ctx),
60+
getApiUrl(urlWithQuery('/libraries/statistic'), ctx),
6061
NEXT_1H_CACHE_HEADER
6162
);
6263

scenes/TrendingScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function TrendingScene({ data, query }: TrendingPageProps) {
2828
const total = data && data.total;
2929

3030
function handleClearAllPress() {
31-
void router.replace(urlWithQuery('/trending', {}));
31+
void router.replace(urlWithQuery('/trending'));
3232
}
3333

3434
return (
@@ -76,7 +76,7 @@ export default function TrendingScene({ data, query }: TrendingPageProps) {
7676
<P style={tw`p-6 text-sm text-secondary`}>
7777
Unfortunately that&apos;s all, what&apos;s trending now. Want to explore more libraries?
7878
Check out the{' '}
79-
<A href={urlWithQuery('/packages', {})} target="_self">
79+
<A href={urlWithQuery('/packages')} target="_self">
8080
directory home page
8181
</A>
8282
.

util/urlWithQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function toQueryString(query: Query) {
44
return new URLSearchParams(query as Record<string, string>).toString();
55
}
66

7-
export default function urlWithQuery(url: string, query: Partial<Query>): string {
7+
export default function urlWithQuery(url: string, query: Partial<Query> = {}): string {
88
const queryString = toQueryString(
99
Object.fromEntries(Object.entries(query).filter(([, v]) => Boolean(v)))
1010
);

0 commit comments

Comments
 (0)