Scheduling infrastructure for absolutely everyone.
chore: ensure compat type definitions do not break existing types (#11741)
Greg Pabian39c3ef0d94ae
diff --git a/packages/lib/hooks/useRouterQuery.ts b/packages/lib/hooks/useRouterQuery.tsindex 587bd8083ec..5a923f284d9 100644--- a/packages/lib/hooks/useRouterQuery.ts+++ b/packages/lib/hooks/useRouterQuery.ts@@ -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;};diff --git a/packages/lib/hooks/useTypedQuery.ts b/packages/lib/hooks/useTypedQuery.tsindex ab420385800..7fb61414d0c 100644--- a/packages/lib/hooks/useTypedQuery.ts+++ b/packages/lib/hooks/useTypedQuery.ts@@ -96,7 +96,9 @@ export function useTypedQuery<T extends z.AnyZodObject>(schema: T) {// Remove all query params from the URLfunction removeAllQueryParams() {- router.replace(pathname);+ if (pathname !== null) {+ router.replace(pathname);+ }}return {diff --git a/packages/lib/next-seo.config.ts b/packages/lib/next-seo.config.tsindex 78442c38dfa..edff0d59f4f 100644--- a/packages/lib/next-seo.config.ts+++ b/packages/lib/next-seo.config.ts@@ -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];};diff --git a/packages/ui/components/apps/AllApps.tsx b/packages/ui/components/apps/AllApps.tsxindex ce3b821913b..4a906b1e873 100644--- a/packages/ui/components/apps/AllApps.tsx+++ b/packages/ui/components/apps/AllApps.tsx@@ -95,7 +95,9 @@ function CategoryTab({ selectedCategory, categories, searchText }: CategoryTabPrref={ref}><lionClick={() => {- router.replace(pathname);+ if (pathname !== null) {+ router.replace(pathname);+ }}}className={classNames(selectedCategory === null ? "bg-emphasis text-default" : "bg-muted text-emphasis",@@ -108,9 +110,11 @@ function CategoryTab({ selectedCategory, categories, searchText }: CategoryTabPrkey={pos}onClick={() => {if (selectedCategory === cat) {- router.replace(pathname);+ if (pathname !== null) {+ router.replace(pathname);+ }} else {- const _searchParams = new URLSearchParams(searchParams);+ const _searchParams = new URLSearchParams(searchParams ?? undefined);_searchParams.set("category", cat);router.replace(`${pathname}?${_searchParams.toString()}`);}diff --git a/packages/ui/components/apps/AppCard.tsx b/packages/ui/components/apps/AppCard.tsxindex bd03245ba07..4d55813e590 100644--- a/packages/ui/components/apps/AppCard.tsx+++ b/packages/ui/components/apps/AppCard.tsx@@ -190,7 +190,9 @@ const InstallAppButtonChild = ({const mutation = useAddAppMutation(null, {onSuccess: (data) => {// Refresh SSR page content without actual reload- router.replace(pathname);+ if (pathname !== null) {+ router.replace(pathname);+ }if (data?.setupPending) return;showToast(t("app_successfully_installed"), "success");},diff --git a/packages/ui/components/breadcrumb/Breadcrumb.tsx b/packages/ui/components/breadcrumb/Breadcrumb.tsxindex 7792657c90b..d7c9f9d1d43 100644--- a/packages/ui/components/breadcrumb/Breadcrumb.tsx+++ b/packages/ui/components/breadcrumb/Breadcrumb.tsx@@ -50,7 +50,7 @@ export const BreadcrumbContainer = () => {useEffect(() => {const rawPath = pathname; // Pathname doesn't include search params anymore- let pathArray = rawPath.split("/");+ let pathArray = rawPath?.split("/") ?? [];pathArray.shift();pathArray = pathArray.filter((path) => path !== "");diff --git a/packages/ui/components/createButton/CreateButton.tsx b/packages/ui/components/createButton/CreateButton.tsxindex 9d8b70d0671..f42b4225e91 100644--- a/packages/ui/components/createButton/CreateButton.tsx+++ b/packages/ui/components/createButton/CreateButton.tsx@@ -60,7 +60,7 @@ export function CreateButton(props: CreateBtnProps) {// inject selection data into url for correct router historyconst openModal = (option: Option) => {- const _searchParams = new URLSearchParams(searchParams);+ const _searchParams = new URLSearchParams(searchParams ?? undefined);function setParamsIfDefined(key: string, value: string | number | boolean | null | undefined) {if (value !== undefined && value !== null) _searchParams.set(key, value.toString());}@@ -136,7 +136,7 @@ export function CreateButton(props: CreateBtnProps) {</DropdownMenuContent></Dropdown>)}- {searchParams.get("dialog") === "new" && CreateDialog}+ {searchParams?.get("dialog") === "new" && CreateDialog}</>);}diff --git a/packages/ui/components/dialog/Dialog.tsx b/packages/ui/components/dialog/Dialog.tsxindex e78b08db9b7..7565c0524c9 100644--- a/packages/ui/components/dialog/Dialog.tsx+++ b/packages/ui/components/dialog/Dialog.tsx@@ -28,7 +28,7 @@ export function Dialog(props: DialogProps) {const router = useRouter();const pathname = usePathname();const searchParams = useSearchParams();- const newSearchParams = new URLSearchParams(searchParams);+ const newSearchParams = new URLSearchParams(searchParams ?? undefined);const { children, name, ...dialogProps } = props;// only used if name is set