Files
Zack TannerandGitHub e9aeb9e1b9 memoize layout router context (#64575)
Since `AppRouterState` is promise-based (so we can `use` the values and
suspend in render), the state itself isn't stable between renders. Each
action corresponds with a new Promise object. When a link is hovered, a
prefetch action is dispatched, even if the prefetch never happens (for
example, if there's already a prefetch entry in the cache, and it
doesn't need to prefetch again). In other words, the prefetch action
will be dispatched but won't necessarily change the state.

This means that these no-op actions that don't actually change the state
values will trigger a re-render. Most of the context providers in
`AppRouter` are memoized with the exception of `LayoutRouter` context.
This PR memoizes those values so that consumers are only notified of
meaningful updates.

Fixes #63159


Closes NEXT-3127
2024-04-16 16:23:39 -07:00

24 lines
386 B
TypeScript

'use client'
export default function Error({
error,
reset,
}: {
error: Error & {
digest?: string
statusCode: number
}
reset: () => void
}) {
console.log('error render')
return (
<main>
<h1>Error</h1>
<div id="random-number">Random: {Math.random()}</div>
<p>{error.message}</p>
<button onClick={reset}>Reset</button>
</main>
)
}