forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary re-render on <Link> reveal
The Link component initiates a prefetch whenever it enters the viewport, but currently the implementation works by setting an `isVisible` state to true, rerendering the component, and calling `router.prefetch` inside a `useEffect` hook. This extra render is not necessary — we can initiate the prefetch directly inside the IntersectionObserver's event handler. The bulk of the changes in this commit involve removing the use of the `useIntersection` abstraction and inlining the IntersectionObserver into the Link module. The removal of this indirection will make it easier to add more sophisticated scheduling improvements, like canceling the prefetch on viewport exit, and increasing the priority of the prefetch during hover. This affects App Router only, not Pages Router.
- Loading branch information
Showing
9 changed files
with
433 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.