From fd6d73dc145a0679e85a1a71fe40c43d3312e27e Mon Sep 17 00:00:00 2001 From: Jan Amann Date: Thu, 24 Oct 2024 14:58:15 +0200 Subject: [PATCH] fix: Don't warn when setting `prefetch={true}` on `` (#1463) Fixes #1462 --- packages/next-intl/.size-limit.ts | 8 ++++---- .../src/navigation/createNavigation.test.tsx | 11 +++++++++++ packages/next-intl/src/navigation/shared/BaseLink.tsx | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/next-intl/.size-limit.ts b/packages/next-intl/.size-limit.ts index b7da32c21..ed9dac2c8 100644 --- a/packages/next-intl/.size-limit.ts +++ b/packages/next-intl/.size-limit.ts @@ -15,25 +15,25 @@ const config: SizeLimitConfig = [ name: "import {createSharedPathnamesNavigation} from 'next-intl/navigation' (react-client)", path: 'dist/production/navigation.react-client.js', import: '{createSharedPathnamesNavigation}', - limit: '4.04 KB' + limit: '4.045 KB' }, { name: "import {createLocalizedPathnamesNavigation} from 'next-intl/navigation' (react-client)", path: 'dist/production/navigation.react-client.js', import: '{createLocalizedPathnamesNavigation}', - limit: '4.04 KB' + limit: '4.045 KB' }, { name: "import {createNavigation} from 'next-intl/navigation' (react-client)", path: 'dist/production/navigation.react-client.js', import: '{createNavigation}', - limit: '4.045 KB' + limit: '4.055 KB' }, { name: "import {createSharedPathnamesNavigation} from 'next-intl/navigation' (react-server)", path: 'dist/production/navigation.react-server.js', import: '{createSharedPathnamesNavigation}', - limit: '16.78 KB' + limit: '16.795 KB' }, { name: "import {createLocalizedPathnamesNavigation} from 'next-intl/navigation' (react-server)", diff --git a/packages/next-intl/src/navigation/createNavigation.test.tsx b/packages/next-intl/src/navigation/createNavigation.test.tsx index a04ddaee4..eacb29ea9 100644 --- a/packages/next-intl/src/navigation/createNavigation.test.tsx +++ b/packages/next-intl/src/navigation/createNavigation.test.tsx @@ -204,6 +204,17 @@ describe.each([ }} />; }); + + it('does not warn when setting the `prefetch` prop', () => { + const consoleSpy = vi.spyOn(console, 'error'); + const markup = renderToString( + + About + + ); + expect(markup).toContain('href="/en/about"'); + expect(consoleSpy).not.toHaveBeenCalled(); + }); }); describe('getPathname', () => { diff --git a/packages/next-intl/src/navigation/shared/BaseLink.tsx b/packages/next-intl/src/navigation/shared/BaseLink.tsx index 57ef571d8..fe595688a 100644 --- a/packages/next-intl/src/navigation/shared/BaseLink.tsx +++ b/packages/next-intl/src/navigation/shared/BaseLink.tsx @@ -38,7 +38,7 @@ function BaseLink( ref: ComponentProps['ref'] ) { const curLocale = useLocale(); - const isChangingLocale = locale !== curLocale; + const isChangingLocale = locale != null && locale !== curLocale; const linkLocale = locale || curLocale; const host = useHost();