From ff737c919396682ce1490e776a16e494e51aff33 Mon Sep 17 00:00:00 2001 From: Jake Leventhal Date: Wed, 29 Jan 2025 15:08:53 -0500 Subject: [PATCH] (fix: #75439) Handle null or undefined href prop passed into componentt --- packages/next/src/client/app-dir/link.tsx | 6 ++++-- packages/next/src/client/link.tsx | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/next/src/client/app-dir/link.tsx b/packages/next/src/client/app-dir/link.tsx index adf90964deb755..08330ec274dcc5 100644 --- a/packages/next/src/client/app-dir/link.tsx +++ b/packages/next/src/client/app-dir/link.tsx @@ -412,7 +412,7 @@ const Link = React.forwardRef( let children: React.ReactNode const { - href: hrefProp, + href: unfilteredHrefProp, as: asProp, children: childrenProp, prefetch: prefetchProp = null, @@ -427,6 +427,8 @@ const Link = React.forwardRef( ...restProps } = props + const hrefProp = unfilteredHrefProp ?? '' + children = childrenProp if ( @@ -582,7 +584,7 @@ const Link = React.forwardRef( } const { href, as } = React.useMemo(() => { - const resolvedHref = formatStringOrUrl(hrefProp) + const resolvedHref = formatStringOrUrl(hrefProp ?? '') return { href: resolvedHref, as: asProp ? formatStringOrUrl(asProp) : resolvedHref, diff --git a/packages/next/src/client/link.tsx b/packages/next/src/client/link.tsx index 685033eedd5572..4caa366bda3daa 100644 --- a/packages/next/src/client/link.tsx +++ b/packages/next/src/client/link.tsx @@ -255,7 +255,7 @@ const Link = React.forwardRef( let children: React.ReactNode const { - href: hrefProp, + href: unfilteredHrefProp, as: asProp, children: childrenProp, prefetch: prefetchProp = null, @@ -271,6 +271,8 @@ const Link = React.forwardRef( ...restProps } = props + const hrefProp = unfilteredHrefProp ?? '' + children = childrenProp if (