I encountered an issue in a project using Blitz.js (built on top of Next.js) and Ant Design as the UI framework.

I noticed the following warning in the browser console:

onMouseEnter was passed to <Link> with href of [object Object] but "legacyBehavior" was set. The legacy behavior requires onMouseEnter be set on the child of next/link

1. Problematic Code

<Tooltip title="for dummies">
	<Link href={Routes.ShowProductPage({ slug: "for-dummies" })} passHref>
		<Button icon={<EyeOutlined />} type="link"></Button>
	</Link>
</Tooltip>

2. Solution

  • Create a wrapper component integrating next/link with Ant Design’s Button:
import React from "react";
import Link, { LinkProps } from "next/link";
import { Button, type ButtonProps } from "antd";

type AntdButtonNextLinkProps = LinkProps & Omit<ButtonProps, "href">;

const AntdButtonNextLink = React.forwardRef(
	({ href, children, ...props }: AntdButtonNextLinkProps, ref: any) => {
		return (
			<Link href={href} passHref>
				<Button ref={ref} {...props} type="link">
					{children}
				</Button>
			</Link>
		);
	}
);
  • Fix the issue by using the new component:
<Tooltip title="for dummies">
	<AntdButtonNextLink
		href={Routes.ShowProductPage({ slug: "for-dummies" })}
		icon={<EyeOutlined />}
	/>
</Tooltip>

References:

  1. https://github.com/chakra-ui/chakra-ui/issues/6105