From b13b700bab9e724e63003aabdb1cb20ba7289a19 Mon Sep 17 00:00:00 2001 From: Juhyeok Kang Date: Sun, 13 Oct 2024 20:44:40 +0900 Subject: [PATCH] fix(suspensive.org): resolve locale initialization issue (#1311) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Overview I address an issue where undefined locale URLs defaulted to 'en' in Nextra documentation. I've implemented Nextra's middleware to recognize locale cookies. https://github.com/user-attachments/assets/03a068df-feef-47f4-b505-532fb29da329 ### [AS-IS] - Custom middleware redirecting undefined locales to '/en' ### [TO-BE] - Use Nextra's built-in middleware - Exclude 'img' directory in matcher configuration - Prevents unnecessary middleware processing for image files, aligning with Nextra's example configuration (see [Nextra PR #3439](https://github.com/shuding/nextra/pull/3439/files#diff-e986406290c383f5b481ce7bc0136f142b96083e0807190d530561eea83bfc70R5-R7) `icon.svg`) ### Issue Nextra styles may appear broken in development. See [Issue #3357](https://github.com/shuding/nextra/issues/3357). Could you please confirm if you're experiencing this as well? 스크린샷 2024-10-13 오후 8 26 02 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests. --- docs/suspensive.org/package.json | 4 +- docs/suspensive.org/src/middleware.ts | 28 ++---------- pnpm-lock.yaml | 62 ++++++++++++++++----------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/docs/suspensive.org/package.json b/docs/suspensive.org/package.json index e8cced4fc..2dea958f2 100644 --- a/docs/suspensive.org/package.json +++ b/docs/suspensive.org/package.json @@ -30,8 +30,8 @@ "d3": "^7.9.0", "framer-motion": "^11.11.8", "next": "catalog:", - "nextra": "^3.0.8", - "nextra-theme-docs": "^3.0.8", + "nextra": "^3.0.11", + "nextra-theme-docs": "^3.0.11", "react": "catalog:react18", "react-dom": "catalog:react18", "remark-sandpack": "^0.0.5", diff --git a/docs/suspensive.org/src/middleware.ts b/docs/suspensive.org/src/middleware.ts index 7f4e87c34..915cb2064 100644 --- a/docs/suspensive.org/src/middleware.ts +++ b/docs/suspensive.org/src/middleware.ts @@ -1,27 +1,4 @@ -import { type NextRequest, NextResponse } from 'next/server' - -const PUBLIC_FILE = /\.(.*)$/ - -export function middleware(req: NextRequest) { - if ( - req.nextUrl.pathname.startsWith('/_next') || - req.nextUrl.pathname.includes('/api/') || - PUBLIC_FILE.test(req.nextUrl.pathname) - ) { - return - } - - if ( - !( - req.nextUrl.pathname.startsWith('/en') || - req.nextUrl.pathname.startsWith('/ko') - ) - ) { - return NextResponse.redirect( - new URL(`/en${req.nextUrl.pathname}${req.nextUrl.search}`, req.url) - ) - } -} +export { middleware } from 'nextra/locales' export const config = { matcher: [ @@ -31,7 +8,8 @@ export const config = { * - _next/static (static files) * - _next/image (image optimization files) * - favicon.ico (favicon file) + * - img (image files) */ - '/((?!api|_next/static|_next/image|favicon.ico).*)', + '/((?!api|_next/static|_next/image|favicon.ico|img).*)', ], } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3ddd46411..28a2c814c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -273,11 +273,11 @@ importers: specifier: 'catalog:' version: 14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) nextra: - specifier: ^3.0.8 - version: 3.0.8(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4) + specifier: ^3.0.11 + version: 3.0.11(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4) nextra-theme-docs: - specifier: ^3.0.8 - version: 3.0.8(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(nextra@3.0.8(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^3.0.11 + version: 3.0.11(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(nextra@3.0.11(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) react: specifier: catalog:react18 version: 18.3.1 @@ -2450,6 +2450,9 @@ packages: '@floating-ui/utils@0.2.8': resolution: {integrity: sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==} + '@formatjs/intl-localematcher@0.5.5': + resolution: {integrity: sha512-t5tOGMgZ/i5+ALl2/offNqAQq/lfUnKLEw0mXQI4N4bqpedhrSE+fyKLpwnd22sK0dif6AV+ufQcTsKShB9J1g==} + '@graphql-typed-document-node/core@3.2.0': resolution: {integrity: sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==} peerDependencies: @@ -8389,16 +8392,16 @@ packages: sass: optional: true - nextra-theme-docs@3.0.8: - resolution: {integrity: sha512-3kCc+01KPDolaUaxQD665a1bdy9ZN1HnC/42/7yL4GspAP7BSprKBvkU4rRz9xCFYIYbxDjq6NYV6FWuOnO94g==} + nextra-theme-docs@3.0.11: + resolution: {integrity: sha512-yRWVw5d9MDn0olgaZ1mEcMUOIkxtHce4lJLpkYo6YgPnrXvwO3wRLEry5zU4aWUUJGTfxkGOWcOgFqVFcOq7XA==} peerDependencies: next: '>=13' - nextra: 3.0.8 + nextra: 3.0.11 react: '>=18' react-dom: '>=18' - nextra@3.0.8: - resolution: {integrity: sha512-7YceCGQOPnEMtqIoDRuNg+BvUc4GpUTPJeZsuKEeJ9AwVgCFRPhCJZoDuGNkIEw3pKAqHUaWFm9JXFytHeBRUQ==} + nextra@3.0.11: + resolution: {integrity: sha512-P/YidS1aQHrMAHrEbX1skSrOv0T/SFwCaffVt5nSpV+mDgPTUmJXP992GZAarUIAYGKR07mYrfDiEegp6PNQvg==} engines: {node: '>=18'} peerDependencies: next: '>=13' @@ -10679,6 +10682,9 @@ packages: tslib@2.6.3: resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==} + tslib@2.7.0: + resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==} + tsup@8.3.0: resolution: {integrity: sha512-ALscEeyS03IomcuNdFdc0YWGVIkwH1Ws7nfTbAPuoILvEV2hpGQAY72LIOjglGo4ShWpZfpBqP/jpQVCzqYQag==} engines: {node: '>=18'} @@ -14875,6 +14881,10 @@ snapshots: '@floating-ui/utils@0.2.8': {} + '@formatjs/intl-localematcher@0.5.5': + dependencies: + tslib: 2.7.0 + '@graphql-typed-document-node/core@3.2.0(graphql@15.8.0)': dependencies: graphql: 15.8.0 @@ -15613,7 +15623,7 @@ snapshots: semver: 7.6.3 strip-ansi: 5.2.0 wcwidth: 1.0.1 - yaml: 2.5.0 + yaml: 2.5.1 transitivePeerDependencies: - encoding @@ -16117,7 +16127,7 @@ snapshots: '@swc/helpers@0.5.5': dependencies: '@swc/counter': 0.1.3 - tslib: 2.6.3 + tslib: 2.7.0 '@tanstack/match-sorter-utils@8.15.1': dependencies: @@ -16422,11 +16432,11 @@ snapshots: '@types/eslint-scope@3.7.7': dependencies: '@types/eslint': 9.6.0 - '@types/estree': 1.0.5 + '@types/estree': 1.0.6 '@types/eslint@9.6.0': dependencies: - '@types/estree': 1.0.5 + '@types/estree': 1.0.6 '@types/json-schema': 7.0.15 '@types/estree-jsx@1.0.5': @@ -17214,7 +17224,7 @@ snapshots: ast-types@0.15.2: dependencies: - tslib: 2.6.3 + tslib: 2.7.0 astral-regex@1.0.0: {} @@ -17644,7 +17654,7 @@ snapshots: camel-case@4.1.2: dependencies: pascal-case: 3.1.2 - tslib: 2.6.3 + tslib: 2.7.0 camelcase-css@2.0.1: {} @@ -18744,7 +18754,7 @@ snapshots: dot-case@3.0.4: dependencies: no-case: 3.0.4 - tslib: 2.6.3 + tslib: 2.7.0 dot-prop@5.3.0: dependencies: @@ -21670,7 +21680,7 @@ snapshots: lower-case@2.0.2: dependencies: - tslib: 2.6.3 + tslib: 2.7.0 lru-cache@10.4.3: {} @@ -22666,7 +22676,7 @@ snapshots: - '@babel/core' - babel-plugin-macros - nextra-theme-docs@3.0.8(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(nextra@3.0.8(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4))(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + nextra-theme-docs@3.0.11(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(nextra@3.0.11(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4))(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: '@headlessui/react': 2.1.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1) clsx: 2.1.1 @@ -22674,14 +22684,15 @@ snapshots: flexsearch: 0.7.43 next: 14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) next-themes: 0.3.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - nextra: 3.0.8(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4) + nextra: 3.0.11(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) scroll-into-view-if-needed: 3.1.0 zod: 3.23.8 - nextra@3.0.8(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4): + nextra@3.0.11(@types/react@18.3.11)(next@14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.5.4): dependencies: + '@formatjs/intl-localematcher': 0.5.5 '@headlessui/react': 2.1.9(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@mdx-js/mdx': 3.0.1 '@mdx-js/react': 3.0.1(@types/react@18.3.11)(react@18.3.1) @@ -22698,6 +22709,7 @@ snapshots: gray-matter: 4.0.3 hast-util-to-estree: 3.1.0 katex: 0.16.11 + negotiator: 0.6.3 next: 14.2.15(@babel/core@7.25.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) p-limit: 6.1.0 react: 18.3.1 @@ -22732,7 +22744,7 @@ snapshots: no-case@3.0.4: dependencies: lower-case: 2.0.2 - tslib: 2.6.3 + tslib: 2.7.0 nocache@3.0.4: {} @@ -23074,7 +23086,7 @@ snapshots: param-case@3.0.4: dependencies: dot-case: 3.0.4 - tslib: 2.6.3 + tslib: 2.7.0 parent-module@1.0.1: dependencies: @@ -23169,7 +23181,7 @@ snapshots: pascal-case@3.1.2: dependencies: no-case: 3.0.4 - tslib: 2.6.3 + tslib: 2.7.0 password-prompt@1.1.3: dependencies: @@ -23857,7 +23869,7 @@ snapshots: ast-types: 0.15.2 esprima: 4.0.1 source-map: 0.6.1 - tslib: 2.6.3 + tslib: 2.7.0 redent@3.0.0: dependencies: @@ -25197,6 +25209,8 @@ snapshots: tslib@2.6.3: {} + tslib@2.7.0: {} + tsup@8.3.0(jiti@1.21.6)(postcss@8.4.47)(typescript@5.5.4)(yaml@2.5.1): dependencies: bundle-require: 5.0.0(esbuild@0.23.0)