-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure mpa navigation render side effects are only fired once (#…
…55032) This is to fix an issue where these redirect side effects can be fired multiple times when the router reducer state changes. This block is still run when the router state updates, which can lead to superfluous attempts to redirect to a page. With these changes, we keep track of the page that is being redirected to. If a re-render occurs while that request is in flight, we don't trigger the side effects. [Slack x-ref](https://vercel.slack.com/archives/C04DUD7EB1B/p1694049914264839)
- Loading branch information
Showing
8 changed files
with
134 additions
and
34 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use client' | ||
import Link from 'next/link' | ||
import { useEffect, useRef } from 'react' | ||
|
||
export default function Page() { | ||
const prefetchRef = useRef() | ||
const slowPageRef = useRef() | ||
|
||
useEffect(() => { | ||
function triggerPrefetch() { | ||
const event = new MouseEvent('mouseover', { | ||
view: window, | ||
bubbles: true, | ||
cancelable: true, | ||
}) | ||
|
||
prefetchRef.current.dispatchEvent(event) | ||
console.log('dispatched') | ||
} | ||
|
||
slowPageRef.current.click() | ||
|
||
setInterval(() => { | ||
triggerPrefetch() | ||
}, 1000) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<Link id="link-to-slow-page" href="/slow-page" ref={slowPageRef}> | ||
To /slow-page | ||
</Link> | ||
<Link id="prefetch-link" href="/hash" ref={prefetchRef}> | ||
Prefetch link | ||
</Link> | ||
</> | ||
) | ||
} |
Oops, something went wrong.