Skip to content

Next 9 - Assigning a ref to the child of <Link> no longer works #7852

@fmapilis

Description

@fmapilis

Bug report

Describe the bug

In Next 8, the ref attached to an <a> element inside of <Link> was working correctly. With the introduction of intersection observer in Next 9, it looks like this ref is getting overwritten, even with prefetch disabled.

To Reproduce

Here's an example page:

import Link from "next/link";
import { useRef, useEffect } from "react";

const Home = () => {
  const buttonRef = useRef();

  useEffect(() => {
    console.log("buttonRef", buttonRef);
  });

  return (
    <Link href="/">
      <a ref={buttonRef}>click me</a>
    </Link>
  );
};

export default Home;

Steps to reproduce the behavior:

  1. Load the page
  2. Check the console

Expected behavior

buttonRef.current's value in Next 8 is a reference to the <a> tag. In Next 9, it's undefined.

System information

  • Version of Next.js: 9.0.0

Additional context

Not sure if this is an intended breaking change, but would be useful documented if so.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions