From 6aad3ec6ae61edaca5787152475ed99ad5c14bd4 Mon Sep 17 00:00:00 2001 From: abhishake1 Date: Mon, 29 Apr 2024 13:24:32 +0000 Subject: [PATCH 1/6] remove unnecessary files --- examples/app-dir-mdx/pnpm-lock.yaml | 336 ++++++++++++++++++ .../next/src/client/components/redirect.ts | 159 +++++---- .../e2e/app-dir/navigation/navigation.test.ts | 16 + 3 files changed, 433 insertions(+), 78 deletions(-) create mode 100644 examples/app-dir-mdx/pnpm-lock.yaml diff --git a/examples/app-dir-mdx/pnpm-lock.yaml b/examples/app-dir-mdx/pnpm-lock.yaml new file mode 100644 index 0000000000000..e3d9cb867b4ce --- /dev/null +++ b/examples/app-dir-mdx/pnpm-lock.yaml @@ -0,0 +1,336 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +dependencies: + '@next/mdx': + specifier: latest + version: 14.2.3 + '@types/mdx': + specifier: 2.0.3 + version: 2.0.3 + '@types/node': + specifier: 18.11.18 + version: 18.11.18 + '@types/react': + specifier: 18.2.8 + version: 18.2.8 + '@types/react-dom': + specifier: 18.0.10 + version: 18.0.10 + next: + specifier: latest + version: 14.2.3(react-dom@18.2.0)(react@18.2.0) + react: + specifier: 18.2.0 + version: 18.2.0 + react-dom: + specifier: 18.2.0 + version: 18.2.0(react@18.2.0) + typescript: + specifier: 4.9.5 + version: 4.9.5 + +packages: + + /@next/env@14.2.3: + resolution: {integrity: sha512-W7fd7IbkfmeeY2gXrzJYDx8D2lWKbVoTIj1o1ScPHNzvp30s1AuoEFSdr39bC5sjxJaxTtq3OTCZboNp0lNWHA==} + dev: false + + /@next/mdx@14.2.3: + resolution: {integrity: sha512-oVz7BWpoLQ9dKvCKxPIX9X6BILPTrpTJnYDn2lAsZvK7J9Ela6xNm57vNwgZ8q7xw1THSDdSlbPNgIalM7U/+A==} + peerDependencies: + '@mdx-js/loader': '>=0.15.0' + '@mdx-js/react': '>=0.15.0' + peerDependenciesMeta: + '@mdx-js/loader': + optional: true + '@mdx-js/react': + optional: true + dependencies: + source-map: 0.7.4 + dev: false + + /@next/swc-darwin-arm64@14.2.3: + resolution: {integrity: sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@next/swc-darwin-x64@14.2.3: + resolution: {integrity: sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-arm64-gnu@14.2.3: + resolution: {integrity: sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-arm64-musl@14.2.3: + resolution: {integrity: sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-x64-gnu@14.2.3: + resolution: {integrity: sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-linux-x64-musl@14.2.3: + resolution: {integrity: sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@next/swc-win32-arm64-msvc@14.2.3: + resolution: {integrity: sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@next/swc-win32-ia32-msvc@14.2.3: + resolution: {integrity: sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==} + engines: {node: '>= 10'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@next/swc-win32-x64-msvc@14.2.3: + resolution: {integrity: sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@swc/counter@0.1.3: + resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} + dev: false + + /@swc/helpers@0.5.5: + resolution: {integrity: sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==} + dependencies: + '@swc/counter': 0.1.3 + tslib: 2.6.2 + dev: false + + /@types/mdx@2.0.3: + resolution: {integrity: sha512-IgHxcT3RC8LzFLhKwP3gbMPeaK7BM9eBH46OdapPA7yvuIUJ8H6zHZV53J8hGZcTSnt95jANt+rTBNUUc22ACQ==} + dev: false + + /@types/node@18.11.18: + resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==} + dev: false + + /@types/prop-types@15.7.12: + resolution: {integrity: sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==} + dev: false + + /@types/react-dom@18.0.10: + resolution: {integrity: sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==} + dependencies: + '@types/react': 18.2.8 + dev: false + + /@types/react@18.2.8: + resolution: {integrity: sha512-lTyWUNrd8ntVkqycEEplasWy2OxNlShj3zqS0LuB1ENUGis5HodmhM7DtCoUGbxj3VW/WsGA0DUhpG6XrM7gPA==} + dependencies: + '@types/prop-types': 15.7.12 + '@types/scheduler': 0.23.0 + csstype: 3.1.3 + dev: false + + /@types/scheduler@0.23.0: + resolution: {integrity: sha512-YIoDCTH3Af6XM5VuwGG/QL/CJqga1Zm3NkU3HZ4ZHK2fRMPYP1VczsTUqtsf43PH/iJNVlPHAo2oWX7BSdB2Hw==} + dev: false + + /busboy@1.6.0: + resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} + engines: {node: '>=10.16.0'} + dependencies: + streamsearch: 1.1.0 + dev: false + + /caniuse-lite@1.0.30001613: + resolution: {integrity: sha512-BNjJULJfOONQERivfxte7alLfeLW4QnwHvNW4wEcLEbXfV6VSCYvr+REbf2Sojv8tC1THpjPXBxWgDbq4NtLWg==} + dev: false + + /client-only@0.0.1: + resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} + dev: false + + /csstype@3.1.3: + resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + dev: false + + /graceful-fs@4.2.11: + resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + dev: false + + /js-tokens@4.0.0: + resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} + dev: false + + /loose-envify@1.4.0: + resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} + hasBin: true + dependencies: + js-tokens: 4.0.0 + dev: false + + /nanoid@3.3.7: + resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + dev: false + + /next@14.2.3(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-dowFkFTR8v79NPJO4QsBUtxv0g9BrS/phluVpMAt2ku7H+cbcBJlopXjkWlwxrk/xGqMemr7JkGPGemPrLLX7A==} + engines: {node: '>=18.17.0'} + hasBin: true + peerDependencies: + '@opentelemetry/api': ^1.1.0 + '@playwright/test': ^1.41.2 + react: ^18.2.0 + react-dom: ^18.2.0 + sass: ^1.3.0 + peerDependenciesMeta: + '@opentelemetry/api': + optional: true + '@playwright/test': + optional: true + sass: + optional: true + dependencies: + '@next/env': 14.2.3 + '@swc/helpers': 0.5.5 + busboy: 1.6.0 + caniuse-lite: 1.0.30001613 + graceful-fs: 4.2.11 + postcss: 8.4.31 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + styled-jsx: 5.1.1(react@18.2.0) + optionalDependencies: + '@next/swc-darwin-arm64': 14.2.3 + '@next/swc-darwin-x64': 14.2.3 + '@next/swc-linux-arm64-gnu': 14.2.3 + '@next/swc-linux-arm64-musl': 14.2.3 + '@next/swc-linux-x64-gnu': 14.2.3 + '@next/swc-linux-x64-musl': 14.2.3 + '@next/swc-win32-arm64-msvc': 14.2.3 + '@next/swc-win32-ia32-msvc': 14.2.3 + '@next/swc-win32-x64-msvc': 14.2.3 + transitivePeerDependencies: + - '@babel/core' + - babel-plugin-macros + dev: false + + /picocolors@1.0.0: + resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} + dev: false + + /postcss@8.4.31: + resolution: {integrity: sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==} + engines: {node: ^10 || ^12 || >=14} + dependencies: + nanoid: 3.3.7 + picocolors: 1.0.0 + source-map-js: 1.2.0 + dev: false + + /react-dom@18.2.0(react@18.2.0): + resolution: {integrity: sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==} + peerDependencies: + react: ^18.2.0 + dependencies: + loose-envify: 1.4.0 + react: 18.2.0 + scheduler: 0.23.2 + dev: false + + /react@18.2.0: + resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} + engines: {node: '>=0.10.0'} + dependencies: + loose-envify: 1.4.0 + dev: false + + /scheduler@0.23.2: + resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} + dependencies: + loose-envify: 1.4.0 + dev: false + + /source-map-js@1.2.0: + resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==} + engines: {node: '>=0.10.0'} + dev: false + + /source-map@0.7.4: + resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==} + engines: {node: '>= 8'} + dev: false + + /streamsearch@1.1.0: + resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} + engines: {node: '>=10.0.0'} + dev: false + + /styled-jsx@5.1.1(react@18.2.0): + resolution: {integrity: sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==} + engines: {node: '>= 12.0.0'} + peerDependencies: + '@babel/core': '*' + babel-plugin-macros: '*' + react: '>= 16.8.0 || 17.x.x || ^18.0.0-0' + peerDependenciesMeta: + '@babel/core': + optional: true + babel-plugin-macros: + optional: true + dependencies: + client-only: 0.0.1 + react: 18.2.0 + dev: false + + /tslib@2.6.2: + resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + dev: false + + /typescript@4.9.5: + resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: false diff --git a/packages/next/src/client/components/redirect.ts b/packages/next/src/client/components/redirect.ts index 162bea53944b8..8a92fd9c7eb76 100644 --- a/packages/next/src/client/components/redirect.ts +++ b/packages/next/src/client/components/redirect.ts @@ -6,27 +6,27 @@ import { RedirectStatusCode } from './redirect-status-code' const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT' export enum RedirectType { - push = 'push', - replace = 'replace', + push = 'push', + replace = 'replace', } export type RedirectError = Error & { - digest: `${typeof REDIRECT_ERROR_CODE};${RedirectType};${U};${RedirectStatusCode};` - mutableCookies: ResponseCookies + digest: `${typeof REDIRECT_ERROR_CODE};${RedirectType};${U};${RedirectStatusCode};` + mutableCookies: ResponseCookies } export function getRedirectError( - url: string, - type: RedirectType, - statusCode: RedirectStatusCode = RedirectStatusCode.TemporaryRedirect + url: string, + type: RedirectType, + statusCode: RedirectStatusCode = RedirectStatusCode.TemporaryRedirect ): RedirectError { - const error = new Error(REDIRECT_ERROR_CODE) as RedirectError - error.digest = `${REDIRECT_ERROR_CODE};${type};${url};${statusCode};` - const requestStore = requestAsyncStorage.getStore() - if (requestStore) { - error.mutableCookies = requestStore.mutableCookies - } - return error + const error = new Error(REDIRECT_ERROR_CODE) as RedirectError + error.digest = `${REDIRECT_ERROR_CODE};${type};${url};${statusCode};` + const requestStore = requestAsyncStorage.getStore() + if (requestStore) { + error.mutableCookies = requestStore.mutableCookies + } + return error } /** @@ -41,21 +41,21 @@ export function getRedirectError( * Read more: [Next.js Docs: `redirect`](https://nextjs.org/docs/app/api-reference/functions/redirect) */ export function redirect( - /** The URL to redirect to */ - url: string, - type: RedirectType = RedirectType.replace + /** The URL to redirect to */ + url: string, + type: RedirectType = RedirectType.replace ): never { - const actionStore = actionAsyncStorage.getStore() - throw getRedirectError( - url, - type, - // If we're in an action, we want to use a 303 redirect - // as we don't want the POST request to follow the redirect, - // as it could result in erroneous re-submissions. - actionStore?.isAction - ? RedirectStatusCode.SeeOther - : RedirectStatusCode.TemporaryRedirect - ) + const actionStore = actionAsyncStorage.getStore() + throw getRedirectError( + url, + type, + // If we're in an action, we want to use a 303 redirect + // as we don't want the POST request to follow the redirect, + // as it could result in erroneous re-submissions. + actionStore?.isAction + ? RedirectStatusCode.SeeOther + : RedirectStatusCode.TemporaryRedirect + ) } /** @@ -70,21 +70,21 @@ export function redirect( * Read more: [Next.js Docs: `redirect`](https://nextjs.org/docs/app/api-reference/functions/redirect) */ export function permanentRedirect( - /** The URL to redirect to */ - url: string, - type: RedirectType = RedirectType.replace + /** The URL to redirect to */ + url: string, + type: RedirectType = RedirectType.replace ): never { - const actionStore = actionAsyncStorage.getStore() - throw getRedirectError( - url, - type, - // If we're in an action, we want to use a 303 redirect - // as we don't want the POST request to follow the redirect, - // as it could result in erroneous re-submissions. - actionStore?.isAction - ? RedirectStatusCode.SeeOther - : RedirectStatusCode.PermanentRedirect - ) + const actionStore = actionAsyncStorage.getStore() + throw getRedirectError( + url, + type, + // If we're in an action, we want to use a 303 redirect + // as we don't want the POST request to follow the redirect, + // as it could result in erroneous re-submissions. + actionStore?.isAction + ? RedirectStatusCode.SeeOther + : RedirectStatusCode.PermanentRedirect + ) } /** @@ -95,28 +95,31 @@ export function permanentRedirect( * @returns true if the error is a redirect error */ export function isRedirectError( - error: unknown + error: unknown ): error is RedirectError { - if ( - typeof error !== 'object' || - error === null || - !('digest' in error) || - typeof error.digest !== 'string' - ) { - return false - } - - const [errorCode, type, destination, status] = error.digest.split(';', 4) - - const statusCode = Number(status) - - return ( - errorCode === REDIRECT_ERROR_CODE && - (type === 'replace' || type === 'push') && - typeof destination === 'string' && - !isNaN(statusCode) && - statusCode in RedirectStatusCode - ) + if ( + typeof error !== 'object' || + error === null || + !('digest' in error) || + typeof error.digest !== 'string' + ) { + return false + } + + const digest = error.digest.split(';') + const [errorCode, type] = digest + const destination = digest.slice(2, -2).join(';') + const status = digest.at(-2) + + const statusCode = Number(status) + + return ( + errorCode === REDIRECT_ERROR_CODE && + (type === 'replace' || type === 'push') && + typeof destination === 'string' && + !isNaN(statusCode) && + statusCode in RedirectStatusCode + ) } /** @@ -127,32 +130,32 @@ export function isRedirectError( * @return the url if the error was a redirect error */ export function getURLFromRedirectError( - error: RedirectError + error: RedirectError ): U export function getURLFromRedirectError(error: unknown): string | null { - if (!isRedirectError(error)) return null + if (!isRedirectError(error)) return null - // Slices off the beginning of the digest that contains the code and the - // separating ';'. - return error.digest.split(';', 3)[2] + // Slices off the beginning of the digest that contains the code and the + // separating ';'. + return error.digest.split(';').slice(2, -2).join(";") } export function getRedirectTypeFromError( - error: RedirectError + error: RedirectError ): RedirectType { - if (!isRedirectError(error)) { - throw new Error('Not a redirect error') - } + if (!isRedirectError(error)) { + throw new Error('Not a redirect error') + } - return error.digest.split(';', 2)[1] as RedirectType + return error.digest.split(';', 2)[1] as RedirectType } export function getRedirectStatusCodeFromError( - error: RedirectError + error: RedirectError ): number { - if (!isRedirectError(error)) { - throw new Error('Not a redirect error') - } + if (!isRedirectError(error)) { + throw new Error('Not a redirect error') + } - return Number(error.digest.split(';', 4)[3]) + return Number(error.digest.split(';').at(-2)) } diff --git a/test/e2e/app-dir/navigation/navigation.test.ts b/test/e2e/app-dir/navigation/navigation.test.ts index a8188f840d10c..4ac1959745103 100644 --- a/test/e2e/app-dir/navigation/navigation.test.ts +++ b/test/e2e/app-dir/navigation/navigation.test.ts @@ -24,6 +24,22 @@ describe('app dir - navigation', () => { expect(url.searchParams.toString()).toMatchInlineSnapshot(`"a=b&c=d"`) }) + it('should set query with semicolon correctly', async () => { + const browser = await next.browser('/') + expect(await browser.elementById('query').text()).toMatchInlineSnapshot( + `""` + ) + + await browser.elementById('set-query').click() + + await retry(() => + expect(browser.elementById('query').text()).resolves.toEqual('a=b;c') + ) + + const url = new URL(await browser.url()) + expect(url.searchParams.toString()).toMatchInlineSnapshot(`"a=b;c"`) + }) + it('should handle unicode search params', async () => { const requests: Array<{ pathname: string From 47669fac5ef9cb372cefedc7f131e059f918cd2d Mon Sep 17 00:00:00 2001 From: "onFire(Abhi)" <40654066+AbhiShake1@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:33:40 +0000 Subject: [PATCH 2/6] Delete examples/app-dir-mdx/pnpm-lock.yaml --- examples/app-dir-mdx/pnpm-lock.yaml | 336 ---------------------------- 1 file changed, 336 deletions(-) delete mode 100644 examples/app-dir-mdx/pnpm-lock.yaml diff --git a/examples/app-dir-mdx/pnpm-lock.yaml b/examples/app-dir-mdx/pnpm-lock.yaml deleted file mode 100644 index e3d9cb867b4ce..0000000000000 --- a/examples/app-dir-mdx/pnpm-lock.yaml +++ /dev/null @@ -1,336 +0,0 @@ -lockfileVersion: '6.0' - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - -dependencies: - '@next/mdx': - specifier: latest - version: 14.2.3 - '@types/mdx': - specifier: 2.0.3 - version: 2.0.3 - '@types/node': - specifier: 18.11.18 - version: 18.11.18 - '@types/react': - specifier: 18.2.8 - version: 18.2.8 - '@types/react-dom': - specifier: 18.0.10 - version: 18.0.10 - next: - specifier: latest - version: 14.2.3(react-dom@18.2.0)(react@18.2.0) - react: - specifier: 18.2.0 - version: 18.2.0 - react-dom: - specifier: 18.2.0 - version: 18.2.0(react@18.2.0) - typescript: - specifier: 4.9.5 - version: 4.9.5 - -packages: - - /@next/env@14.2.3: - resolution: {integrity: sha512-W7fd7IbkfmeeY2gXrzJYDx8D2lWKbVoTIj1o1ScPHNzvp30s1AuoEFSdr39bC5sjxJaxTtq3OTCZboNp0lNWHA==} - dev: false - - /@next/mdx@14.2.3: - resolution: {integrity: sha512-oVz7BWpoLQ9dKvCKxPIX9X6BILPTrpTJnYDn2lAsZvK7J9Ela6xNm57vNwgZ8q7xw1THSDdSlbPNgIalM7U/+A==} - peerDependencies: - '@mdx-js/loader': '>=0.15.0' - '@mdx-js/react': '>=0.15.0' - peerDependenciesMeta: - '@mdx-js/loader': - optional: true - '@mdx-js/react': - optional: true - dependencies: - source-map: 0.7.4 - dev: false - - /@next/swc-darwin-arm64@14.2.3: - resolution: {integrity: sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - /@next/swc-darwin-x64@14.2.3: - resolution: {integrity: sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==} - engines: {node: '>= 10'} - cpu: [x64] - os: [darwin] - requiresBuild: true - dev: false - optional: true - - /@next/swc-linux-arm64-gnu@14.2.3: - resolution: {integrity: sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@next/swc-linux-arm64-musl@14.2.3: - resolution: {integrity: sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@next/swc-linux-x64-gnu@14.2.3: - resolution: {integrity: sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@next/swc-linux-x64-musl@14.2.3: - resolution: {integrity: sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==} - engines: {node: '>= 10'} - cpu: [x64] - os: [linux] - requiresBuild: true - dev: false - optional: true - - /@next/swc-win32-arm64-msvc@14.2.3: - resolution: {integrity: sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==} - engines: {node: '>= 10'} - cpu: [arm64] - os: [win32] - requiresBuild: true - dev: false - optional: true - - /@next/swc-win32-ia32-msvc@14.2.3: - resolution: {integrity: sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==} - engines: {node: '>= 10'} - cpu: [ia32] - os: [win32] - requiresBuild: true - dev: false - optional: true - - /@next/swc-win32-x64-msvc@14.2.3: - resolution: {integrity: sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==} - engines: {node: '>= 10'} - cpu: [x64] - os: [win32] - requiresBuild: true - dev: false - optional: true - - /@swc/counter@0.1.3: - resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} - dev: false - - /@swc/helpers@0.5.5: - resolution: {integrity: sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==} - dependencies: - '@swc/counter': 0.1.3 - tslib: 2.6.2 - dev: false - - /@types/mdx@2.0.3: - resolution: {integrity: sha512-IgHxcT3RC8LzFLhKwP3gbMPeaK7BM9eBH46OdapPA7yvuIUJ8H6zHZV53J8hGZcTSnt95jANt+rTBNUUc22ACQ==} - dev: false - - /@types/node@18.11.18: - resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==} - dev: false - - /@types/prop-types@15.7.12: - resolution: {integrity: sha512-5zvhXYtRNRluoE/jAp4GVsSduVUzNWKkOZrCDBWYtE7biZywwdC2AcEzg+cSMLFRfVgeAFqpfNabiPjxFddV1Q==} - dev: false - - /@types/react-dom@18.0.10: - resolution: {integrity: sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==} - dependencies: - '@types/react': 18.2.8 - dev: false - - /@types/react@18.2.8: - resolution: {integrity: sha512-lTyWUNrd8ntVkqycEEplasWy2OxNlShj3zqS0LuB1ENUGis5HodmhM7DtCoUGbxj3VW/WsGA0DUhpG6XrM7gPA==} - dependencies: - '@types/prop-types': 15.7.12 - '@types/scheduler': 0.23.0 - csstype: 3.1.3 - dev: false - - /@types/scheduler@0.23.0: - resolution: {integrity: sha512-YIoDCTH3Af6XM5VuwGG/QL/CJqga1Zm3NkU3HZ4ZHK2fRMPYP1VczsTUqtsf43PH/iJNVlPHAo2oWX7BSdB2Hw==} - dev: false - - /busboy@1.6.0: - resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} - engines: {node: '>=10.16.0'} - dependencies: - streamsearch: 1.1.0 - dev: false - - /caniuse-lite@1.0.30001613: - resolution: {integrity: sha512-BNjJULJfOONQERivfxte7alLfeLW4QnwHvNW4wEcLEbXfV6VSCYvr+REbf2Sojv8tC1THpjPXBxWgDbq4NtLWg==} - dev: false - - /client-only@0.0.1: - resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} - dev: false - - /csstype@3.1.3: - resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} - dev: false - - /graceful-fs@4.2.11: - resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} - dev: false - - /js-tokens@4.0.0: - resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - dev: false - - /loose-envify@1.4.0: - resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} - hasBin: true - dependencies: - js-tokens: 4.0.0 - dev: false - - /nanoid@3.3.7: - resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} - engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} - hasBin: true - dev: false - - /next@14.2.3(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-dowFkFTR8v79NPJO4QsBUtxv0g9BrS/phluVpMAt2ku7H+cbcBJlopXjkWlwxrk/xGqMemr7JkGPGemPrLLX7A==} - engines: {node: '>=18.17.0'} - hasBin: true - peerDependencies: - '@opentelemetry/api': ^1.1.0 - '@playwright/test': ^1.41.2 - react: ^18.2.0 - react-dom: ^18.2.0 - sass: ^1.3.0 - peerDependenciesMeta: - '@opentelemetry/api': - optional: true - '@playwright/test': - optional: true - sass: - optional: true - dependencies: - '@next/env': 14.2.3 - '@swc/helpers': 0.5.5 - busboy: 1.6.0 - caniuse-lite: 1.0.30001613 - graceful-fs: 4.2.11 - postcss: 8.4.31 - react: 18.2.0 - react-dom: 18.2.0(react@18.2.0) - styled-jsx: 5.1.1(react@18.2.0) - optionalDependencies: - '@next/swc-darwin-arm64': 14.2.3 - '@next/swc-darwin-x64': 14.2.3 - '@next/swc-linux-arm64-gnu': 14.2.3 - '@next/swc-linux-arm64-musl': 14.2.3 - '@next/swc-linux-x64-gnu': 14.2.3 - '@next/swc-linux-x64-musl': 14.2.3 - '@next/swc-win32-arm64-msvc': 14.2.3 - '@next/swc-win32-ia32-msvc': 14.2.3 - '@next/swc-win32-x64-msvc': 14.2.3 - transitivePeerDependencies: - - '@babel/core' - - babel-plugin-macros - dev: false - - /picocolors@1.0.0: - resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} - dev: false - - /postcss@8.4.31: - resolution: {integrity: sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==} - engines: {node: ^10 || ^12 || >=14} - dependencies: - nanoid: 3.3.7 - picocolors: 1.0.0 - source-map-js: 1.2.0 - dev: false - - /react-dom@18.2.0(react@18.2.0): - resolution: {integrity: sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==} - peerDependencies: - react: ^18.2.0 - dependencies: - loose-envify: 1.4.0 - react: 18.2.0 - scheduler: 0.23.2 - dev: false - - /react@18.2.0: - resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} - engines: {node: '>=0.10.0'} - dependencies: - loose-envify: 1.4.0 - dev: false - - /scheduler@0.23.2: - resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} - dependencies: - loose-envify: 1.4.0 - dev: false - - /source-map-js@1.2.0: - resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==} - engines: {node: '>=0.10.0'} - dev: false - - /source-map@0.7.4: - resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==} - engines: {node: '>= 8'} - dev: false - - /streamsearch@1.1.0: - resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} - engines: {node: '>=10.0.0'} - dev: false - - /styled-jsx@5.1.1(react@18.2.0): - resolution: {integrity: sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==} - engines: {node: '>= 12.0.0'} - peerDependencies: - '@babel/core': '*' - babel-plugin-macros: '*' - react: '>= 16.8.0 || 17.x.x || ^18.0.0-0' - peerDependenciesMeta: - '@babel/core': - optional: true - babel-plugin-macros: - optional: true - dependencies: - client-only: 0.0.1 - react: 18.2.0 - dev: false - - /tslib@2.6.2: - resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - dev: false - - /typescript@4.9.5: - resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} - engines: {node: '>=4.2.0'} - hasBin: true - dev: false From 941dc8a05e3035031da713928729f00e2002bd10 Mon Sep 17 00:00:00 2001 From: "onFire(Abhi)" <40654066+AbhiShake1@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:40:04 +0000 Subject: [PATCH 3/6] Update redirect.ts --- .../next/src/client/components/redirect.ts | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/packages/next/src/client/components/redirect.ts b/packages/next/src/client/components/redirect.ts index 8a92fd9c7eb76..0d4d5b67c53ed 100644 --- a/packages/next/src/client/components/redirect.ts +++ b/packages/next/src/client/components/redirect.ts @@ -6,27 +6,27 @@ import { RedirectStatusCode } from './redirect-status-code' const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT' export enum RedirectType { - push = 'push', - replace = 'replace', + push = 'push', + replace = 'replace', } export type RedirectError = Error & { - digest: `${typeof REDIRECT_ERROR_CODE};${RedirectType};${U};${RedirectStatusCode};` - mutableCookies: ResponseCookies + digest: `${typeof REDIRECT_ERROR_CODE};${RedirectType};${U};${RedirectStatusCode};` + mutableCookies: ResponseCookies } export function getRedirectError( - url: string, - type: RedirectType, - statusCode: RedirectStatusCode = RedirectStatusCode.TemporaryRedirect + url: string, + type: RedirectType, + statusCode: RedirectStatusCode = RedirectStatusCode.TemporaryRedirect ): RedirectError { - const error = new Error(REDIRECT_ERROR_CODE) as RedirectError - error.digest = `${REDIRECT_ERROR_CODE};${type};${url};${statusCode};` - const requestStore = requestAsyncStorage.getStore() - if (requestStore) { - error.mutableCookies = requestStore.mutableCookies - } - return error + const error = new Error(REDIRECT_ERROR_CODE) as RedirectError + error.digest = `${REDIRECT_ERROR_CODE};${type};${url};${statusCode};` + const requestStore = requestAsyncStorage.getStore() + if (requestStore) { + error.mutableCookies = requestStore.mutableCookies + } + return error } /** @@ -41,21 +41,21 @@ export function getRedirectError( * Read more: [Next.js Docs: `redirect`](https://nextjs.org/docs/app/api-reference/functions/redirect) */ export function redirect( - /** The URL to redirect to */ - url: string, - type: RedirectType = RedirectType.replace + /** The URL to redirect to */ + url: string, + type: RedirectType = RedirectType.replace ): never { - const actionStore = actionAsyncStorage.getStore() - throw getRedirectError( - url, - type, - // If we're in an action, we want to use a 303 redirect - // as we don't want the POST request to follow the redirect, - // as it could result in erroneous re-submissions. - actionStore?.isAction - ? RedirectStatusCode.SeeOther - : RedirectStatusCode.TemporaryRedirect - ) + const actionStore = actionAsyncStorage.getStore() + throw getRedirectError( + url, + type, + // If we're in an action, we want to use a 303 redirect + // as we don't want the POST request to follow the redirect, + // as it could result in erroneous re-submissions. + actionStore?.isAction + ? RedirectStatusCode.SeeOther + : RedirectStatusCode.TemporaryRedirect + ) } /** @@ -70,21 +70,21 @@ export function redirect( * Read more: [Next.js Docs: `redirect`](https://nextjs.org/docs/app/api-reference/functions/redirect) */ export function permanentRedirect( - /** The URL to redirect to */ - url: string, - type: RedirectType = RedirectType.replace + /** The URL to redirect to */ + url: string, + type: RedirectType = RedirectType.replace ): never { - const actionStore = actionAsyncStorage.getStore() - throw getRedirectError( - url, - type, - // If we're in an action, we want to use a 303 redirect - // as we don't want the POST request to follow the redirect, - // as it could result in erroneous re-submissions. - actionStore?.isAction - ? RedirectStatusCode.SeeOther - : RedirectStatusCode.PermanentRedirect - ) + const actionStore = actionAsyncStorage.getStore() + throw getRedirectError( + url, + type, + // If we're in an action, we want to use a 303 redirect + // as we don't want the POST request to follow the redirect, + // as it could result in erroneous re-submissions. + actionStore?.isAction + ? RedirectStatusCode.SeeOther + : RedirectStatusCode.PermanentRedirect + ) } /** @@ -95,31 +95,31 @@ export function permanentRedirect( * @returns true if the error is a redirect error */ export function isRedirectError( - error: unknown + error: unknown ): error is RedirectError { - if ( - typeof error !== 'object' || - error === null || - !('digest' in error) || - typeof error.digest !== 'string' - ) { - return false - } - - const digest = error.digest.split(';') - const [errorCode, type] = digest - const destination = digest.slice(2, -2).join(';') - const status = digest.at(-2) - - const statusCode = Number(status) - - return ( - errorCode === REDIRECT_ERROR_CODE && - (type === 'replace' || type === 'push') && - typeof destination === 'string' && - !isNaN(statusCode) && - statusCode in RedirectStatusCode - ) + if ( + typeof error !== 'object' || + error === null || + !('digest' in error) || + typeof error.digest !== 'string' + ) { + return false + } + + const digest = error.digest.split(';') + const [errorCode, type] = digest + const destination = digest.slice(2, -2).join(';') + const status = digest.at(-2) + + const statusCode = Number(status) + + return ( + errorCode === REDIRECT_ERROR_CODE && + (type === 'replace' || type === 'push') && + typeof destination === 'string' && + !isNaN(statusCode) && + statusCode in RedirectStatusCode + ) } /** @@ -133,15 +133,15 @@ export function getURLFromRedirectError( error: RedirectError ): U export function getURLFromRedirectError(error: unknown): string | null { - if (!isRedirectError(error)) return null + if (!isRedirectError(error)) return null - // Slices off the beginning of the digest that contains the code and the - // separating ';'. - return error.digest.split(';').slice(2, -2).join(";") + // Slices off the beginning of the digest that contains the code and the + // separating ';'. + return error.digest.split(';').slice(2, -2).join(";") } export function getRedirectTypeFromError( - error: RedirectError + error: RedirectError ): RedirectType { if (!isRedirectError(error)) { throw new Error('Not a redirect error') From c0d51261b1449c614dd9496ffc53facfd6ac442f Mon Sep 17 00:00:00 2001 From: "onFire(Abhi)" <40654066+AbhiShake1@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:42:03 +0000 Subject: [PATCH 4/6] Update redirect.ts --- .../next/src/client/components/redirect.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/next/src/client/components/redirect.ts b/packages/next/src/client/components/redirect.ts index 0d4d5b67c53ed..beda88f0612da 100644 --- a/packages/next/src/client/components/redirect.ts +++ b/packages/next/src/client/components/redirect.ts @@ -53,8 +53,8 @@ export function redirect( // as we don't want the POST request to follow the redirect, // as it could result in erroneous re-submissions. actionStore?.isAction - ? RedirectStatusCode.SeeOther - : RedirectStatusCode.TemporaryRedirect + ? RedirectStatusCode.SeeOther + : RedirectStatusCode.TemporaryRedirect ) } @@ -76,14 +76,14 @@ export function permanentRedirect( ): never { const actionStore = actionAsyncStorage.getStore() throw getRedirectError( - url, - type, - // If we're in an action, we want to use a 303 redirect - // as we don't want the POST request to follow the redirect, - // as it could result in erroneous re-submissions. - actionStore?.isAction - ? RedirectStatusCode.SeeOther - : RedirectStatusCode.PermanentRedirect + url, + type, + // If we're in an action, we want to use a 303 redirect + // as we don't want the POST request to follow the redirect, + // as it could result in erroneous re-submissions. + actionStore?.isAction + ? RedirectStatusCode.SeeOther + : RedirectStatusCode.PermanentRedirect ) } @@ -130,7 +130,7 @@ export function isRedirectError( * @return the url if the error was a redirect error */ export function getURLFromRedirectError( - error: RedirectError + error: RedirectError ): U export function getURLFromRedirectError(error: unknown): string | null { if (!isRedirectError(error)) return null @@ -143,15 +143,15 @@ export function getURLFromRedirectError(error: unknown): string | null { export function getRedirectTypeFromError( error: RedirectError ): RedirectType { - if (!isRedirectError(error)) { - throw new Error('Not a redirect error') - } + if (!isRedirectError(error)) { + throw new Error('Not a redirect error') + } - return error.digest.split(';', 2)[1] as RedirectType + return error.digest.split(';', 2)[1] as RedirectType } export function getRedirectStatusCodeFromError( - error: RedirectError + error: RedirectError ): number { if (!isRedirectError(error)) { throw new Error('Not a redirect error') From 90cfd79e1a7b319f3bb2b335a8e93142700ee2a2 Mon Sep 17 00:00:00 2001 From: "onFire(Abhi)" <40654066+AbhiShake1@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:42:53 +0000 Subject: [PATCH 5/6] Update redirect.ts --- packages/next/src/client/components/redirect.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/next/src/client/components/redirect.ts b/packages/next/src/client/components/redirect.ts index beda88f0612da..8c02c9399b661 100644 --- a/packages/next/src/client/components/redirect.ts +++ b/packages/next/src/client/components/redirect.ts @@ -153,9 +153,9 @@ export function getRedirectTypeFromError( export function getRedirectStatusCodeFromError( error: RedirectError ): number { - if (!isRedirectError(error)) { - throw new Error('Not a redirect error') - } + if (!isRedirectError(error)) { + throw new Error('Not a redirect error') + } - return Number(error.digest.split(';').at(-2)) + return Number(error.digest.split(';').at(-2)) } From beb36a065efbd915a3a4f623627c16ef89baae4b Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 30 Apr 2024 14:55:18 -0700 Subject: [PATCH 6/6] fix test/link --- packages/next/src/client/components/redirect.ts | 2 +- .../app-dir/navigation/app/redirect/semicolon/page.js | 7 +++++++ test/e2e/app-dir/navigation/navigation.test.ts | 11 +++-------- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 test/e2e/app-dir/navigation/app/redirect/semicolon/page.js diff --git a/packages/next/src/client/components/redirect.ts b/packages/next/src/client/components/redirect.ts index 8c02c9399b661..f75c2cd08588b 100644 --- a/packages/next/src/client/components/redirect.ts +++ b/packages/next/src/client/components/redirect.ts @@ -137,7 +137,7 @@ export function getURLFromRedirectError(error: unknown): string | null { // Slices off the beginning of the digest that contains the code and the // separating ';'. - return error.digest.split(';').slice(2, -2).join(";") + return error.digest.split(';').slice(2, -2).join(';') } export function getRedirectTypeFromError( diff --git a/test/e2e/app-dir/navigation/app/redirect/semicolon/page.js b/test/e2e/app-dir/navigation/app/redirect/semicolon/page.js new file mode 100644 index 0000000000000..e6219c56c7a19 --- /dev/null +++ b/test/e2e/app-dir/navigation/app/redirect/semicolon/page.js @@ -0,0 +1,7 @@ +import { redirect } from 'next/navigation' + +export const dynamic = 'force-dynamic' + +export default function Page() { + return redirect('/?a=b;c') +} diff --git a/test/e2e/app-dir/navigation/navigation.test.ts b/test/e2e/app-dir/navigation/navigation.test.ts index 4ac1959745103..a285f7ecb0227 100644 --- a/test/e2e/app-dir/navigation/navigation.test.ts +++ b/test/e2e/app-dir/navigation/navigation.test.ts @@ -25,19 +25,14 @@ describe('app dir - navigation', () => { }) it('should set query with semicolon correctly', async () => { - const browser = await next.browser('/') - expect(await browser.elementById('query').text()).toMatchInlineSnapshot( - `""` - ) - - await browser.elementById('set-query').click() + const browser = await next.browser('/redirect/semicolon') await retry(() => - expect(browser.elementById('query').text()).resolves.toEqual('a=b;c') + expect(browser.elementById('query').text()).resolves.toEqual('a=b%3Bc') ) const url = new URL(await browser.url()) - expect(url.searchParams.toString()).toMatchInlineSnapshot(`"a=b;c"`) + expect(url.searchParams.toString()).toBe('a=b%3Bc') }) it('should handle unicode search params', async () => {