1. 29 Feb, 2024 5 commits
  2. 28 Feb, 2024 22 commits
    • Max Leiter's avatar
      Server Action tests (#62655) · 74b3f0f4
      Max Leiter authored
      ### What?
      Backports some Server Action changes from Shu to 14.1.1.
      
      
      [Improve the Server Actions SWC transform
      ](https://github.com/vercel/next.js/pull/62655/commits/bf6460e985c0ff8e41c03e000cbcb2638bcf99c7)
      
      [Fix Server Reference being double
      registered](https://github.com/vercel/next.js/pull/62655/commits/ef81b1099856bc7918dfa39e6d272cce53451eaf)
      
      
      [Improve the Server Actions SWC transform (part
      2)](https://github.com/vercel/next.js/pull/62655/commits/6e59c222a84f48edfc958d3327eb5448431e7784)
      
      [Fix module-level Server Action creation with closure-closed
      values](https://github.com/vercel/next.js/pull/62655/commits/51c6a07ec6a373eca3425ef565a53f4105112099)
      
      
      [Rename internal utility naming for
      clarification](https://github.com/vercel/next.js/pull/62655/commits/00d8e6e0612b7afddbce5f944a7330413e548871)
      
      ### Why?
      
      ### How?
      
      ---------
      Co-authored-by: 's avatarShu Ding <g@shud.in>
      Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
      74b3f0f4
    • Jiachi Liu's avatar
      Backport metadata fixes (#62663) · a6946b69
      Jiachi Liu authored
      Backport metadata fixes 
      #61898
      #62109
      #62615
      
      Closes NEXT-2641
      a6946b69
    • Ethan Arrowood's avatar
      Fix draft mode invariant (#62121) · 4002f4b3
      Ethan Arrowood authored
      ### What?
      
      In today's implementation, requests that don't end in `.rsc` are getting
      the data request query. We need to remove this toggle to prevent them
      from 500'ing.
      
      ### Why?
      
      The invariant triggered was:
      
      
      https://github.com/vercel/next.js/blob/212553958c671ea1f71d96fbc97ea4b9e5019bf3/packages/next/src/server/base-server.ts#L2838-L2842
      
      Crawling up the code, the conditional:
      
      
      https://github.com/vercel/next.js/blob/212553958c671ea1f71d96fbc97ea4b9e5019bf3/packages/next/src/server/base-server.ts#L2815
      
      must be `true`.
      
      The variable `isDataReq` is set here:
      
      
      https://github.com/vercel/next.js/blob/212553958c671ea1f71d96fbc97ea4b9e5019bf3/packages/next/src/server/base-server.ts#L1833-L1839
      
      This conditional expression is a bit complex, but it simplifies down to:
      - `isDataReq` is `true` when (TODO)
      - `isDataReq` is `false` when (TODO)
      
      ### How?
      
      Closes NEXT-2341
      Fixes #61377
      
      Tested manually by:
      - Building and packaging this branch locally
      - Deploying tarball and then depending on it as the Next.js version for
      an example app similar to the one reported by #61377
      - Inspecting console for 500 errors.
      
      ---------
      Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
      Co-authored-by: 's avatarZack Tanner <zacktanner@gmail.com>
      4002f4b3
    • Steven's avatar
      fix: babel usage with next/image (#61835) · 7dbf6f82
      Steven authored
      The `process/browser` lib was imported and being transformed, but
      `process.browser = true` turns to `true = true` that causes the
      compilation error, we need to exclude them from certain compilation
      layers
      
      - Fixes https://github.com/vercel/next.js/issues/61116
      
      Closes NEXT-2410
      Closes NEXT-2328
      
      ---------
      Co-authored-by: 's avatarJiachi Liu <inbox@huozhi.im>
      7dbf6f82
    • Jiachi Liu's avatar
      Fix next/server apit push alias for ESM pkg (#61721) · 3efc842a
      Jiachi Liu authored
      We have a modularize imports config for `next/server` before, which will
      transform the `next/server` imports to directly import from the actual
      file, for instance: `import { NextRequest } from 'next/server'` will
      become `import { NextRequest } from
      'next/dist/server/web/exports/next-request'`, where the NextRequest is
      exported as default export. This is fine in most case until you're using
      a ESM pkg, then it will be resolved as `{ default: NextRequest }`
      according to the spec. Since it's a ESM import to a CJS module in
      `next/dist`.
      
      Since we already have the ESM alias introduced in #59852 , this can
      handle the case more properly.
      
      Remove the modularize imports config for `next/server`, use the ESM api
      alias instead.
      
      Migrate the cjs optimizer tests from middleware to a separate endpoint
      `/cjs/server`. As now ESM imports for next/server are not going to get
      tree-shaken in dev, but since we don't have image response there it's
      still fine.
      
      Closes NEXT-2376
      Closes NEXT-2374
      3efc842a
    • JJ Kasper's avatar
      Replace image optimizer IPC call with request handler (#61471) · 179d14e4
      JJ Kasper authored
      This ensures we don't do un-necessary IPC calls during image optimizing
      and leverage the internal request handler for fetching internal static
      images/resources.
      
      x-ref: https://github.com/vercel/next.js/issues/58248
      
      Closes NEXT-2318
      179d14e4
    • Steven's avatar
      chore: refactor image optimization to separate external/internal urls (#61172) · f8fe70dd
      Steven authored
      This PR is refactoring only and doesn't change the logic, therefore no
      tests were added.
      
      The improvement here is readability:
      - separate functions to fetch external vs internal image (in the future,
      we could improve perf of internal image routing)
      - types of the arguments are more specific (rather than passing in
      complete NextConfig)
      
      > Note: Its easier to review with whitespace hidden:
      https://github.com/vercel/next.js/pull/61172/files?w=1
      f8fe70dd
    • Steven's avatar
      fix(image): warn when animated image is missing `unoptimized` prop (#61045) · 5a5f178f
      Steven authored
      This PR adds a warning when attempting to optimize an animated image.
      
      ```jsx
      <Image src="/image.gif" />
      ```
      
      The warning looks like the following:
      
      ```
      The requested resource "/image.gif" is an animated image so it will not be optimized. Consider adding the "unoptimized" property to the <Image>.
      ```
      
      To remove the warning, add the `unoptimized` prop.
      
      ```jsx
      <Image src="/image.gif" unoptimized />
      ```
      
      We don't attempt to optimized animated images because it can be very
      slow (30+ seconds) and sometimes deoptimizeds (the output is larger than
      the input) so its best to serve the animated image as-is.
      
      Closes NEXT-2199
      5a5f178f
    • Balázs Orbán's avatar
      fix(build-output): show stack during CSR bailout warning (#62594) · b0474c81
      Balázs Orbán authored
      We should treat the warning for CSR bailout the same as the hard-error,
      and show the stack trace for either case.
      
      It might be useful to track down the source of this warning.
      
      We have the stack info already, but we only showed it during the error
      logging. We should show it for warnings too.
      
      This is similar to #61200
      
      Closes NEXT-2624
      b0474c81
    • Jiachi Liu's avatar
      Fix extra swc optimizer applied to node_modules in browser layer (#62051) · 1bee5b6c
      Jiachi Liu authored
      Disable swc transform optimizer for node_modules in browser layer of app
      router bundles
      
      Fixes #61858
      Fixes #60644
      Fixes #60920
      Fixes #61740
      Closes NEXT-2418
      
      In browser there could be not only one runtime, it could have both js
      worker and browser. In js worker the `typeof window` is not as same as
      in browser, so disabling the swc optimizer which will replace the code.
      Leave the condition as it as.
      1bee5b6c
    • Donny/강동윤's avatar
      fix(next-swc): Detect `exports.foo` from `cjs_finder` (#61795) · b747e08b
      Donny/강동윤 authored
      ### What?
      
      Patch cjs finder to detect `exports.foo` (instead of module.exports)
      
      ### Why?
      
      This causes an issue for `react.production.min.js`.
      
      x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1707343215879979
      
      ### How?
      
      Closes PACK-2443
      b747e08b
    • Jiachi Liu's avatar
      Fix attempted import error for react (#61791) · af47328c
      Jiachi Liu authored
      ### What
      
      Exclude precompiled react packages from browser layer loaders coverage.
      
      ### Why
      
      Since we're transpiling all the browser layer code now after #59569,
      then SWC will also compile react. But when it compiles
      `react.production.min.js` it gives me with the code and ESM helper
      inserted
      
      ```js
      import { _ as _type_of } from "@swc/helpers/_/_type_of"; // This is not correct
      var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Sym
      bol.for("react.strict_mode"), r = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.f
      ```
      
      This makes bundler think it's a ESM package but actually it's CJS, which
      converts the module into `{ default: .., __esModule }` instead of the
      original react module.
      
      When you're using `React.useEffect` or other API through namespace
      import (`import * as React from 'react'`), this will break the module
      exports check in bundling as the property doesn't directly attached to
      the module now. This PR disabled the transform for precompiled react
      packages now and will see the deeper issue in next-swc side later.
      
      Fixes #60890
      Fixes #61185
      
      Closes NEXT-2362
      af47328c
    • Jiachi Liu's avatar
      181e7d52
    • JJ Kasper's avatar
    • JJ Kasper's avatar
      update chunking tests · c1edac79
      JJ Kasper authored
      c1edac79
    • Zack Tanner's avatar
      fix router crash on revalidate + popstate (#62383) · 6aee03de
      Zack Tanner authored
      When the popstate action is fired (as is the case in a browser back
      button), if the page you're going back to has missing cache node data,
      the router will crash.
      
      Almost all router actions will suspend at the app-router level with the
      exception of `ACTION_RESTORE`. This was to address an issue where
      suspending in the router would add enough delay for browser scroll
      restoration behavior not to work.
      
      As a result, when going back to the page with missing data, app-router
      wouldn't suspend but layout-router would suspend on the missing data
      while triggering a lazy fetch. We trigger a server-patch with the
      applied lazy data, but when React replays the render, it will replay the
      branch without the cache node data applied. This results in the router
      getting caught in a loop of suspending, applying the cache node,
      replaying the branch without the cache node, and eventually crashing due
      to an error thrown by React to prevent re-suspending indefinitely.
      
      This adds a property to the cache node to signal if the lazy data has
      been resolved. If it has been, we won't call the server patch action
      again.
      
      Fixes #61336
      Closes NEXT-2438
      6aee03de
    • Zack Tanner's avatar
      fix loading issue when navigating to page with async metadata (#61687) · 8fd3d7ee
      Zack Tanner authored
      ### What
      Client-side transitioning to a page that triggered a loading boundary
      with async metadata would cause the transition to stall, potentially
      getting stuck in a refetch loop.
      
      ### Why
      In layout-router, we trigger a "lazy fetch" when we encounter a segment
      that we don't have cache nodes for. This calls out to the server and
      suspends until the data fetch is resolved, and applied to the router
      tree. However after suspending but before updating the client router, we
      set `childNode.lazyData` to null. When we unsuspend from the server
      patch action, `childNode.rsc` might still be missing and clearing
      `lazyData` means we've blown away the reference to the fetch we already
      had pending, triggering a refetch loop.
      
      ### How
      This removes the logic that mutates the cache node in render, as this is
      not concurrent safe, and doesn't appear to be needed for anything.
      
      Fixes #61117
      Closes NEXT-2361
      
      ---------
      Co-authored-by: 's avatarJiachi Liu <inbox@huozhi.im>
      8fd3d7ee
    • Zack Tanner's avatar
      revert changes to process default routes at build (#61241) · 05b972b8
      Zack Tanner authored
      Reverts changes from #61173 & #60240 (while leaving the tests that were
      added).
      
      There are too many spots where considering `/default` routes as pages
      needs to be carefully considered in different runtimes, and it turns out
      that it's not actually needed to handle the case that it was originally
      added for. I confirmed that the test that added the case it was intended
      to fix (`parallel-routes-catchall-default`, along with the unit tests in
      `normalize-catchall-routes`) are still passing as expected.
      05b972b8
    • Willi#m ⬣'s avatar
      fix parallel route top-level catch-all normalization logic to support nested… · 7026eb21
      Willi#m ⬣ authored
      fix parallel route top-level catch-all normalization logic to support nested explicit (non-catchall) slot routes (#60776)
      
      Fix NEXT-2165
      
      ### What?
      
      Addresses the limitation of #60240, where a dummy `default` file is
      required in parallel route child slot to prevent errors in dev server
      rendering (`TypeError: Cannot read properties of undefined (reading
      'clientModules')`) as well as errors in build and deploy (`Error:
      ENOENT: no such file or directory, lstat
      ‘/vercel/path0/.next/server/app/parallel-route/[section]/@part/[partSlug]/page_client-reference-manifest.js’`)
      
      Without the `default.tsx`, builds and deployments will fail with:
      
      <img width="956" alt="CleanShot 2024-01-18 at 02 12 36@2x"
      src="https://github.com/vercel/next.js/assets/179761/80ba61bd-6ec0-4b16-a393-dc9375227e19">
      
      local dev server will also crash with:
      
      <img width="986" alt="CleanShot 2024-01-18 at 02 13 19@2x"
      src="https://github.com/vercel/next.js/assets/179761/cc500a32-b2f8-47b4-999e-e57cf5141b2f">
      
      > TypeError: Cannot read properties of undefined (reading
      'clientModules')
      
      
      ### Why?
      
      Since `default.tsx` is not a compulsory when you have slot that are
      specific and ends with a dynamic route segment, this PR extends support
      so that it is possible mixing catch-all routes with specific
      non-catchall routes without requiring an additional `default.tsx` .
      
      This PR will allow the following test cases to pass:
      
      ```
      it('should not add the catch-all route to segments that have a more specific [dynamicRoute]', () => {
          const appPaths = {
            '/': ['/page'],
            '/[[...catchAll]]': ['/[[...catchAll]]/page'],
            '/nested/[foo]/[bar]/default': [
              '/nested/[foo]/[bar]/default',
              '/nested/[foo]/[bar]/@slot0/default',
              '/nested/[foo]/[bar]/@slot2/default',
            ],
            '/nested/[foo]/[bar]': [
              '/nested/[foo]/[bar]/@slot0/page',
              '/nested/[foo]/[bar]/@slot1/page',
            ],
            '/nested/[foo]/[bar]/[baz]': [
              '/nested/[foo]/[bar]/@slot0/[baz]/page',
              '/nested/[foo]/[bar]/@slot1/[baz]/page',
            ],
            '/[locale]/nested/[foo]/[bar]/[baz]/[qux]': [
              '/[locale]/nested/[foo]/[bar]/@slot1/[baz]/[qux]/page',
            ],
          }
      
          const initialAppPaths = JSON.parse(JSON.stringify(appPaths))
          normalizeCatchAllRoutes(appPaths)
          expect(appPaths).toMatchObject(initialAppPaths)
        })
      ...
      ```
      
      ```it('should not add the catch-all route to segments that have a more specific [dynamicRoute]', () => {
          const appPaths = {
            '/': ['/page'],
            '/[[...catchAll]]': ['/[[...catchAll]]/page'],
            '/nested/[foo]/[bar]/default': [
              '/nested/[foo]/[bar]/default',
              '/nested/[foo]/[bar]/@slot0/default',
              '/nested/[foo]/[bar]/@slot2/default',
            ],
            '/nested/[foo]/[bar]': [
              '/nested/[foo]/[bar]/@slot0/page',
              '/nested/[foo]/[bar]/@slot1/page',
            ],
            '/nested/[foo]/[bar]/[baz]': [
              '/nested/[foo]/[bar]/@slot0/[baz]/page',
              '/nested/[foo]/[bar]/@slot1/[baz]/page',
            ],
            '/[locale]/nested/[foo]/[bar]/[baz]/[qux]': [
              '/[locale]/nested/[foo]/[bar]/@slot1/[baz]/[qux]/page',
            ],
          }
      ...
      ```
      
      and allow parallel routes defined in this [code
      repro](https://github.com/williamli/nextjs-NEXT-2165) to build.
      
      
      ![image](https://github.com/vercel/next.js/assets/179761/030f4fe1-3a27-41e5-bbd9-bc511f95e5d7)
      
      
      ### How?
      
      `packages/next/src/build/normalize-catchall-routes.ts` is extended to
      check `appPath` to see if it is:
      1. the route is not a catchall
      2. `isMoreSpecific` than the closest `catchAllRoute`.
      
      
      where `isMoreSpecific` is defined as:
      
      ```
      
      function isMoreSpecific(pathname: string, catchAllRoute: string): boolean {
        const pathnameDepth = pathname.split('/').length
        const catchAllRouteDepth = catchAllRoute.split('/').length - 1
        return pathnameDepth > catchAllRouteDepth
      }
      
      ```
      
      ---------
      Co-authored-by: 's avatarZack Tanner <zacktanner@gmail.com>
      7026eb21
    • Shu Ding's avatar
      Improve redirection handling (#62561) · 9bbd0821
      Shu Ding authored
      Currently to redirect to another RSC route of the same app, we initiate
      another request to that route. This PR changes that request to directly
      use the internal hostname of the current server handler, rather than
      relying on other headers.
      
      Closes NEXT-2614
      9bbd0821
    • JJ Kasper's avatar
      update config for publish · 22ba4cde
      JJ Kasper authored
      22ba4cde
    • JJ Kasper's avatar
      apply chunking fix #62424 · 1153ad29
      JJ Kasper authored
      1153ad29
  3. 18 Jan, 2024 13 commits