Skip to content

Commit

Permalink
(fix: #75439) Handle null or undefined href prop passed into componentt
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeleventhal committed Jan 29, 2025
1 parent c97dff9 commit ff737c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/next/src/client/app-dir/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
let children: React.ReactNode

const {
href: hrefProp,
href: unfilteredHrefProp,
as: asProp,
children: childrenProp,
prefetch: prefetchProp = null,
Expand All @@ -427,6 +427,8 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
...restProps
} = props

const hrefProp = unfilteredHrefProp ?? ''

children = childrenProp

if (
Expand Down Expand Up @@ -582,7 +584,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
}

const { href, as } = React.useMemo(() => {
const resolvedHref = formatStringOrUrl(hrefProp)
const resolvedHref = formatStringOrUrl(hrefProp ?? '')
return {
href: resolvedHref,
as: asProp ? formatStringOrUrl(asProp) : resolvedHref,
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
let children: React.ReactNode

const {
href: hrefProp,
href: unfilteredHrefProp,
as: asProp,
children: childrenProp,
prefetch: prefetchProp = null,
Expand All @@ -271,6 +271,8 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
...restProps
} = props

const hrefProp = unfilteredHrefProp ?? ''

children = childrenProp

if (
Expand Down

0 comments on commit ff737c9

Please sign in to comment.