From 03a4620432ff063b2b84f4dba5c49ae36b92fd73 Mon Sep 17 00:00:00 2001 From: Daniel Almaguer Date: Wed, 13 Nov 2024 02:14:41 -0600 Subject: [PATCH 1/3] fix: Correctly handle search params in redirects when using `trailingSlash: true` (#1537) `normalizeTrailingSlash` expects a `pathname` but it's getting pathname + search. This causes redirects to urls like `/users/?sort=asc/` --------- Co-authored-by: Jan Amann --- .../next-intl/src/middleware/middleware.test.tsx | 14 ++++++++++++++ packages/next-intl/src/middleware/middleware.tsx | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/next-intl/src/middleware/middleware.test.tsx b/packages/next-intl/src/middleware/middleware.test.tsx index 14aa25c5e..7449040eb 100644 --- a/packages/next-intl/src/middleware/middleware.test.tsx +++ b/packages/next-intl/src/middleware/middleware.test.tsx @@ -1125,6 +1125,20 @@ describe('prefix-based routing', () => { 'http://localhost:3000/en/' ); }); + + it('keeps search params when redirecting to a locale at the root', () => { + middleware(createMockRequest('/?sort=asc')); + expect(MockedNextResponse.redirect.mock.calls[0][0].toString()).toBe( + 'http://localhost:3000/en/?sort=asc' + ); + }); + + it('keeps search params when redirecting to a locale', () => { + middleware(createMockRequest('/users?sort=asc')); + expect(MockedNextResponse.redirect.mock.calls[0][0].toString()).toBe( + 'http://localhost:3000/en/users/?sort=asc' + ); + }); }); describe('localized pathnames', () => { diff --git a/packages/next-intl/src/middleware/middleware.tsx b/packages/next-intl/src/middleware/middleware.tsx index 6ed38e8e2..620bee462 100644 --- a/packages/next-intl/src/middleware/middleware.tsx +++ b/packages/next-intl/src/middleware/middleware.tsx @@ -120,7 +120,9 @@ export default function createMiddleware< } function redirect(url: string, redirectDomain?: string) { - const urlObj = new URL(normalizeTrailingSlash(url), request.url); + const urlObj = new URL(url, request.url); + + urlObj.pathname = normalizeTrailingSlash(urlObj.pathname); if (domainsConfig.length > 0 && !redirectDomain && domain) { const bestMatchingDomain = getBestMatchingDomain( From e7baf7194fd179163bcdee405bb00e49657f09b6 Mon Sep 17 00:00:00 2001 From: amannn Date: Wed, 13 Nov 2024 08:15:31 +0000 Subject: [PATCH 2/3] v3.25.1 --- CHANGELOG.md | 6 ++++++ lerna.json | 2 +- packages/next-intl/CHANGELOG.md | 6 ++++++ packages/next-intl/package.json | 2 +- packages/use-intl/CHANGELOG.md | 6 ++++++ packages/use-intl/package.json | 2 +- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67502048c..37fbf271f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 3.25.1 (2024-11-13) + +### Bug Fixes + +* Correctly handle search params in redirects when using `trailingSlash: true` ([#1537](https://github.com/amannn/next-intl/issues/1537)) ([03a4620](https://github.com/amannn/next-intl/commit/03a4620432ff063b2b84f4dba5c49ae36b92fd73)) – by @deini + ## 3.25.0 (2024-11-08) ### Features diff --git a/lerna.json b/lerna.json index aa2216697..7defc7868 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json", - "version": "3.25.0", + "version": "3.25.1", "packages": [ "packages/*" ], diff --git a/packages/next-intl/CHANGELOG.md b/packages/next-intl/CHANGELOG.md index c8666950a..cee0c5181 100644 --- a/packages/next-intl/CHANGELOG.md +++ b/packages/next-intl/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 3.25.1 (2024-11-13) + +### Bug Fixes + +* Correctly handle search params in redirects when using `trailingSlash: true` ([#1537](https://github.com/amannn/next-intl/issues/1537)) ([03a4620](https://github.com/amannn/next-intl/commit/03a4620432ff063b2b84f4dba5c49ae36b92fd73)) – by @deini + ## 3.25.0 (2024-11-08) ### Features diff --git a/packages/next-intl/package.json b/packages/next-intl/package.json index e1481c688..496ba804a 100644 --- a/packages/next-intl/package.json +++ b/packages/next-intl/package.json @@ -1,6 +1,6 @@ { "name": "next-intl", - "version": "3.25.0", + "version": "3.25.1", "sideEffects": false, "author": "Jan Amann ", "funding": [ diff --git a/packages/use-intl/CHANGELOG.md b/packages/use-intl/CHANGELOG.md index 42e6b8f2d..fe5e3bf1b 100644 --- a/packages/use-intl/CHANGELOG.md +++ b/packages/use-intl/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 3.25.1 (2024-11-13) + +### Bug Fixes + +* Correctly handle search params in redirects when using `trailingSlash: true` ([#1537](https://github.com/amannn/next-intl/issues/1537)) ([03a4620](https://github.com/amannn/next-intl/commit/03a4620432ff063b2b84f4dba5c49ae36b92fd73)) – by @deini + ## 3.25.0 (2024-11-08) ### Features diff --git a/packages/use-intl/package.json b/packages/use-intl/package.json index 949fd5e01..98122662e 100644 --- a/packages/use-intl/package.json +++ b/packages/use-intl/package.json @@ -1,6 +1,6 @@ { "name": "use-intl", - "version": "3.25.0", + "version": "3.25.1", "sideEffects": false, "author": "Jan Amann ", "description": "Internationalization (i18n) for React", From 140ef4613803ef4124b50c50eadd0d727f9fb306 Mon Sep 17 00:00:00 2001 From: Rudy Boutte <32516879+boutterudy@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:11:29 +0100 Subject: [PATCH 3/3] docs: clarify TypeScript version requirement and add troubleshooting for TypeScript error (#1538) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 🔍 Overview This PR enhances the **TypeScript Integration** and **Routing** sections of the `next-intl` documentation by: - Specifying **TypeScript version 5** or later as a requirement for compatibility with `next-intl`. - Adding a troubleshooting tip under the **Define routing** section to help developers resolve a common TypeScript error. --- ### 📄 Changes 1. **TypeScript Version Requirement**: - Updated the TypeScript Integration section to recommend **TypeScript version 5 or later** to prevent issues such as `TS2554: Expected 0 arguments, but got 1`. - This provides users with upfront guidance to avoid compatibility issues. 2. **New Troubleshooting Detail**: - Added a `Details` section in **Define routing** explaining how to resolve the `TS2554` TypeScript error by upgrading to TypeScript 5 or later. - This gives clear instructions on how to upgrade TypeScript if users encounter this error during setup. --- ### 🤔 Why This Update? While setting up `next-intl` with the code in the documentation, I encountered an error _(also found it [on Stackoverflow](https://stackoverflow.com/questions/79168391/next-intl-routing-ts-giving-ts2554-expected-0-arguments-but-got-1))_ due to using **TypeScript 4**. Upgrading to **TypeScript 5** resolved the issue. To help others avoid this confusion, I’ve added a clear version requirement and troubleshooting section to the documentation. --- ### 📌 Notes As this is my first Pull Request for `next-intl`, please let me know if I need to correct anything 🙏 --- docs/src/pages/docs/workflows/typescript.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/pages/docs/workflows/typescript.mdx b/docs/src/pages/docs/workflows/typescript.mdx index c7014a09f..1597b4b8e 100644 --- a/docs/src/pages/docs/workflows/typescript.mdx +++ b/docs/src/pages/docs/workflows/typescript.mdx @@ -115,7 +115,7 @@ declare global { If you're encountering problems, double check that: 1. Your interface uses the correct name. -2. You're using TypeScript version 4 or later. +2. You're using TypeScript version 5 or later. 3. You're using correct paths for all modules you're importing into your global declaration file. 4. Your type declaration file is included in `tsconfig.json`. 5. Your editor has loaded the most recent type declarations. When in doubt, you can restart.