1. 24 Apr, 2024 1 commit
  2. 23 Apr, 2024 9 commits
    • JJ Kasper's avatar
      Clean-up fetch metrics tracking (#64746) · a230be48
      JJ Kasper authored
      This ensures we only track fetch metrics in development mode as that's
      the only time we report them currently, this also adds an upper limit on
      how many metrics we store per-request as previously this was unbounded,
      on top of that this ensures we don't keep tracking fetch metrics after
      the request has ended as we only report on request end, and finally this
      adds a clean-up to the reference we attach to the request object
      containing the fetch metrics once we have used them.
      
      Closes: https://github.com/vercel/next.js/issues/64212
      
      Closes NEXT-3159
      a230be48
    • Jeffrey Zutt's avatar
      fix: remove traceparent from cachekey should not remove traceparent from original object (#64727) · 73c2d634
      Jeffrey Zutt authored
      ### What?
      
      I submitted PR #64499 , it got merged, but it contains a mistake.
      I'm terribly sorry about this!
      
      By removing the traceparent from the cachekey, we mistakenly removed the
      header from the original object.
      Causing the actual request to be executed without the traceparent
      header.
      
      ### Why?
      
      Creating a cachekey should not alter the original object.
      
      ### How?
      
      Flip the arguments for Object.assign
      
      ---------
      Co-authored-by: 's avatarJeffrey <jeffrey@jeffreyzutt.nl>
      Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
      73c2d634
    • Zack Tanner's avatar
      fix root page revalidation when redirecting in a server action (#64730) · dd441911
      Zack Tanner authored
      When a server action triggers a redirect, we're incorrectly applying a
      refresh marker to the segment they were on, rather than the segment they
      were being redirected to. As a result, when revalidation occurs (via
      `revalidateX` or `router.refresh()`), the top-level segment would be
      replaced with data for an incorrect segment.
      
      For example, if triggering a redirect action from `/redirect` to `/`,
      the router state tree would save a reference to `/redirect`. The next
      time a refresh or revalidate happens, it'd refresh the segment data for
      `/redirect` instead of `/`.
      
      Fixes #64728
      
      
      Closes NEXT-3156
      dd441911
    • Zack Tanner's avatar
      prevent erroneous route interception during lazy fetch (#64692) · 8b4c2347
      Zack Tanner authored
      When the router cache can't find a cache node for the requested segment,
      it performs a request to the server to get the missing data. This
      request to the server currently will always include the `next-url`
      header, and on soft-navigations, the router will route the request to
      the intercepted handler. This lazy fetch is treated as a soft navigation
      by the server, and will incorrectly return data for the intercepted
      route.
      
      Similar to the handling in `router.refresh`, and the server action
      reducer, we should not include the `next-url` header if there's no
      interception route currently in the tree, as otherwise we'll be
      erroneously triggering the intercepted route.
      
      Fixes #64676
      Closes NEXT-3146
      8b4c2347
    • Sam Ko's avatar
      fix(fetch-cache): fix additional typo, add type & data validation (#64799) · d6a7ca0e
      Sam Ko authored
      This PR fixes the fetch cache, which currently is not using the fetch
      cache when it exists (the tags were not getting set properly), and tags
      have not updated.
      
      (Before)
      
      https://github.com/vercel/next.js/assets/28912696/74d8f592-0698-4ae4-be4b-30cffb1ffe11
      
      (After)
      
      https://github.com/vercel/next.js/assets/28912696/af12b13a-46c6-41c3-9ac3-20e1ec44a865
      
      - https://github.com/vercel/next.js/pull/64786
      - https://github.com/vercel/next.js/pull/63547
      
      Closes NEXT-3173
      d6a7ca0e
    • Jiachi Liu's avatar
      Fix next/image usage in mdx (#64875) · 4a6b511c
      Jiachi Liu authored
      ### What
      
      Apply the react aliases for app dir also to the files with
      `pagesExtension`
      
      ### Why
      
      In the page bundle of mdx page:
      
      In RSC layer react is referencing to the insatlled react 18.2.0 's
      `jsx-runtime` to create each JSX element. The react 18.2 JSX runtime
      access `propTypes` of the component type and then it crashes 💥
      In RSC layer it should use the built-in react canary's `jsx-runtime`.
      
      The reason that it didn't use the built-in one is we're using customized
      `pageExtension` `["mdx"]` for mdx, where we didn't apply all these rules
      for the files with `pageExtension`, but only the js and ts files by
      default.
      
      For mdx specifically, we cannot only applied to
      `(page|layout|route).[page extension]` cause every mdx file needs to
      have proper resolution. Since this doesn't break transform, it's safe to
      apply for all files with page extension.
      
      Fixes #58888 
      
      Closes NEXT-3187
      4a6b511c
    • Jiachi Liu's avatar
      Fix mixed exports in server component with barrel optimization (#64894) · 04cc13c0
      Jiachi Liu authored
      ### What
      
      * Remove the change added in #64467, but still kept tests.
      * Add more tests for mixed imports (component and function) from shared
      component with `optimizePackageImports`
      
      ### Why
      
      The fix in #64467 was not correct, as mixing `export *` with `"use
      client"` should error if Next.js detect it properly.
      When there's mixed exports, that a shared function will become a client
      reference if the target file inherits the client boundary.
      
      The original issue #64467 fixed was actually related to tree-shaking,
      which is fixed in #64681.
      
      Closes NEXT-3197
      04cc13c0
    • Jiachi Liu's avatar
      fix: mixing namespace import and named import client components (#64809) · 8d01d496
      Jiachi Liu authored
      ### What
      
      Reported by @MaxLeiter, when you mixing named import and wildcard import
      to a client component, and if you clone the module it will missed others
      exports except the named ones. This lead to an issue that rendered React
      element type is `undefined`.
      
      ### Why
      
      We're using a tree-shaking strategy that collects the imported
      identifiers from client components on server components side. But in our
      code `connection.dependency.ids` can be undefined when you're using
      `import *`. So for that case we include all the exports.
      
      In the flight client entry plugin, if we found there's named imports
      that collected later, and the module is already being marked as
      namespace import `*`, we merge the ids into "*", so the whole module and
      all exports are respected.
      
      Now there're few possible cases for a client component import:
      
      During webpack build, in the outout going connections, there're
      connection with empty imported ids (`[]`), cannot unable to detect the
      imported ids (`['*']`) and detected named imported ids (`['a', 'b',
      ..]`). First two represnt to include the whole module and all exports,
      but we might collect the named imports could come later than the whole
      module. So if we found the existing collection already has `['*']` then
      we keep using that regardless the collected named imports. This can
      avoid the collected named imports cover "exports all" case, where we
      will expose less exports for that collection module lead to the
      undefined component error.
      
      Closes NEXT-3177
      8d01d496
    • Jiachi Liu's avatar
      Fix: resolve mixed re-exports module as cjs (#64681) · de84e3ae
      Jiachi Liu authored
      ### Why
      
      If you have a client entry that mixing `default` re-export and `*`
      re-export, atm we cannot statically analyze all the exports from this
      the boundary, unless we can apply barrel file optimization for every
      import which could slow down speed.
      
      ```js
      // index.js
      'use client'
      export * from './client'
      export { default } from './client'
      ```
      
      Before that happen we high recommend you don't mixing that and try to
      add the client directive to the leaf level client module. We're not able
      to determine what the identifiers are imported from the wildcard import
      path. This would work if we resolved the actual file but currently we
      can't.
      
      ### What
      
      When we found the mixing client entry module like that, we treat it as a
      CJS client module and include all the bundle in client like before what
      we have the client components import optimization.
      
      Ideally we could warn users don't apply the client directive to these
      kinda of barrel file, and only apply them to where we needed.
      
      
      Fixes #64518 
      Closes NEXT-3119
      de84e3ae
  3. 17 Apr, 2024 26 commits
  4. 12 Apr, 2024 4 commits