1. 07 Jul, 2022 8 commits
  2. 06 Jul, 2022 26 commits
    • JJ Kasper's avatar
      v12.2.1-canary.4 · 34117946
      JJ Kasper authored
      34117946
    • Tim Neutkens's avatar
      Implement new client-side router (#37551) · f1131413
      Tim Neutkens authored
      ## Client-side router for `app` directory
      
      This PR implements the new router that leverages React 18 concurrent features like Suspense and startTransition.
      It also integrates with React Server Components and builds on top of it to allow server-centric routing that only renders the part of the page that has to change.
      
      It's one of the pieces of the implementation of https://nextjs.org/blog/layouts-rfc.
      
      ## Details
      
      I'm going to document the differences with the current router here (will be reworked for the upgrade guide)
      
      ### Client-side cache
      
      In the current router we have an in-memory cache for getStaticProps data so that if you prefetch and then navigate to a route that has been prefetched it'll be near-instant. For getServerSideProps the behavior is different, any navigation to a page with getServerSideProps fetches the data again.
      
      In the new model the cache is a fundamental piece, it's more granular than at the page level and is set up to ensure consistency across concurrent renders. It can also be invalidated at any level.
      
      #### Push/Replace (also applies to next/link)
      
      The new router still has a `router.push` / `router.replace` method.
      
      There are a few differences in how it works though:
      
      - It only takes `href` as an argument, historically you had to provide `href` (the page path) and `as` (the actual url path) to do dynamic routing. In later versions of Next.js this is no longer required and in the majority of cases `as` was no longer needed. In the new router there's no way to reason about `href` vs `as` because there is no notion of "pages" in the browser.
      - Both methods now use `startTransition`, you can wrap these in your own `startTransition` to get `isPending`
      - The push/replace support concurrent rendering. When a render is bailed by clicking a different link to navigate to a completely different page that still works and doesn't cause race conditions.
      - Support for optimistic loading states when navigating
      
      ##### Hard/Soft push/replace
      
      Because of the client-side cache being reworked this now allows us to cover two cases: hard push and soft push.
      
      The main difference between the two is if the cache is reused while navigating. The default for `next/link` is a `hard` push which means that the part of the cache affected by the navigation will be invalidated, e.g. if you already navigated to `/dashboard` and you `router.push('/dashboard')` again it'll get the latest version. This is similar to the existing `getServerSideProps` handling.
      
      In case of a soft push (API to be defined but for testing added `router.softPush('/')`) it'll reuse the existing cache and not invalidate parts that are already filled in. In practice this means it's more like the `getStaticProps` client-side navigation because it does not fetch on navigation except if a part of the page is missing.
      
      #### Back/Forward navigation
      
      Back and Forward navigation ([popstate](https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event)) are always handled as a soft navigation, meaning that the cache is reused, this ensures back/forward navigation is near-instant when it's in the client-side cache. This will also allow back/forward navigation to be a high priority update instead of a transition as it is based on user interaction. Note: in this PR it still uses `startTransition` as there's no way to handle the high priority update suspending which happens in case of missing data in the cache. We're working with the React team on a solution for this particular case.
      
      ### Layouts
      
      Note: this section assumes you've read [The layouts RFC](https://nextjs.org/blog/layouts-rfc) and [React Server Components RFC](https://reactjs.org/blog/2020/12/21/data-fetching-with-react-server-components.html)
      
      React Server Components rendering leverages the Flight streaming mechanism in React 18, this allows sending a serializable representation of the rendered React tree on the server to the browser, the client-side React can use this serialized representation to render components client-side without the JavaScript being sent to the browser. This is one of the building blocks of Server Components. This allows a bunch of interesting features but for now I'll keep it to how it affects layouts.
      
      When you have a `app/dashboard/layout.js` and `app/dashboard/page.js` the page will render as children of the layout, when you add another page like `app/dashboard/integrations/page.js` that page falls under the dashboard layout as well. When client-side navigating the new router automatically figures out if the page you're navigating to can be a smaller render than the whole page, in this case `app/dashboard/page.js` and `app/dashboard/integrations/page.js` share the `app/dashboard/layout.js` so instead of rendering the whole page we render below the layout component, this means the layout itself does not get re-rendered, the layout's `getServerSideProps` would not be called, and the Flight response would only hold the result of `app/dashboard/integrations/page.js`, effectively giving you the smallest patch for the UI.
      
      ---
      
      Note: the commits in this PR were mostly work in progress to ensure it wasn't lost along the way. The implementation was reworked a bunch of times to where it is now.
      Co-authored-by: 's avatarJiachi Liu <4800338+huozhi@users.noreply.github.com>
      Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
      f1131413
    • Damien Simonin Feugas's avatar
      feat: build edge functions with node.js modules and fail at runtime (#38234) · 6e2c3821
      Damien Simonin Feugas authored
      ## What's in there?
      
      The Edge runtime [does not support Node.js modules](https://edge-runtime.vercel.app/features/available-apis#unsupported-apis).
      When building Next.js application, we currently fail the build when detecting node.js module imported from middleware.
      
      This is an blocker for using code that is conditionally loading node.js modules (based on platform/env detection), as @cramforce reported.
      
      This PR implements a new strategy where:
      - we can build such middleware/Edge API route code **with a warning**
      - we fail at run time, with graceful errors in dev (console & react-dev-overlay error)
      - we fail at run time, with console errors in production
      
      ## How to test?
      
      All cases are covered with integration tests.
      To try them live, create a simple app with a page, a `middleware.js` file and a `pages/api/route.js`file.
      Here are iconic examples:
      
      ### node.js modules
      ```js
      // middleware.js
      import { NextResponse } from 'next/server'
      // static
      import { basename } from 'path'
      
      export default async function middleware() {
        // dynamic
        const { basename } = await import('path')
        basename()
        return NextResponse.next()
      }
      
      export const config = { matcher: '/' }
      ```
      ```js
      // pags/api/route.js
      // static
      import { isAbsolute } from 'path'
      
      export default async function handle() {
        // dynamic
        const { isAbsolute } = await import('path')
        return Response.json({ useNodeModule: isAbsolute('/test') })
      }
      
      export const config = { runtime: 'experimental-edge' }
      ```
      
      Desired error (+ source code highlight in dev):
      
      > The edge runtime does not support Node.js 'path' module
      Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
      
      Desired warning at build time:
      
      > A Node.js module is loaded ('path' at line 2) which is not supported in the Edge Runtime.
      Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
      
      - [x]  in dev middleware, static, shows desired error on stderr
      - [x]  in dev route, static, shows desired error on stderr
      - [x]  in dev middleware, dynamic, shows desired error on stderr
      - [x]  in dev route, dynamic, shows desired error on stderr
      - [x]  in dev middleware, static, shows desired error on react error overlay
      - [x]  in dev route, static, shows desired error on react error overlay
      - [x]  in dev middleware, dynamic, shows desired error on react error overlay
      - [x]  in dev route, dynamic, shows desired error on react error overlay
      - [x]  builds middleware successfully, shows build warning, shows desired error on stderr on call
      - [x]  builds route successfully, shows build warning, shows desired error on stderr on call
      
      ### 3rd party modules not found
      
      ```js
      // middleware.js
      import { NextResponse } from 'next/server'
      // static
      import Unknown from 'unknown'
      
      export default async function middleware() {
        // dynamic
        const Unknown = await import('unknown')
        new Unknown()
        return NextResponse.next()
      }
      ```
      export const config = { matcher: '/' }
      ```
      ```js
      // pags/api/route.js
      // static
      import Unknown from 'unknown'
      
      export default async function handle() {
        // dynamic
        const Unknown = await import('unknown')
        return Response.json({ use3rdPartyModule: Unknown() })
      }
      
      export const config = { runtime: 'experimental-edge' }
      ```
      
      Desired error (+ source code highlight in dev):
      
      > Module not found: Can't resolve 'does-not-exist'
      Learn More: https://nextjs.org/docs/messages/module-not-found
      
      - [x]  in dev middleware, static, shows desired error on stderr
      - [x]  in dev route, static, shows desired error on stderr
      - [x]  in dev middleware, dynamic, shows desired error on stderr
      - [x]  in dev route, dynamic, shows desired error on stderr
      - [x]  in dev middleware, static, shows desired error on react error overlay
      - [x]  in dev route, static, shows desired error on react error overlay
      - [x]  in dev middleware, dynamic, shows desired error on react error overlay
      - [x]  in dev route, dynamic, shows desired error on react error overlay
      - [x]  fails to build middleware, with desired error on stderr
      - [x]  fails to build route, with desired error on stderr
      
      ### unused node.js modules
      ```js
      // middleware.js
      import { NextResponse } from 'next/server'
      
      export default async function middleware() {
        if (process.exit) {
          const { basename } = await import('path')
          basename()
        }
        return NextResponse.next()
      }
      ```
      ```js
      // pags/api/route.js
      export default async function handle() {
        if (process.exit) {
          const { basename } = await import('path')
          basename()
        }
        return Response.json({ useNodeModule: false })
      }
      
      export const config = { runtime: 'experimental-edge' }
      ```
      
      Desired warning at build time:
      
      > A Node.js module is loaded ('path' at line 2) which is not supported in the Edge Runtime.
      Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
      
      - [x]  invoke middleware in dev with no error
      - [x]  invoke route in dev with no error
      - [x]  builds successfully, shows build warning, invoke middleware with no error
      - [x]  builds successfully, shows build warning, invoke api-route with no error
      
      ## Notes to reviewers
      
      The strategy to implement this feature is to leverages webpack [externals](https://webpack.js.org/configuration/externals/#externals) and run a global `__unsupported_module()` function when using a node.js module from edge function's code.
      For the record, I tried using [webpack resolve.fallback](https://webpack.js.org/configuration/resolve/#resolvefallback) and [Webpack.IgnorePlugin](https://webpack.js.org/plugins/ignore-plugin/) but they do not allow throwing proper errors at runtime that would contain the loaded module name for reporting.
      
      `__unsupported_module()` is defined in `EdgeRuntime`, and returns a proxy that's throw on use (whether it's property access, function call, new operator... synchronous & promise-based styles).
      
      However there's an issue with error reporting: webpack does not includes the import lines in the generated sourcemaps, preventing from displaying useful errors.
      I extended our middleware-plugin to supplement the sourcemaps (when analyzing edge function code, it saves which module is imported from which file, together with line/column/source)
      
      The react-dev-overlay was adapted to look for this additional information when the caught error relates to modules, instead of looking at sourcemaps.
      
      I removed the previous mechanism (built by @nkzawa ) which caught webpack errors at built time to change the displayed error message (files `next/build/index.js`, `next/build/utils.ts` and `wellknown-errors-plugin`)
      6e2c3821
    • Max Proske's avatar
      chore(examples): Convert `blog` example to TypeScript (#38095) · 0f4333a5
      Max Proske authored
      Converted Blog example over to TypeScript to match the Contribution guidelines.
      
      I also simplified the example by removing `_document.js` and prettier from `package.json`.
      
      ## Documentation / Examples
      
      - [X] Make sure the linting passes by running `pnpm lint`
      - [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      0f4333a5
    • Zane Chua's avatar
      Update edge-runtime.md (#38271) · 3b3d249c
      Zane Chua authored
      * Update edge-runtime.md
      
      * Update docs/api-reference/edge-runtime.md
      
      * fix linting
      Co-authored-by: 's avatarLee Robinson <me@leerob.io>
      Co-authored-by: 's avatarBalázs Orbán <info@balazsorban.com>
      Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
      3b3d249c
    • Dustin Goodman's avatar
    • Marius Jørgensen's avatar
      Fix/update docs for swc styled components (#38280) · 3ae343fa
      Marius Jørgensen authored
      According to https://github.com/vercel/next.js/issues/30802 SWC transforms for `styled-components` were updated with support for `cssProp`, `fileName` and `namespace`. The docs only mention support for `ssr` and `displayName`.
      
      ## Documentation / Examples
      
      - [x] Make sure the linting passes by running `pnpm lint`
      3ae343fa
    • Rishabh Poddar's avatar
      Updates with-supertokens example (#38369) · b83107c3
      Rishabh Poddar authored
      * add-supertokens-to-authentication.md
      
      * bump supertokens deps
      
      * update SuperTokens Auth doc
      
      * Update docs/authentication.md
      Co-authored-by: 's avatarLee Robinson <me@leerob.io>
      
      * Update docs/authentication.md
      Co-authored-by: 's avatarLee Robinson <me@leerob.io>
      
      * updates supertokens dependency and optimises for serverless execution
      
      * runs prettier-fix
      
      * adds supertokens to 'Bring Your Own Database' section as well
      
      * does not show home page if not logged in
      
      * extracts config into its own file and calls it in all serverless functions
      
      * removes need for backend init in app.jsx
      
      * simplifies use of dynamic
      
      * refreshes page after getServerSideProps
      
      * removes unnecessary check in API
      
      * update to docs pertaining SuperTokens
      
      * adds placeholder secrets so that the UI loads on first run
      
      * changes to readme
      
      * updates version of supertokens frontend and backend SDK, and a few other fixes
      
      * Update docs/authentication.md
      Co-authored-by: 's avatarLee Robinson <me@leerob.io>
      
      * updates to readme for supertokens example
      
      * updates version of dependency
      
      * updates dependency version
      
      * updates to dependencies
      
      * removes unnecessary config on frontend
      
      * changes how redirection is done post signout
      
      * update to dependency
      
      * updates examples
      
      * updates code to use for new package
      
      * updates dependencies
      
      * updates auth-react package
      
      * with-supertokens example updated to use supertokens-node v7
      
      * updates dependency
      
      * updates supertokens-node version
      
      * Update examples/with-supertokens/package.json
      Co-authored-by: 's avatarLee Robinson <me@leerob.io>
      
      * updates based on check-examples.sh script
      
      * linter fix
      
      * updates supertokens-auth-react dependency version
      
      * adds development OAuth key to example
      
      * removes section from README
      
      * removes unnecessary file
      
      * updates dependency versions
      
      * with-supertokens: reduced bundle size by removing node lib from bundle
      
      Linting fix
      
      * Removed accidentally added config file
      
      * adds sign in with apple
      
      * extracted oauth keys to .env file
      
      * fixes node init issue race condition
      
      * removes unnecessary file
      
      * updates supertokens-auth-react dependency
      
      * updates superttokens-node dependency
      
      * adds a cap to react dependency
      
      * updates eslint-config-next version
      
      * removes unnecessary dev dependency
      
      * updates to latest version of supertokens-auth-react SDK
      
      * Updated nextjs in supertokens example
      
      * Update examples/with-supertokens/package.json
      
      * Update examples/with-supertokens/package.json
      
      * Update package.json
      
      * Update examples/with-supertokens/package.json
      Co-authored-by: 's avatarBalázs Orbán <info@balazsorban.com>
      
      * Update examples/with-supertokens/package.json
      Co-authored-by: 's avatarBalázs Orbán <info@balazsorban.com>
      
      * updates to supertokens-auth-react version
      
      * feat: update&improve ssr in with-supertokens
      
      * refactor: implement review feedback
      
      * refactor: moved everything into ProtectedPage to make Auth component usage clearer
      
      * refactor: implement review feedback
      
      * updates dependency version and uses nextjs router for navigation
      
      * removes prettier dendency in with-supertokens example app
      b83107c3
    • okmttdhr, okp's avatar
      Call Error.getInitialProps for the top level error (#21240) · 69f8024a
      okmttdhr, okp authored
      * fix: Call Error.getInitialProps to pass `err`
      
      * test: Call Error.getInitialPropsfoe the top level error
      
      * test: Update build output limit
      
      * test: Add tests for top level error
      
      * Revert "test: Call Error.getInitialPropsfoe the top level error"
      
      This reverts commit 81fa0c38c704ae6feb79a65eba316362bbebc939.
      
      * test: Fix failing test
      69f8024a
    • Gal Schlezinger's avatar
      [edge] enable edge compiler source maps by default (#38365) · 708688dd
      Gal Schlezinger authored
      since we no longer have a single compiler for browser & edge, we can enable
      source map generation by default for all edge functions. This would make it
      much easier to debug and understand what's happening when deploying to prod
      as the log statements will show us the actual code location instead of post
      bundling and minified location.
      
      This also removes the experimental flag as it's not needed anymore.
      708688dd
    • Shu Ding's avatar
      Add more CSS imports test cases (#38343) · f3969888
      Shu Ding authored
      
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [x] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      f3969888
    • Jiachi Liu's avatar
      Filter proper chunks from chunk group for client components (#38379) · a16d8dd4
      Jiachi Liu authored
      Client components might result in a page chunk or a standalone splitted chunk marked in flight manifest, this PR filters out the page chunk for standalone chunk so that while loading a client chunk (like for `next/link`) it won't load the page chunk to break the hydration. `chunk.ids` is not enough for getting required chunks, so we get the chunks from chunk group then filter the required ones.
      
      tests: Re-enable few previous rsc tests
      chore: refactor few webpack api usage
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [x] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      a16d8dd4
    • Maia Teegarden's avatar
      Enable swc minifier in create next apps (#38215) · f2b8a6b6
      Maia Teegarden authored
      
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      f2b8a6b6
    • JJ Kasper's avatar
      Replace pre-commit with husky (#38350) · 95731741
      JJ Kasper authored
      * Replace pre-commit with husky
      
      * update lock
      
      * actually update lock
      95731741
    • stefanprobst's avatar
      chore: shorten image blur svg placholder (#38157) · 6b4b0373
      stefanprobst authored
      
      
      trying to shorten the svg blur placeholder on `next/future/image`:
      
      - is the `xlink` namespace needed?
      - are self-closing tags allowed?
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      6b4b0373
    • Steven's avatar
      Revert "chore: remove workspace from `package.json` since we have `pnpm-works…" (#38376) · fb868605
      Steven authored
      Revert "chore: remove workspace from `package.json` since we have `pnpm-works… (#38166)"
      
      This reverts commit a37abc62.
      fb868605
    • Yohann MARTZOLFF's avatar
      Add example: with-apivideo-upload (#36050) · 27bfdec1
      Yohann MARTZOLFF authored
      * feat(app): Landing
      
      * feat(index): Add button to video view
      
      * Remove React stric mode
      
      * feat(index): Handle navigate with query params
      
      * feat(app): Create common style
      
      * feat(app): Video view
      
      * feat(video view): Add footer
      
      * feat(app): Add .env
      
      * feat(index): Hide upload button on progress
      
      * Update pages type
      
      * Change MyApp props type
      
      * feat(index): Add prod domain for fetching
      
      * update(app): CSS
      
      * update(index): Domain name
      
      * feat(index): Remove getSSProps
      
      * Update README
      
      * Update README
      
      * update(status): CSS
      
      * feat(index): Add link to GitHub repo
      
      * Remove static API key from .env
      
      * Lint
      
      * update(packages): next version
      
      * Lint + Prettier
      
      * Remove name & version from package.json
      
      * update: Rename .env.development -> .env.local.example
      
      * update: Remove esLint + updagrade React & ReactDOM version
      
      * Remove yarn.lock changes
      Co-authored-by: 's avatarJosé Barcelon-Godfrey <jose.barcelon@gmail.com>
      27bfdec1
    • Anjorin Damilare's avatar
      chore: remove workspace from `package.json` since we have `pnpm-works… (#38166) · a37abc62
      Anjorin Damilare authored
      chore: remove workspace from `package.json` since we have `pnpm-workspace`
      a37abc62
    • Anders Søgaard's avatar
      Correctly check if width is lte 0 in Image Optimization API (#38226) · e5be3449
      Anders Søgaard authored
      This PR corrects a mistake where a negative number could pass, as a number greater than 0.
      
      This is due to negative numbers being a truthy value in JS.
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      e5be3449
    • Winme's avatar
      Remove CharkraProvicer RestCSS prop (#38199) · 58070c65
      Winme authored
      See the charkra-ui offical docs [ChakraProvider component](https://chakra-ui.com/getting-started/cra-guide#chakraprovider-props), `resetCSS` default value now is `true`, So there is no need to add this prop again
      58070c65
    • Armand Abric's avatar
      Fix typo in SWC plugin destructuring example (#38367) · fa1261cb
      Armand Abric authored
      
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      Co-authored-by: 's avatarBalázs Orbán <18369201+balazsorban44@users.noreply.github.com>
      fa1261cb
    • Max Proske's avatar
      chore(examples): Convert `api-routes-middleware` example to TypeScript (#38358) · 88038ca2
      Max Proske authored
      Convert `api-routes-middleware` example to TypeScript to match Contribution docs.
      
      - Updated cookie util to match the [extending `res`  with TypeScript Next.js docs](https://nextjs.org/docs/api-routes/api-middlewares#connectexpress-middleware-support)
      
      ## Documentation / Examples
      
      - [X] Make sure the linting passes by running `pnpm lint`
      - [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      )
      88038ca2
    • Max Proske's avatar
      chore(examples): Convert `api-routes-cors` example to TypeScript (#38356) · 5145c2d5
      Max Proske authored
      Convert `api-routes-cores` example to TypeScript to match Contribution docs.
      
      - Update CORS configuration to match the [middleware Next.js docs](https://nextjs.org/docs/api-routes/api-middlewares#connectexpress-middleware-support)
      - Allow POST requests as per instructions in `index.tsx`: "make a **POST** / GET / OPTIONS request to /api/cors"
      
      ## Documentation / Examples
      
      - [X] Make sure the linting passes by running `pnpm lint`
      - [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      5145c2d5
    • Jeff Mendez's avatar
      chore(examples): fix experiments loading npm wasm (#38348) · 616e0d7e
      Jeff Mendez authored
      * enables default config that handles npm wasm bundles
      
      
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      616e0d7e
    • Gal Schlezinger's avatar
      [build] validate the exported config values (#38370) · 56e760a2
      Gal Schlezinger authored
      Right now if people will accidentally export a typo like `runtime: 'experimental-egde'` we will fail silently.
      This commit ensures we will throw and fail loudly when such typos occur.
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      56e760a2
    • Ryan "Haticus" Huellen's avatar
      Clarification for Testing Environment Variables (#38359) · 20c1079e
      Ryan "Haticus" Huellen authored
      ## Documentation / Examples
      
      - [X] Make sure the linting passes by running `pnpm lint`
      - [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      
      ## The Issue
      When it came to testing environment variables with jest in the current release of NextJS, I ran into an issue where my variables were seemingly undefined for no reason. With some research and the help from a friend in discussion post #38353 it was determined further configuration steps were needed in relation to the environment variables for jest. At the time being, no direct link is made between [Setting up Jest](https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler) and [Test Environment Variables](https://nextjs.org/docs/basic-features/environment-variables#test-environment-variables).
      
      ## The Change
      This fix provides further clarification on the issue by creating a new link within the note on the [Setting up Jest](https://nextjs.org/docs/basic-features/environment-variables#test-environment-variables) page. Moreover, further explanations were added to ensure developers understand the `test` environment is completely separate from both `development` and `production` meaning files like `.env.development` and `env.prodution` won't be recognized when testing.
      
      ## Supporting Documentation
      This is an issue time and time again for developers. Not only have I experienced this, but others have asked on both [GitHub Discussions](https://github.com/vercel/next.js/discussions/16270) and [StackOverflow](https://stackoverflow.com/questions/63934104/environment-variables-undefined-in-nextjs-when-running-jest/67997819#67997819). Moreover, many of the solutions from 2020 no longer work properly.
      
      I hope this is sufficient enough for a contribution to the documentation. Minor improvements like these create the ideal developer experience Next.js is known for. :)
      Co-authored-by: 's avatarLee Robinson <9113740+leerob@users.noreply.github.com>
      20c1079e
  3. 05 Jul, 2022 6 commits
    • Shu Ding's avatar
      Fix global CSS file imports (#38339) · 085085eb
      Shu Ding authored
      Follow up of #38310 and #38329, this PR adjusts the loader rules to allow importing global CSS files from the app dir.
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [x] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      085085eb
    • Wyatt Johnson's avatar
      Handle Client Rewrites Correctly (#38340) · 329f6cb9
      Wyatt Johnson authored
      When an API route is detected for the `getRouteInfo` method (a route with a `/api` prefix), we should redirect the user to the original destination instead of the rewritten destination. This makes the behaviour consistent with how rewrites have been documented thus far.
      
      The reproduction described in #37783 now causes an invariant violation error (for redirecting to the same URL), but this is instead related to the fact that the router (when rehydrated) attempts to redirect the user again to the correct destination. This should be corrected either in this PR or in a future one that addresses the hydration behaviour directly.
      
      ## Bug
      
      - Related to #37783
      - Related to #37949
      
      ## Example
      
      With the following `next.config.js`:
      
      ```js
      /** @type {import('next').NextConfig} */
      const nextConfig = {
        reactStrictMode: true,
        async rewrites() {
          return {
            beforeFiles: [
              {
                source: '/:path(.*)',
                has: [{ type: 'query', key: 'json', value: 'true' }],
                destination: '/api/json?from=:path',
              },
            ],
          }
        },
      }
      
      module.exports = nextConfig
      ```
      
      The following link:
      
      ```jsx
      <Link href="/not/real?json=true">
        <a>Take me to JSON</a>
      </Link>
      ```
      
      When clicked, will navigate the user to `/not/real?json=true` and have it's contents served by `/api/json` and not simply redirected to `/api/json` which is incorrect.
      Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
      329f6cb9
    • Hannes Bornö's avatar
      Display stack trace when error occurs in API route (#38289) · 469c5030
      Hannes Bornö authored
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [x] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      469c5030
    • JJ Kasper's avatar
    • Cupid Valentine's avatar
      Update analysis scripts (#38201) · 9f162cc8
      Cupid Valentine authored
      9f162cc8
    • Cupid Valentine's avatar
      Update get-static-props.md (#38287) · 09fdf9ad
      Cupid Valentine authored
      
      
      ## Bug
      
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Feature
      
      - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
      - [ ] Related issues linked using `fixes #number`
      - [ ] Integration tests added
      - [ ] Documentation added
      - [ ] Telemetry added. In case of a feature if it's used or not.
      - [ ] Errors have helpful link attached, see `contributing.md`
      
      ## Documentation / Examples
      
      - [ ] Make sure the linting passes by running `pnpm lint`
      - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
      09fdf9ad