diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 206c4baf9cf7bd4..a004ef005d77b55 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -78,7 +78,7 @@ type InternalLinkProps = { */ locale?: string | false /** - * Enable legacy link behaviour. + * Enable legacy link behavior. * @defaultValue `false` * @see https://github.com/vercel/next.js/commit/489e65ed98544e69b0afd7e0cfc3f9f6c2b803b7 */ @@ -122,18 +122,21 @@ function prefetch( return } - // Resolve the locale from the router. - const locale = 'locale' in router ? router.locale : undefined + // We should only dedupe requests when experimental.optimisticClientCache is + // disabled. + if (!process.env.__NEXT_OPTIMISTIC_CLIENT_CACHE) { + const locale = 'locale' in router ? router.locale : undefined - const key = href + '%' + as + (locale ? '%' + locale : '') + const key = href + '%' + as + (locale ? '%' + locale : '') - // If we've already fetched the key, then don't prefetch it again! - if (prefetched.has(key)) { - return - } + // If we've already fetched the key, then don't prefetch it again! + if (prefetched.has(key)) { + return + } - // Mark this URL as prefetched. - prefetched.add(key) + // Mark this URL as prefetched. + prefetched.add(key) + } // Prefetch the JSON page if asked (only in the client) // We need to handle a prefetch error here since we may be @@ -568,7 +571,6 @@ const Link = React.forwardRef( return } - // Check for not prefetch disabled in page using appRouter if (!prefetchEnabled && isAppRouter) { return } @@ -592,7 +594,6 @@ const Link = React.forwardRef( return } - // Check for not prefetch disabled in page using appRouter if (!prefetchEnabled && isAppRouter) { return } diff --git a/packages/next/shared/lib/loadable.d.ts b/packages/next/shared/lib/loadable.d.ts index 505fa09be9c3c3f..8ac6e8043379751 100644 --- a/packages/next/shared/lib/loadable.d.ts +++ b/packages/next/shared/lib/loadable.d.ts @@ -9,7 +9,7 @@ declare namespace LoadableExport { } } -// eslint-disable-next-line no-redeclare +// eslint-disable-next-line @typescript-eslint/no-redeclare declare const LoadableExport: LoadableExport.ILoadable export = LoadableExport diff --git a/test/e2e/app-dir/app/components/router-hooks-fixtures.js b/test/e2e/app-dir/app/components/router-hooks-fixtures.js index 465ff3b665ca7be..95f62d6f6fd7f35 100644 --- a/test/e2e/app-dir/app/components/router-hooks-fixtures.js +++ b/test/e2e/app-dir/app/components/router-hooks-fixtures.js @@ -4,8 +4,7 @@ import { useRouter as useAppRouter, useSearchParams, } from 'next/navigation' -import { useState } from 'react' -import { useEffect } from 'react' +import { useState, useEffect } from 'react' export const RouterHooksFixtures = () => { const pagesRouter = usePagesRouter()