chore: ensure compat type definitions do not break existing types (#11741)

This commit is contained in:
Greg Pabian authored and GitHub committed 2023-10-10 14:50:15 -07:00
1 parent 0f92afb4bd
commit 39c3ef0d94
8 files changed
+31 -12

No files matched your search

+7 -2
View File
@@ -3,8 +3,13 @@ import { useSearchParams } from "next/navigation";
/**
* An alternative to Object.fromEntries that allows duplicate keys.
*/
function fromEntriesWithDuplicateKeys(entries: ReturnType<ReturnType<typeof useSearchParams>["entries"]>) {
function fromEntriesWithDuplicateKeys(entries: IterableIterator<[string, string]> | null) {
const result: Record<string, string | string[]> = {};
if (entries === null) {
return result;
}
// Consider setting atleast ES2015 as target
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
@@ -31,6 +36,6 @@ function fromEntriesWithDuplicateKeys(entries: ReturnType<ReturnType<typeof useS
*/
export const useRouterQuery = () => {
const searchParams = useSearchParams();
const routerQuery = fromEntriesWithDuplicateKeys(searchParams.entries());
const routerQuery = fromEntriesWithDuplicateKeys(searchParams?.entries() ?? null);
return routerQuery;
};
+3 -1
View File
@@ -96,7 +96,9 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T) {
// Remove all query params from the URL
function removeAllQueryParams() {
router.replace(pathname);
if (pathname !== null) {
router.replace(pathname);
}
}
return {
+7 -1
View File
@@ -47,6 +47,12 @@ export const seoConfig: {
* @param path NextJS' useRouter().asPath
* @returns
*/
export const buildCanonical = ({ origin, path }: { origin: Location["origin"]; path: Router["asPath"] }) => {
export const buildCanonical = ({
origin,
path,
}: {
origin: Location["origin"];
path: Router["asPath"] | null;
}) => {
return `${origin}${path === "/" ? "" : path}`.split("?")[0];
};