mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
fix: nextjs unreliable params in route
This commit is contained in:
@@ -2,6 +2,7 @@ import type { NextRequest } from 'next/server';
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { fetchVersions } from '~/app/docAPI';
|
import { fetchVersions } from '~/app/docAPI';
|
||||||
|
|
||||||
export async function GET(_: NextRequest, params: { package: string }) {
|
export async function GET(req: NextRequest) {
|
||||||
return NextResponse.json(await fetchVersions(params.package));
|
const packageName = req.nextUrl.pathname.split('/').slice(2, 3)[0] ?? 'discord.js';
|
||||||
|
return NextResponse.json(await fetchVersions(packageName));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,15 +10,14 @@ import useSWR from 'swr';
|
|||||||
|
|
||||||
const isDev = process.env.NEXT_PUBLIC_LOCAL_DEV === 'true' ?? process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview';
|
const isDev = process.env.NEXT_PUBLIC_LOCAL_DEV === 'true' ?? process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview';
|
||||||
|
|
||||||
// eslint-disable-next-line promise/prefer-await-to-then
|
|
||||||
const fetcher = async (url: string) => fetch(url).then(async (res) => res.json());
|
|
||||||
|
|
||||||
export default function VersionSelect({ versions }: { readonly versions: string[] }) {
|
export default function VersionSelect({ versions }: { readonly versions: string[] }) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const packageName = pathname?.split('/').slice(3, 4)[0];
|
const packageName = pathname?.split('/').slice(3, 4)[0];
|
||||||
const branchName = pathname?.split('/').slice(4, 5)[0];
|
const branchName = pathname?.split('/').slice(4, 5)[0];
|
||||||
|
|
||||||
const { data } = useSWR<string[]>(`/api/${packageName}/versions`, { fetcher, fallbackData: versions });
|
const { data } = useSWR<string[]>(packageName ? `/api/${packageName}/versions` : null, {
|
||||||
|
fallbackData: versions,
|
||||||
|
});
|
||||||
|
|
||||||
const versionMenu = useMenuState({
|
const versionMenu = useMenuState({
|
||||||
gutter: 8,
|
gutter: 8,
|
||||||
|
|||||||
Reference in New Issue
Block a user