next-intl 4.13.2 → 4.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,21 @@ import { getAcceptLanguageLocale } from './resolveLocale.js';
|
|
|
2
2
|
|
|
3
3
|
function syncCookie(request, response, locale, routing, domain) {
|
|
4
4
|
if (!routing.localeCookie) return;
|
|
5
|
+
|
|
6
|
+
// Only document requests indicate that the user is actually
|
|
7
|
+
// navigating to a page—in contrast to background requests of the
|
|
8
|
+
// client-side router like prefetches and cache revalidations.
|
|
9
|
+
// E.g. as of Next.js 16.3, the router revalidates previously
|
|
10
|
+
// visited routes after a navigation, including routes of a locale
|
|
11
|
+
// the user has just switched away from. Updating the cookie based
|
|
12
|
+
// on such a request would overwrite the locale that was just set
|
|
13
|
+
// when switching the locale. Note that Next.js strips router
|
|
14
|
+
// headers like `Next-Router-Prefetch` before invoking the
|
|
15
|
+
// middleware, therefore `Sec-Fetch-Dest` is used to detect
|
|
16
|
+
// background requests. Locale switches via a soft navigation
|
|
17
|
+
// update the cookie on the client side.
|
|
18
|
+
const secFetchDest = request.headers.get('sec-fetch-dest');
|
|
19
|
+
if (secFetchDest != null && secFetchDest !== 'document') return;
|
|
5
20
|
const {
|
|
6
21
|
name,
|
|
7
22
|
...rest
|
|
@@ -6,19 +6,25 @@ import { useLocale } from 'use-intl';
|
|
|
6
6
|
import syncLocaleCookie from './syncLocaleCookie.js';
|
|
7
7
|
import { jsx } from 'react/jsx-runtime';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// Somehow the types for `next/link` don't work as expected
|
|
10
|
+
// when `moduleResolution: "nodenext"` is used.
|
|
11
|
+
const Link = NextLink;
|
|
12
|
+
|
|
13
|
+
// Links that change the locale are handled in a separate component,
|
|
14
|
+
// since reading the pathname (necessary for syncing the locale cookie)
|
|
15
|
+
// requires a Suspense boundary when Cache Components are used. Due to
|
|
16
|
+
// this split, regular links are not subject to this requirement.
|
|
17
|
+
function LocaleChangingLink({
|
|
18
|
+
curLocale,
|
|
19
|
+
linkRef,
|
|
11
20
|
locale,
|
|
12
21
|
localeCookie,
|
|
13
22
|
onClick,
|
|
14
23
|
prefetch,
|
|
15
24
|
...rest
|
|
16
|
-
}
|
|
17
|
-
const curLocale = useLocale();
|
|
18
|
-
const isChangingLocale = locale != null && locale !== curLocale;
|
|
19
|
-
|
|
25
|
+
}) {
|
|
20
26
|
// The types aren't entirely correct here. Outside of Next.js
|
|
21
|
-
// `
|
|
27
|
+
// `usePathname` can be called, but the return type is `null`.
|
|
22
28
|
const pathname = usePathname();
|
|
23
29
|
function onLinkClick(event) {
|
|
24
30
|
// Even though we force a prefix when changing locales,
|
|
@@ -27,22 +33,35 @@ function BaseLink({
|
|
|
27
33
|
syncLocaleCookie(localeCookie, pathname, curLocale, locale);
|
|
28
34
|
if (onClick) onClick(event);
|
|
29
35
|
}
|
|
36
|
+
if (prefetch && "development" !== 'production') {
|
|
37
|
+
console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`');
|
|
38
|
+
}
|
|
39
|
+
return /*#__PURE__*/jsx(Link, {
|
|
40
|
+
ref: linkRef,
|
|
41
|
+
hrefLang: locale,
|
|
42
|
+
onClick: onLinkClick,
|
|
43
|
+
prefetch: false,
|
|
44
|
+
...rest
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function BaseLink({
|
|
48
|
+
locale,
|
|
49
|
+
localeCookie,
|
|
50
|
+
...rest
|
|
51
|
+
}, ref) {
|
|
52
|
+
const curLocale = useLocale();
|
|
53
|
+
const isChangingLocale = locale != null && locale !== curLocale;
|
|
30
54
|
if (isChangingLocale) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
return /*#__PURE__*/jsx(LocaleChangingLink, {
|
|
56
|
+
curLocale: curLocale,
|
|
57
|
+
linkRef: ref,
|
|
58
|
+
locale: locale,
|
|
59
|
+
localeCookie: localeCookie,
|
|
60
|
+
...rest
|
|
61
|
+
});
|
|
35
62
|
}
|
|
36
|
-
|
|
37
|
-
// Somehow the types for `next/link` don't work as expected
|
|
38
|
-
// when `moduleResolution: "nodenext"` is used.
|
|
39
|
-
const Link = NextLink;
|
|
40
63
|
return /*#__PURE__*/jsx(Link, {
|
|
41
64
|
ref: ref,
|
|
42
|
-
href: href,
|
|
43
|
-
hrefLang: isChangingLocale ? locale : undefined,
|
|
44
|
-
onClick: onLinkClick,
|
|
45
|
-
prefetch: prefetch,
|
|
46
65
|
...rest
|
|
47
66
|
});
|
|
48
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAcceptLanguageLocale as e}from"./resolveLocale.js";function o(o,a,l
|
|
1
|
+
import{getAcceptLanguageLocale as e}from"./resolveLocale.js";function o(o,t,s,a,l){if(!a.localeCookie)return;const c=o.headers.get("sec-fetch-dest");if(null!=c&&"document"!==c)return;const{name:i,...r}=a.localeCookie,n=o.cookies.has(i);if(n&&o.cookies.get(i)?.value!==s)t.cookies.set(i,s,{path:o.nextUrl.basePath||void 0,...r});else if(!n){e(o.headers,l?.locales||a.locales,a.defaultLocale)!==s&&t.cookies.set(i,s,{path:o.nextUrl.basePath||void 0,...r})}}export{o as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import o from"next/link";import{usePathname as
|
|
2
|
+
import o from"next/link";import{usePathname as e}from"next/navigation";import{forwardRef as r}from"react";import{useLocale as n}from"use-intl";import t from"./syncLocaleCookie.js";import{jsx as c}from"react/jsx-runtime";const l=o;function i({curLocale:o,linkRef:r,locale:n,localeCookie:i,onClick:a,prefetch:f,...m}){const u=e();return c(l,{ref:r,hrefLang:n,onClick:function(e){t(i,u,o,n),a&&a(e)},prefetch:!1,...m})}function a({locale:o,localeCookie:e,...r},t){const a=n();return null!=o&&o!==a?c(i,{curLocale:a,linkRef:t,locale:o,localeCookie:e,...r}):c(l,{ref:t,...r})}var f=r(a);export{f as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"funding": [
|
|
@@ -127,11 +127,11 @@
|
|
|
127
127
|
"@formatjs/intl-localematcher": "^0.8.1",
|
|
128
128
|
"@parcel/watcher": "^2.4.1",
|
|
129
129
|
"@swc/core": "^1.15.2",
|
|
130
|
-
"icu-minify": "^4.13.
|
|
130
|
+
"icu-minify": "^4.13.4",
|
|
131
131
|
"negotiator": "^1.0.0",
|
|
132
|
-
"next-intl-swc-plugin-extractor": "^4.13.
|
|
132
|
+
"next-intl-swc-plugin-extractor": "^4.13.4",
|
|
133
133
|
"po-parser": "^2.1.1",
|
|
134
|
-
"use-intl": "^4.13.
|
|
134
|
+
"use-intl": "^4.13.4"
|
|
135
135
|
},
|
|
136
136
|
"peerDependencies": {
|
|
137
137
|
"next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
@@ -142,5 +142,5 @@
|
|
|
142
142
|
"optional": true
|
|
143
143
|
}
|
|
144
144
|
},
|
|
145
|
-
"gitHead": "
|
|
145
|
+
"gitHead": "7fa175d0303804fea48aad0c8b5de89077948e9c"
|
|
146
146
|
}
|