Skip to content

Commit 68f0565

Browse files
committed
Fixes to align with Next 15 changes
1 parent e67294f commit 68f0565

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

src/app/[...parts]/page.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { type Metadata } from "next";
12
import { redirect } from "next/navigation";
3+
import { type JSX } from "react";
24
import { type ViewType } from "react-diff-view";
35
import { createSimplePackageSpec } from "^/lib/createSimplePackageSpec";
46
import { DEFAULT_DIFF_FILES_GLOB } from "^/lib/default-diff-files";
@@ -15,11 +17,14 @@ import PackagephobiaDiff from "./_page/PackagephobiaDiff";
1517
import { type DIFF_TYPE_PARAM_NAME } from "./_page/paramNames";
1618

1719
export interface DiffPageProps {
18-
params: { parts: string | string[] };
19-
searchParams: QueryParams & { [DIFF_TYPE_PARAM_NAME]: ViewType };
20+
params: Promise<{ parts: string | string[] }>;
21+
searchParams: Promise<QueryParams & { [DIFF_TYPE_PARAM_NAME]: ViewType }>;
2022
}
2123

22-
export function generateMetadata({ params: { parts } }: DiffPageProps) {
24+
export async function generateMetadata({
25+
params,
26+
}: DiffPageProps): Promise<Metadata> {
27+
const { parts } = await params;
2328
const specs = splitParts(decodeParts(parts));
2429

2530
const [a, b] = specs.map((spec) => createSimplePackageSpec(spec));
@@ -31,18 +36,19 @@ export function generateMetadata({ params: { parts } }: DiffPageProps) {
3136
}
3237

3338
const DiffPage = async ({
34-
params: { parts },
39+
params,
3540
searchParams,
3641
}: DiffPageProps): Promise<JSX.Element> => {
37-
const { diffFiles, ...optionsQuery } = searchParams;
42+
const { parts } = await params;
43+
const { diffFiles, ...optionsQuery } = await searchParams;
3844

3945
const specsOrVersions = splitParts(decodeParts(parts));
4046
const { redirect: redirectTarget, canonicalSpecs } =
4147
await destination(specsOrVersions);
4248

4349
if (redirectTarget !== false) {
4450
const specsStr = specsToDiff(canonicalSpecs);
45-
const searchStr = Object.entries(searchParams)
51+
const searchStr = Object.entries(await searchParams)
4652
.map(([key, value]) => `${key}=${value}`)
4753
.join("&");
4854

src/app/api/[...parts]/route.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ enum STATUS_CODES {
1111
PERMANENT_REDIRECT = 308,
1212
}
1313

14-
export async function GET(
15-
req: NextRequest,
16-
{ params: { parts } }: { params: { parts: string[] } },
17-
) {
14+
export interface DiffApiContext {
15+
params: Promise<{ parts: string | string[] }>;
16+
}
17+
18+
export async function GET(req: NextRequest, { params }: DiffApiContext) {
19+
const { parts } = await params;
1820
const { searchParams } = new URL(req.url);
1921
const options = Object.fromEntries(searchParams);
2022

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Footer from "./_layout/Footer";
77
import Header from "./_layout/Header";
88
import "./globals.css";
99

10-
export const metadata = {
10+
export const metadata: Metadata = {
1111
applicationName: "npm-diff.app",
1212
title: {
1313
default: "npm-diff.app 📦🔃",
@@ -20,7 +20,7 @@ export const metadata = {
2020
address: false,
2121
telephone: false,
2222
},
23-
} satisfies Metadata;
23+
};
2424

2525
export const viewport = {
2626
themeColor: "#3f444e",

src/lib/suspense.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ export default function suspense<T>(
1313
WrappedComponent: ComponentType<T>,
1414
fallback: FunctionComponent<T> | ReactNode = <></>,
1515
): FunctionComponent<T & { key: string }> {
16-
const C = ({ key, ...props }: T & { key: string }): ReactElement => (
16+
const C = async ({
17+
key,
18+
...props
19+
}: T & { key: string }): Promise<ReactElement> => (
1720
<SuspenseComp
1821
key={key}
1922
fallback={
2023
typeof fallback === "function"
21-
? fallback(props as any)
24+
? await fallback(props as any)
2225
: fallback
2326
}
2427
>

src/lib/utils/useThrottle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useUnmount } from "react-use";
66
// Once this issue is closed, we should be able to remove this file
77
const useThrottle = <T>(value: T, ms: number = 200) => {
88
const [state, setState] = useState<T>(value);
9-
const timeout = useRef<ReturnType<typeof setTimeout>>();
9+
const timeout = useRef<ReturnType<typeof setTimeout>>(undefined);
1010
const nextValue = useRef(null) as any;
1111
const hasNextValue = useRef(0) as any;
1212

0 commit comments

Comments
 (0)