next-intl 4.0.0-beta-22cf1cd → 4.0.0-beta-4106641

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.
@@ -59,12 +59,14 @@ function createMiddleware(routing) {
59
59
  urlObj.host = redirectDomain;
60
60
  if (request.headers.get('x-forwarded-host')) {
61
61
  urlObj.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol;
62
- urlObj.port = request.headers.get('x-forwarded-port') ?? '';
62
+ const redirectDomainPort = redirectDomain.split(':')[1];
63
+ urlObj.port = redirectDomainPort ?? request.headers.get('x-forwarded-port') ?? '';
63
64
  }
64
65
  }
65
66
  if (request.nextUrl.basePath) {
66
67
  urlObj.pathname = applyBasePath(urlObj.pathname, request.nextUrl.basePath);
67
68
  }
69
+ hasRedirected = true;
68
70
  return NextResponse.redirect(urlObj.toString());
69
71
  }
70
72
  const unprefixedExternalPathname = getNormalizedPathname(externalPathname, resolvedRouting.locales, resolvedRouting.localePrefix);
@@ -73,6 +75,7 @@ function createMiddleware(routing) {
73
75
  const isUnprefixedRouting = resolvedRouting.localePrefix.mode === 'never' || hasMatchedDefaultLocale && resolvedRouting.localePrefix.mode === 'as-needed';
74
76
  let response;
75
77
  let internalTemplateName;
78
+ let hasRedirected;
76
79
  let unprefixedInternalPathname = unprefixedExternalPathname;
77
80
  const pathnames = resolvedRouting.pathnames;
78
81
  if (pathnames) {
@@ -140,7 +143,7 @@ function createMiddleware(routing) {
140
143
  }
141
144
  }
142
145
  syncCookie(request, response, locale, resolvedRouting, domain);
143
- if (resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
146
+ if (!hasRedirected && resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
144
147
  response.headers.set('Link', getAlternateLinksHeaderValue({
145
148
  routing: resolvedRouting,
146
149
  localizedPathnames: internalTemplateName != null && pathnames ? pathnames[internalTemplateName] : undefined,
@@ -29,9 +29,10 @@ function createSharedNavigationFns(getLocale, routing) {
29
29
  locale,
30
30
  ...rest
31
31
  }, ref) {
32
- let pathname, params;
32
+ let pathname, params, query;
33
33
  if (typeof href === 'object') {
34
34
  pathname = href.pathname;
35
+ query = href.query;
35
36
  // @ts-expect-error -- This is ok
36
37
  params = href.params;
37
38
  } else {
@@ -76,8 +77,12 @@ function createSharedNavigationFns(getLocale, routing) {
76
77
  // @ts-expect-error -- This is ok
77
78
  {
78
79
  locale: curLocale,
79
- href: pathnames == null ? pathname : {
80
+ href: pathnames == null ? {
80
81
  pathname,
82
+ query
83
+ } : {
84
+ pathname,
85
+ query,
81
86
  params
82
87
  }
83
88
  }, false)
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{receiveRoutingConfig as t}from"../routing/config.js";import{HEADER_LOCALE_NAME as r}from"../shared/constants.js";import{matchesPathname as o,normalizeTrailingSlash as a,getLocalePrefix as l}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as p,getBestMatchingDomain as u,applyBasePath as U,getLocaleAsPrefix as P}from"./utils.js";function g(g){const v=t(g);return function(t){let g;try{g=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const L=c(g),{domain:j,locale:w}=s(v,t.headers,t.cookies,L),k=j?j.defaultLocale===w:w===v.defaultLocale,b=v.domains?.filter((e=>d(w,e)))||[],y=null!=v.domains&&!j;function R(o){const a=new URL(o,t.url);t.nextUrl.basePath&&(a.pathname=U(a.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);return l.set(r,w),e.rewrite(a,{request:{headers:l}})}function q(r,o){const l=new URL(r,t.url);if(l.pathname=a(l.pathname),b.length>0&&!o&&j){const e=u(j,w,b);e&&(o=e.domain,e.defaultLocale===w&&"as-needed"===v.localePrefix.mode&&(l.pathname=f(l.pathname,v.locales,v.localePrefix)))}return o&&(l.host=o,t.headers.get("x-forwarded-host")&&(l.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol,l.port=t.headers.get("x-forwarded-port")??"")),t.nextUrl.basePath&&(l.pathname=U(l.pathname,t.nextUrl.basePath)),e.redirect(l.toString())}const H=f(L,v.locales,v.localePrefix),z=m(L,v.locales,v.localePrefix),A=null!=z,C="never"===v.localePrefix.mode||k&&"as-needed"===v.localePrefix.mode;let I,S,V=H;const B=v.pathnames;if(B){let e;if([e,S]=h(B,H,w),S){const r=B[S],a="string"==typeof r?r:r[w];if(o(a,H))V=x(H,a,S);else{let o;o=e?"string"==typeof r?r:r[e]:S;const n=C?void 0:l(w,v.localePrefix),s=x(H,o,a);I=q(p(s,n,t.nextUrl.search))}}}if(!I)if("/"!==V||A){const e=p(V,P(w),t.nextUrl.search);if(A){const r=p(H,z.prefix,t.nextUrl.search);if("never"===v.localePrefix.mode)I=q(p(H,void 0,t.nextUrl.search));else if(z.exact)if(k&&C)I=q(p(H,void 0,t.nextUrl.search));else if(v.domains){const t=u(j,z.locale,b);I=j?.domain===t?.domain||y?R(e):q(r,t?.domain)}else I=R(e);else I=q(r)}else I=C?R(e):q(p(H,l(w,v.localePrefix),t.nextUrl.search))}else I=C?R(p(V,P(w),t.nextUrl.search)):q(p(H,l(w,v.localePrefix),t.nextUrl.search));return i(t,I,w,v,j),"never"!==v.localePrefix.mode&&v.alternateLinks&&v.locales.length>1&&I.headers.set("Link",n({routing:v,localizedPathnames:null!=S&&B?B[S]:void 0,request:t,resolvedLocale:w})),I}}export{g as default};
1
+ import{NextResponse as e}from"next/server";import{receiveRoutingConfig as t}from"../routing/config.js";import{HEADER_LOCALE_NAME as r}from"../shared/constants.js";import{matchesPathname as o,normalizeTrailingSlash as a,getLocalePrefix as l}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as p,getBestMatchingDomain as u,applyBasePath as U,getLocaleAsPrefix as P}from"./utils.js";function g(g){const v=t(g);return function(t){let g;try{g=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const L=c(g),{domain:j,locale:w}=s(v,t.headers,t.cookies,L),k=j?j.defaultLocale===w:w===v.defaultLocale,b=v.domains?.filter((e=>d(w,e)))||[],y=null!=v.domains&&!j;function R(o){const a=new URL(o,t.url);t.nextUrl.basePath&&(a.pathname=U(a.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);return l.set(r,w),e.rewrite(a,{request:{headers:l}})}function q(r,o){const l=new URL(r,t.url);if(l.pathname=a(l.pathname),b.length>0&&!o&&j){const e=u(j,w,b);e&&(o=e.domain,e.defaultLocale===w&&"as-needed"===v.localePrefix.mode&&(l.pathname=f(l.pathname,v.locales,v.localePrefix)))}if(o&&(l.host=o,t.headers.get("x-forwarded-host"))){l.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol;const e=o.split(":")[1];l.port=e??t.headers.get("x-forwarded-port")??""}return t.nextUrl.basePath&&(l.pathname=U(l.pathname,t.nextUrl.basePath)),V=!0,e.redirect(l.toString())}const H=f(L,v.locales,v.localePrefix),z=m(L,v.locales,v.localePrefix),A=null!=z,C="never"===v.localePrefix.mode||k&&"as-needed"===v.localePrefix.mode;let I,S,V,B=H;const D=v.pathnames;if(D){let e;if([e,S]=h(D,H,w),S){const r=D[S],a="string"==typeof r?r:r[w];if(o(a,H))B=x(H,a,S);else{let o;o=e?"string"==typeof r?r:r[e]:S;const n=C?void 0:l(w,v.localePrefix),s=x(H,o,a);I=q(p(s,n,t.nextUrl.search))}}}if(!I)if("/"!==B||A){const e=p(B,P(w),t.nextUrl.search);if(A){const r=p(H,z.prefix,t.nextUrl.search);if("never"===v.localePrefix.mode)I=q(p(H,void 0,t.nextUrl.search));else if(z.exact)if(k&&C)I=q(p(H,void 0,t.nextUrl.search));else if(v.domains){const t=u(j,z.locale,b);I=j?.domain===t?.domain||y?R(e):q(r,t?.domain)}else I=R(e);else I=q(r)}else I=C?R(e):q(p(H,l(w,v.localePrefix),t.nextUrl.search))}else I=C?R(p(B,P(w),t.nextUrl.search)):q(p(H,l(w,v.localePrefix),t.nextUrl.search));return i(t,I,w,v,j),!V&&"never"!==v.localePrefix.mode&&v.alternateLinks&&v.locales.length>1&&I.headers.set("Link",n({routing:v,localizedPathnames:null!=S&&D?D[S]:void 0,request:t,resolvedLocale:w})),I}}export{g as default};
@@ -1 +1 @@
1
- import{redirect as e,permanentRedirect as o}from"next/navigation";import{forwardRef as a}from"react";import{receiveRoutingConfig as t}from"../../routing/config.js";import n from"../../shared/use.js";import{isLocalizableHref as r,isPromise as i}from"../../shared/utils.js";import m from"./BaseLink.js";import{serializeSearchParams as l,compileLocalizedPathname as c,applyPathnamePrefix as f,normalizeNameOrNameWithParams as s}from"./utils.js";import{jsx as u}from"react/jsx-runtime";function p(p,d){const h=t(d||{}),j=h.pathnames,g="as-needed"===h.localePrefix.mode&&h.domains||void 0;function v({href:e,locale:o,...a},t){let l,c;"object"==typeof e?(l=e.pathname,c=e.params):l=e;const f=r(e),s=p(),d=i(s)?n(s):s,v=f?y({locale:o||d,href:null==j?l:{pathname:l,params:c}},null!=o||g||void 0):l;return u(m,{ref:t,defaultLocale:h.defaultLocale,href:"object"==typeof e?{...e,pathname:v}:v,locale:o,localeCookie:h.localeCookie,unprefixed:g&&f?{domains:h.domains.reduce(((e,o)=>(e[o.domain]=o.defaultLocale,e)),{}),pathname:y({locale:d,href:null==j?l:{pathname:l,params:c}},!1)}:void 0,...a})}const x=a(v);function y(e,o){const{href:a,locale:t}=e;let n;return null==j?"object"==typeof a?(n=a.pathname,a.query&&(n+=l(a.query))):n=a:n=c({locale:t,...s(a),pathnames:h.pathnames}),f(n,t,h,e.domain,o)}function L(e){return function(o,...a){return e(y(o,o.domain?void 0:g),...a)}}const k=L(e),b=L(o);return{config:h,Link:x,redirect:k,permanentRedirect:b,getPathname:y}}export{p as default};
1
+ import{redirect as e,permanentRedirect as o}from"next/navigation";import{forwardRef as a}from"react";import{receiveRoutingConfig as t}from"../../routing/config.js";import n from"../../shared/use.js";import{isLocalizableHref as r,isPromise as i}from"../../shared/utils.js";import m from"./BaseLink.js";import{serializeSearchParams as l,compileLocalizedPathname as c,applyPathnamePrefix as f,normalizeNameOrNameWithParams as u}from"./utils.js";import{jsx as s}from"react/jsx-runtime";function p(p,d){const h=t(d||{}),j=h.pathnames,y="as-needed"===h.localePrefix.mode&&h.domains||void 0;function g({href:e,locale:o,...a},t){let l,c,f;"object"==typeof e?(l=e.pathname,f=e.query,c=e.params):l=e;const u=r(e),d=p(),g=i(d)?n(d):d,q=u?v({locale:o||g,href:null==j?l:{pathname:l,params:c}},null!=o||y||void 0):l;return s(m,{ref:t,defaultLocale:h.defaultLocale,href:"object"==typeof e?{...e,pathname:q}:q,locale:o,localeCookie:h.localeCookie,unprefixed:y&&u?{domains:h.domains.reduce(((e,o)=>(e[o.domain]=o.defaultLocale,e)),{}),pathname:v({locale:g,href:null==j?{pathname:l,query:f}:{pathname:l,query:f,params:c}},!1)}:void 0,...a})}const q=a(g);function v(e,o){const{href:a,locale:t}=e;let n;return null==j?"object"==typeof a?(n=a.pathname,a.query&&(n+=l(a.query))):n=a:n=c({locale:t,...u(a),pathnames:h.pathnames}),f(n,t,h,e.domain,o)}function x(e){return function(o,...a){return e(v(o,o.domain?void 0:y),...a)}}const L=x(e),k=x(o);return{config:h,Link:q,redirect:L,permanentRedirect:k,getPathname:v}}export{p as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "4.0.0-beta-22cf1cd",
3
+ "version": "4.0.0-beta-4106641",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -112,7 +112,7 @@
112
112
  "dependencies": {
113
113
  "@formatjs/intl-localematcher": "^0.5.4",
114
114
  "negotiator": "^1.0.0",
115
- "use-intl": "4.0.0-beta-22cf1cd"
115
+ "use-intl": "4.0.0-beta-4106641"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
@@ -124,5 +124,5 @@
124
124
  "optional": true
125
125
  }
126
126
  },
127
- "gitHead": "4c488a143d58b57453b167b59b8061e3263016dc"
127
+ "gitHead": "b8eaa58ecd2088f788d5f4b7510493ce7f850176"
128
128
  }