Skip to content

Commit

Permalink
feat: add forward-compatibility support for Next v13 Link (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley authored Nov 14, 2022
1 parent 5d29cc1 commit 45fe15e
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .changeset/silver-cars-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@hashicorp/react-button': minor
'@hashicorp/react-card': minor
'@hashicorp/react-docs-sidenav': minor
'@hashicorp/react-error-view': minor
'@hashicorp/react-link-wrap': minor
'@hashicorp/react-next-steps': minor
'@hashicorp/react-pricing-features': minor
'@hashicorp/react-pricing-tiers': minor
'@hashicorp/react-search': minor
'@hashicorp/react-standalone-link': minor
---

Use `legacyBehavior` prop for `next/link` to support Next v13
8 changes: 7 additions & 1 deletion packages/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ function Button({
</Elem>
)

return url ? <Link href={url}>{content}</Link> : content
return url ? (
<Link href={url} legacyBehavior>
{content}
</Link>
) : (
content
)
}

function Icon({
Expand Down
2 changes: 1 addition & 1 deletion packages/card/primitives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Card = React.forwardRef<HTMLAnchorElement, BaseCardProps>(
{withArrow ? <IconArrowRight24 /> : null}
</div>

<Link href={link}>
<Link href={link} legacyBehavior>
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a ref={ref} className={s.link} aria-label={heading} />
</Link>
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-sidenav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function NavLeaf({ title, url, isActive, isHidden }: NavLeafProps) {
// if the item has a path, it's a leaf node so we render a link to the page
return (
<li className={isHidden ? s.hiddenNode : ''}>
<Link href={url}>
<Link href={url} legacyBehavior>
<a className={s.navItem} data-is-active={isActive}>
<InlineSvg
src={svgBullet}
Expand Down
2 changes: 1 addition & 1 deletion packages/error-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ErrorPage({ statusCode }: ErrorPageProps): React.ReactElement {
<h1 className={s.heading}>{heading}</h1>
<p>{message}</p>
<p>
<Link href="/">
<Link href="/" legacyBehavior>
<a className={s.link}>Back to Home</a>
</Link>
</p>
Expand Down
1 change: 1 addition & 0 deletions packages/link-wrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function LinkWrap({
replace={replace}
scroll={scroll}
shallow={shallow}
legacyBehavior
>
<a data-testid="a" {...props}>
{children}
Expand Down
2 changes: 1 addition & 1 deletion packages/next-steps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function NextSteps({
function Tile({ variant, heading, description, cta }) {
const [isHovered, setIsHovered] = React.useState(false)
return (
<Link href={cta.url}>
<Link href={cta.url} legacyBehavior>
<a
className={classNames(s.tile, s[variant])}
onMouseOver={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function StickyTiers({
<div key={title} className={s.tier}>
<p className={s.tierName}>{title}</p>
<div className={s.cta}>
<Link href={cta.url}>
<Link href={cta.url} legacyBehavior>
{/* links should not be tabbable since they are in other locations on the page (see tier cards in hero) */}
<a onClick={cta.onClick} tabIndex={-1}>
{cta.title}
Expand Down
2 changes: 1 addition & 1 deletion packages/pricing-tiers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function PricingTiers({ tiers }: PricingTiersProps) {
onClick={cta.onClick}
/>
) : (
<Link href={cta.url}>
<Link href={cta.url} legacyBehavior>
<a className={s.textLink} onClick={cta.onClick}>
{cta.title}
</a>
Expand Down
2 changes: 1 addition & 1 deletion packages/search/hits.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const Hit = forwardRef(
id={`hit-${hit.__position}`}
data-testid="hit-item"
>
<Link {...hitLink} passHref>
<Link {...hitLink} passHref legacyBehavior>
<LinkWithClick
ref={ref}
className={classNames(s.hitLinkWrapper, { [s.isActive]: isActive })}
Expand Down
2 changes: 1 addition & 1 deletion packages/standalone-link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function StandaloneLink({
const [isHovered, setIsHovered] = React.useState(false)
const { onMouseOver, onMouseOut } = restProps
return (
<Link href={href}>
<Link href={href} legacyBehavior>
<a
className={classNames(s.root, s[appearance], s[theme])}
onMouseOver={(event) => {
Expand Down

1 comment on commit 45fe15e

@vercel
Copy link

@vercel vercel bot commented on 45fe15e Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.