Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into canary
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/next-intl/src/middleware/utils.test.tsx
#	packages/next-intl/src/shared/utils.test.tsx
  • Loading branch information
amannn committed Jul 11, 2024
2 parents cb15046 + 077a0ca commit 11262b8
Show file tree
Hide file tree
Showing 72 changed files with 249 additions and 227 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 3.15.5 (2024-07-09)

### Bug Fixes

* Support relative pathnames in `redirect` ([#1178](https://github.com/amannn/next-intl/issues/1178)) ([3b698d7](https://github.com/amannn/next-intl/commit/3b698d7abdb8859a43448381ba2361dee4b5e669)), closes [#1177](https://github.com/amannn/next-intl/issues/1177) – by @amannn

## 3.15.4 (2024-07-08)

### Bug Fixes

* Export `DomainsConfig` ([#1175](https://github.com/amannn/next-intl/issues/1175)) ([c4d1bb0](https://github.com/amannn/next-intl/commit/c4d1bb08e23cc8a726c3a52e6cee7b1c63cb4c8a)) – by @amannn

## 3.15.3 (2024-06-26)

### Bug Fixes

* Prefer more specific routes in `usePathname` when detecting the currently active pathname for localized pathnames ([#1152](https://github.com/amannn/next-intl/issues/1152)) ([936839e](https://github.com/amannn/next-intl/commit/936839e9508e447f3e60cc1f606258fd00e5227e)), closes [#1151](https://github.com/amannn/next-intl/issues/1151) – by @amannn

## 3.15.2 (2024-06-19)

**Note:** Version bump only for package root
Expand Down
1 change: 0 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "docs",
"version": "2.14.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
4 changes: 3 additions & 1 deletion docs/pages/docs/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ If you want to serve your localized content based on different domains, you can
- `ca.example.com/fr`

```tsx filename="config.ts"
import {DomainsConfig} from 'next-intl/routing';

export const locales = ['en', 'fr'] as const;

export const domains: DomainsConfig<typeof locales> = [
Expand All @@ -342,4 +344,4 @@ export const domains: DomainsConfig<typeof locales> = [
**Note that:**

1. You can optionally remove the locale prefix in pathnames by changing the [`localePrefix`](#locale-prefix) setting.
2. If no domain matches, the middleware will fall back to the [`defaultLocale`](/docs/routing/middleware#default-locale) (e.g. on `localhost`).
2. If no domain matches, the middleware will fall back to the [`defaultLocale`](/docs/routing/middleware#default-locale) (e.g. on `localhost`).
1 change: 0 additions & 1 deletion examples/example-app-router-migration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-app-router-migration",
"version": "2.10.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 0 additions & 2 deletions examples/example-app-router-mixed-routing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-app-router-mixed-routing",
"version": "2.14.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -25,7 +24,6 @@
"eslint-config-molindo": "^7.0.0",
"eslint-config-next": "^14.2.4",
"postcss": "^8.4.38",
"prettier-plugin-tailwindcss": "^0.6.5",
"typescript": "^5.4.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function middleware(request: NextRequest) {
if (isAppRoute) {
// Add a hint that we can read in `i18n.ts`
request.headers.set('x-app-route', 'true');
return NextResponse.next({headers: request.headers});
return NextResponse.next({request: {headers: request.headers}});
} else {
return intlMiddleware(request);
}
Expand Down
1 change: 0 additions & 1 deletion examples/example-app-router-next-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-app-router-next-auth",
"version": "2.14.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
1 change: 0 additions & 1 deletion examples/example-app-router-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-app-router-playground",
"version": "2.9.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
1 change: 0 additions & 1 deletion examples/example-app-router-single-locale/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-app-router-single-locale",
"version": "2.10.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
extends: [
'molindo/typescript',
'molindo/react',
'molindo/tailwind',
'plugin:@next/next/recommended'
]
};
3 changes: 0 additions & 3 deletions examples/example-app-router-without-i18n-routing/.prettierrc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"eslint-config-molindo": "^7.0.0",
"eslint-config-next": "^14.2.4",
"postcss": "^8.4.38",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^3.4.4",
"typescript": "^5.4.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function NavLink({href, ...rest}: ComponentProps<typeof Link>) {
<Link
aria-current={isActive ? 'page' : undefined}
className={clsx(
'border-b-2 border-transparent pb-2 pt-2 font-semibold transition-colors',
'border-b-2 border-transparent py-2 font-semibold transition-colors',
isActive
? 'border-b-slate-900 text-slate-900'
: 'text-slate-600 hover:border-b-slate-300 hover:text-slate-900'
Expand Down
2 changes: 0 additions & 2 deletions examples/example-app-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-app-router",
"version": "2.14.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down Expand Up @@ -34,7 +33,6 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"postcss": "^8.4.38",
"prettier-plugin-tailwindcss": "^0.6.5",
"typescript": "^5.4.5"
}
}
1 change: 0 additions & 1 deletion examples/example-pages-router-advanced/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-pages-router-advanced",
"version": "2.14.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
1 change: 0 additions & 1 deletion examples/example-pages-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-pages-router",
"version": "2.14.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion examples/example-react-native/app.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"expo": {
"name": "example-react-native",
"slug": "example-use-intl",
"version": "1.0.0",
"slug": "example-react-native",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
Expand Down
1 change: 0 additions & 1 deletion examples/example-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "example-react-native",
"version": "2.14.3",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
Expand Down
1 change: 0 additions & 1 deletion examples/example-use-intl/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "example-use-intl",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
"version": "3.15.2",
"version": "3.15.5",
"packages": [
"packages/*"
],
Expand Down
3 changes: 3 additions & 0 deletions packages/next-intl/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {
'molindo/cypress'
],
plugins: ['deprecation'],
rules: {
'import/no-useless-path-segments': 'error'
},
overrides: [
{
files: ['test/**/*.tsx'],
Expand Down
18 changes: 18 additions & 0 deletions packages/next-intl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 3.15.5 (2024-07-09)

### Bug Fixes

* Support relative pathnames in `redirect` ([#1178](https://github.com/amannn/next-intl/issues/1178)) ([3b698d7](https://github.com/amannn/next-intl/commit/3b698d7abdb8859a43448381ba2361dee4b5e669)), closes [#1177](https://github.com/amannn/next-intl/issues/1177) – by @amannn

## 3.15.4 (2024-07-08)

### Bug Fixes

* Export `DomainsConfig` ([#1175](https://github.com/amannn/next-intl/issues/1175)) ([c4d1bb0](https://github.com/amannn/next-intl/commit/c4d1bb08e23cc8a726c3a52e6cee7b1c63cb4c8a)) – by @amannn

## 3.15.3 (2024-06-26)

### Bug Fixes

* Prefer more specific routes in `usePathname` when detecting the currently active pathname for localized pathnames ([#1152](https://github.com/amannn/next-intl/issues/1152)) ([936839e](https://github.com/amannn/next-intl/commit/936839e9508e447f3e60cc1f606258fd00e5227e)), closes [#1151](https://github.com/amannn/next-intl/issues/1151) – by @amannn

## 3.15.2 (2024-06-19)

**Note:** Version bump only for package next-intl
Expand Down
2 changes: 1 addition & 1 deletion packages/next-intl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-intl",
"version": "3.15.2",
"version": "3.15.5",
"sideEffects": false,
"author": "Jan Amann <[email protected]>",
"funding": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import {NextRequest} from 'next/server';
import {it, expect, describe} from 'vitest';
import {receiveConfig} from '../../src/middleware/config';
import getAlternateLinksHeaderValue from '../../src/middleware/getAlternateLinksHeaderValue';
import {Pathnames} from '../../src/routing';
import {Pathnames} from '../routing';
import {receiveConfig} from './config';
import getAlternateLinksHeaderValue from './getAlternateLinksHeaderValue';

describe.each([{basePath: undefined}, {basePath: '/base'}])(
'basePath: $basePath',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {RequestCookies} from 'next/dist/compiled/@edge-runtime/cookies';
import {NextRequest, NextResponse} from 'next/server';
import {pathToRegexp} from 'path-to-regexp';
import {it, describe, vi, beforeEach, expect, Mock} from 'vitest';
import createMiddleware from '../../src/middleware';
import {Pathnames} from '../../src/routing';
import {COOKIE_LOCALE_NAME} from '../../src/shared/constants';
import createMiddleware from '../middleware';
import {Pathnames} from '../routing';
import {COOKIE_LOCALE_NAME} from '../shared/constants';

vi.mock('next/server', async (importActual) => {
const ActualNextServer = (await importActual()) as any;
Expand Down
8 changes: 4 additions & 4 deletions packages/next-intl/src/middleware/middleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function createMiddleware<
? domain.defaultLocale === locale
: locale === config.defaultLocale;

const domainConfigs =
const domainsConfig =
config.domains?.filter((curDomain) =>
isLocaleSupportedOnDomain(locale, curDomain)
) || [];
Expand All @@ -64,11 +64,11 @@ export default function createMiddleware<
function redirect(url: string, redirectDomain?: string) {
const urlObj = new URL(normalizeTrailingSlash(url), request.url);

if (domainConfigs.length > 0 && !redirectDomain) {
if (domainsConfig.length > 0 && !redirectDomain) {
const bestMatchingDomain = getBestMatchingDomain(
domain,
locale,
domainConfigs
domainsConfig
);
if (bestMatchingDomain) {
redirectDomain = bestMatchingDomain.domain;
Expand Down Expand Up @@ -237,7 +237,7 @@ export default function createMiddleware<
const pathDomain = getBestMatchingDomain(
domain,
pathnameMatch.locale,
domainConfigs
domainsConfig
);

if (domain?.domain !== pathDomain?.domain && !hasUnknownHost) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it} from 'vitest';
import {getAcceptLanguageLocale} from '../../src/middleware/resolveLocale';
import {getAcceptLanguageLocale} from './resolveLocale';

describe('getAcceptLanguageLocale', () => {
it('resolves a more specific locale to a generic one', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/next-intl/src/middleware/resolveLocale.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {match} from '@formatjs/intl-localematcher';
import Negotiator from 'negotiator';
import {RequestCookies} from 'next/dist/server/web/spec-extension/cookies';
import {Locales, DomainConfig, Pathnames} from '../routing/types';
import {
Locales,
Pathnames,
DomainsConfig,
DomainConfig
} from '../routing/types';
import {COOKIE_LOCALE_NAME} from '../shared/constants';
import {MiddlewareRoutingConfig} from './config';
import {getHost, getPathnameMatch, isLocaleSupportedOnDomain} from './utils';

function findDomainFromHost<AppLocales extends Locales>(
requestHeaders: Headers,
domains: Array<DomainConfig<AppLocales>>
domains: DomainsConfig<AppLocales>
) {
let host = getHost(requestHeaders);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getInternalTemplate,
getNormalizedPathname,
getRouteParams
} from '../../src/middleware/utils';
} from './utils';

describe('getNormalizedPathname', () => {
it('should return the normalized pathname', () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/next-intl/src/middleware/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
Locales,
LocalePrefixConfigVerbose,
DomainConfig,
Pathnames
Pathnames,
DomainsConfig
} from '../routing/types';
import {
getLocalePrefix,
Expand Down Expand Up @@ -238,7 +239,7 @@ export function isLocaleSupportedOnDomain<AppLocales extends Locales>(
export function getBestMatchingDomain<AppLocales extends Locales>(
curHostDomain: DomainConfig<AppLocales> | undefined,
locale: string,
domainConfigs: Array<DomainConfig<AppLocales>>
domainsConfig: DomainsConfig<AppLocales>
) {
let domainConfig;

Expand All @@ -249,12 +250,12 @@ export function getBestMatchingDomain<AppLocales extends Locales>(

// Prio 2: Use alternative domain with matching default locale
if (!domainConfig) {
domainConfig = domainConfigs.find((cur) => cur.defaultLocale === locale);
domainConfig = domainsConfig.find((cur) => cur.defaultLocale === locale);
}

// Prio 3: Use alternative domain with restricted matching locale
if (!domainConfig) {
domainConfig = domainConfigs.find(
domainConfig = domainsConfig.find(
(cur) => cur.locales != null && cur.locales.includes(locale)
);
}
Expand All @@ -266,7 +267,7 @@ export function getBestMatchingDomain<AppLocales extends Locales>(

// Prio 5: Use alternative domain that supports all locales
if (!domainConfig) {
domainConfig = domainConfigs.find((cur) => !cur.locales);
domainConfig = domainsConfig.find((cur) => !cur.locales);
}

return domainConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
import React from 'react';
import {renderToString} from 'react-dom/server';
import {it, describe, vi, expect, beforeEach} from 'vitest';
import createLocalizedPathnamesNavigationClient from '../../src/navigation/react-client/createLocalizedPathnamesNavigation';
import createLocalizedPathnamesNavigationServer from '../../src/navigation/react-server/createLocalizedPathnamesNavigation';
import BaseLink from '../../src/navigation/shared/BaseLink';
import {Pathnames} from '../../src/routing';
import {getRequestLocale} from '../../src/server/react-server/RequestLocale';
import {getLocalePrefix} from '../../src/shared/utils';
import {Pathnames} from '../routing';
import {getRequestLocale} from '../server/react-server/RequestLocale';
import {getLocalePrefix} from '../shared/utils';
import createLocalizedPathnamesNavigationClient from './react-client/createLocalizedPathnamesNavigation';
import createLocalizedPathnamesNavigationServer from './react-server/createLocalizedPathnamesNavigation';
import BaseLink from './shared/BaseLink';

vi.mock('next/navigation', async () => {
const actual = await vi.importActual('next/navigation');
Expand Down
Loading

0 comments on commit 11262b8

Please sign in to comment.