1. 09 Aug, 2024 7 commits
  2. 08 Aug, 2024 23 commits
    • Josh Story's avatar
      Introduce prerenderAsyncStorage and refactor app-render (#68637) · db153fbc
      Josh Story authored
      In preparation for a number of new features and rendering modes this PR
      dramatically refactors app-render and related files to make future
      contributions easier to land.
      
      Historically we have used AsyncLocalStorage to scope state that is
      contextual for an entire page export (RSC > SSR > error handling etc...)
      however it can be useful and is generally a good practice to push the
      ALS scoping deeper into the render when possible. One case is for
      tracking dynamic access. in this PR we introduce prerenderAsyncStorage
      which is wrapped around individual render calls into React. If there is
      a store during a render then we can infer we are in an App Router
      prerender.
      
      Longer term we should consider combinging the requestStorage and
      staticGenerationStorage since these are scoped at the same level and the
      name of staticGenerationStorage is misleading because it is in scope
      even when there is no static generation happening.
      
      In addition to storage changes the code paths for app-render are
      reorganized to use fewer closures and to consolidate argument passing.
      Additionally we now treat render (dynamic request handling) and
      prerender (build and revalidate handling) in separate code paths. This
      allows for clearer login within each pathway and fewer repeated
      conditionals.
      
      There are still a number of things to further clean up like how we track
      metadata. One idea is to have the render/prerender functions simply
      return a RenderResult. Another area is error handling. There is
      currently a bug where ssr only errors won't fail a build the same way an
      RSC error would. To keep this PR clean I've reproduced this behavior
      even if it is buggy so we can land a fix stacked on top
      db153fbc
    • vercel-release-bot's avatar
      v15.0.0-canary.110 · ae127ac6
      vercel-release-bot authored
      ae127ac6
    • Vercel Release Bot's avatar
      Update font data (#68639) · 83f2e551
      Vercel Release Bot authored
      This auto-generated PR updates font data with latest available
      
      ---------
      Co-authored-by: 's avatarsamcx <sam@vercel.com>
      83f2e551
    • Hendrik Liebau's avatar
      Prevent incompability with `'eval-source-map'` and `mangle: false` (#68688) · c86062ac
      Hendrik Liebau authored
      Setting the terser option `mangle` to `false` for dev server runtime
      bundles as done in #68641 seems to be incompatible with
      `'eval-source-map'`, i.e. when running `pnpm dev`. The combination
      yields strange runtime errors when running an app with the node runtime.
      E.g.:
      ```
       ⨯ TypeError: isValidElementType is not a function
          at renderToHTMLImpl (webpack://next/dist/src/server/render.tsx?e2d9:568:10)
          at render (webpack://next/dist/src/server/route-modules/pages/module.ts?84fd:125:12)
      ```
      or
      ```
      TypeError: Cannot read properties of undefined (reading 'contexts')
          at Object.<anonymous> (<snip>/packages/next/src/server/route-modules/pages/vendored/contexts/html-context.ts:1:59)
      ```
      or
      ```
       ⨯ Error: Cannot find module 'next/dist/server/lib/trace/tracer'
      Require stack:
      - <snip>/packages/next/dist/compiled/next-server/app-page.runtime.dev.js
      - <snip>/test/e2e/app-dir/app/.next/server/app/dashboard/page.js
      ```
      
      Since using `'eval-source-map'` already fixes showing the original
      names, we don't need to disable mangling in this case.
      
      **How to reproduce on `canary`:**
      
      - start `pnpm dev`
      - start `pnpm next dev test/e2e/app-dir/app`
      - open http://localhost:3000/client-component-route
      - observe errors
      c86062ac
    • Sebastian Silbermann's avatar
    • Hemanshu Upadhyay's avatar
      Migrated 'with-absolute-imports' to App-router Convention (#68666) · 51892ebb
      Hemanshu Upadhyay authored
      Hey There 👋 
      This PR Includes the following changes 
      -> Migration of with-absolute-imports example to App Router
      -> Updated all packages
      -> Added the Layout page as per App router Convention. 
      
      
      cc - @samcx
      Co-authored-by: 's avatarSam Ko <sam@vercel.com>
      51892ebb
    • vercel-release-bot's avatar
      v15.0.0-canary.109 · 31310493
      vercel-release-bot authored
      31310493
    • Jiwon Choi's avatar
      chore: remove asset prefix warning log and update docs (#68681) · 485497d9
      Jiwon Choi authored
      ### Why?
      
      In https://github.com/vercel/next.js/pull/68622 we fixed a bug that HMR
      breaks when `assetPrefix` is set to full URL.
      The fix was targeted to the edge case where the user may set `localhost`
      to the `assetPrefix`, and technically, when the request is valid the HMR
      should work.
      
      However, we do not recommend this pattern as the `assetPrefix` is
      intended to be used for setting a CDN URL.
      
      ### How?
      
      Therefore we modify the docs to gently imply that the `assetPrefix` is
      for CDN URL.
      Also, removed the warning log that could be confusing whether we support
      it or not.
      Setting localhost will still work, but we do not mention about it within
      the app.
      485497d9
    • JJ Kasper's avatar
      Ensure we copy map file as well for experimental tracing (#68676) · 7c10fcf2
      JJ Kasper authored
      These files can be present if server source maps flag is enabled so need
      copying as well. Also removes incorrect `_not-found` special case which
      will need revisiting and updating define-env check to not apply in dev.
      
      x-ref: [slack
      thread](https://vercel.slack.com/archives/C056QDZARTM/p1723119830912809)
      7c10fcf2
    • JJ Kasper's avatar
      Ensure we hard error on invalid config export (#68638) · e8dec1f3
      JJ Kasper authored
      Currently we only log warnings when we fail to parse config values and
      then fall back to their defaults, this is very dangerous as this can
      cause unexpected behavior and the warning log can be easy to miss. To
      prevent this unexpected behavior this updates to treat these as errors
      instead and fails the build if any invalid config exports are provided.
      
      x-ref: NDX-190
      e8dec1f3
    • Josh Story's avatar
      Stop mangling server runtime in dev (#68641) · e740c48a
      Josh Story authored
      The server runtimes are currently all bundled in production mode with
      full optimizaitons. This can make certain things hard in dev mode
      because while most of your app will be unmangled anything that runs from
      the server runtime will be runnign without useful debug information like
      original function names. This PR updates the runtime configs to no
      longer mangle the output.
      e740c48a
    • Jiachi Liu's avatar
      test: refactor unclear tests to composed matchers (#68674) · 8a801847
      Jiachi Liu authored
      ### What
      
      Improve the test matcher for string matching while searching in array
      case, those flaky tests were giving unclear failing messages without
      enough context to help investigate the flakeness.
      
      ### Why
      
      Example of existing unclear flaky failure
      ```
      pnpm test test/integration/link-ref/test/index.test.js
      • Invalid hrefs > production mode > should preload with child ref with React.createRef
      Expand output
      ● Invalid hrefs › production mode › should preload with child ref with React.createRef
      expect(received).toBe(expected) // [Object.is](http://object.is/) equality
      
      Expected: true
      Received: false
      ```
      
      While looking at the test, assertions like `expect(found).toBe(true)`
      could fail without telling us what are the context, what is the original
      input before narrowing down as a boolean value. After changing to a
      composed testing matcher, we're able to see what href links are giving
      us the unexpected result
      
      ```ts
      expect(hrefs).toEqual(
          expect.arrayContaining([expect.stringContaining('index')])
        )
      ```
      
      For example, if we're looking for a string pattern `first-1` in the link
      hrefs, but it only got `first`, the failure message would look like
      this. This will help us identify the root cause easier with more
      context.
      
      ```
       ● Prefetching Links in viewport › production mode › should prefetch with link in viewport onload
      
         expect(received).toEqual(expected) // deep equality
      
         Expected: ArrayContaining [StringContaining "first1"]
         Received: ["/_next/static/chunks/pages/first-c9300691290bda9a.js"]
      
           109 |               links.map(async (link) => await link.getAttribute('href'))
           110 |             )
         > 111 |             expect(hrefs).toEqual(
               |                           ^
           112 |               expect.arrayContaining([expect.stringContaining('first1')])
      ```
      8a801847
    • Delba de Oliveira's avatar
      Docs: Add note about RC deps (#68591) · 17f2cb65
      Delba de Oliveira authored
      Add helper notes for those struggling to upgrade to React 19 RC when
      using Next.js RC.
      [NDX-118](https://linear.app/vercel/issue/NDX-118/update-note-on-react-rc-versions-when-upgrading-to-nextjs-15-rc)
      
      ---------
      Co-authored-by: 's avatarAmy Burns <amy.burns@vercel.com>
      17f2cb65
    • Hendrik Liebau's avatar
      Use proper react release channel for `react-dom/static` aliases (#68663) · abf12f85
      Hendrik Liebau authored
      Now that `react-dom/static` is also available outside of the
      experimental channel, we don't need to hard-code the react release
      channel in the bundle aliases anymore.
      
      Without this fix, `react-dom` would end up twice in our non-experimental
      server runtime bundles with the changes in #68637.
      
      <img width="1479" alt="react-dom twice in bundle"
      src="https://github.com/user-attachments/assets/ed50e9ec-b984-496b-92e1-69515f2afbc8">
      abf12f85
    • Delba de Oliveira's avatar
      Docs: Add static indicator diagram (#68659) · 6f1c3519
      Delba de Oliveira authored
      Adds static indicator diagrams to the `devIndicators` docs.
      [DOC-3152](https://linear.app/vercel/issue/DOC-3152/add-static-indicator-diagrams).
      6f1c3519
    • Sebastian Silbermann's avatar
    • Jiachi Liu's avatar
      Reject next image urls in image optimizer (#68628) · 4e0790fd
      Jiachi Liu authored
      ### What
      
      Follow up on #67465, add more cases that should be rejected by image
      optimizer when the url is tend to contain the generated next image with
      `/_next/image` in url.
      
      These should also get should get rejected:
      
      * with encoded: `%2F_next%2Fimage%3` 
      * with asset prefix: `/assets/_next/image` 
      * with host: `https://<domain>/_next/image` 
      
      Closes NDX-101
      x-ref:
      [slack](https://vercel.slack.com/archives/C07AYREDX45/p1720111367743119)
      4e0790fd
    • Donny/강동윤's avatar
      feat(turbopack): Allow type-only import of `usePathname` (#68643) · 2cee0de0
      Donny/강동윤 authored
      ### What?
      
      Type-only imports of `usePathaname` from server components are fine.
      
      ### How?
      
      Closes PACK-3186
      2cee0de0
    • Jiwon Choi's avatar
      01a3f988
    • vercel-release-bot's avatar
      v15.0.0-canary.108 · 604e68ad
      vercel-release-bot authored
      604e68ad
    • JJ Kasper's avatar
      Remove extraneous configs from cache manifest (#68645) · 5f2e294a
      JJ Kasper authored
      As discussed we can tolerate sharing cache between source maps enabled
      and not e.g. sharing cache from main -> preview so this drops those
      related configs from the cache manifest.
      5f2e294a
    • Will Binns-Smith's avatar
      Turbopack HMR: Reload the page when server session changes (#68630) · be10d2a5
      Will Binns-Smith authored
      It’s possible to the following scenario to occur:
      
      - Browser loads a page and establishes HMR connection
      - User quits the server, makes changes, and restarts the server
      - The browser reloads, the user makes more changes, and the two reach an
      inconsistent state
      
      To avoid this, reload the browser when the server changes. This already
      happened with webpack, so implement it for Turbopack.
      
      Test Plan: `TURBOPACK=1 pnpm test-dev
      test/development/basic/hmr.test.ts`
      
      ---------
      Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
      be10d2a5
    • Zack Tanner's avatar
      fix app router prefetch deduping (#68642) · cc926543
      Zack Tanner authored
      The `Link` component has built in prefetch deduping behavior that was
      added for pages router, since pages only supports a single kind of
      prefetch.
      
      Both pages & app routers share the `Link` component, meaning the
      deduping behavior was enabled for both. However, app router supports
      different [prefetch
      types](https://nextjs.org/docs/app/api-reference/components/link#prefetch).
      This means that if a page contains a link to a URL with auto
      prefetching, followed by a URL with `prefetch={true}`, the full prefetch
      would not be applied because it was short-circuited by `Link`.
      
      Closes NDX-124
      cc926543
  3. 07 Aug, 2024 10 commits
    • vercel-release-bot's avatar
      v15.0.0-canary.107 · 71882dbc
      vercel-release-bot authored
      71882dbc
    • Jiachi Liu's avatar
      8f2dd209
    • JJ Kasper's avatar
      Handle pruning mismatching cache for experimental trace (#68635) · c1272627
      JJ Kasper authored
      If there's a bug in a previous cache or it mis-matches we need to ensure
      we prune it so it's not left around and merged at all when it shouldn't
      be.
      
      x-ref: [slack
      thread](https://vercel.slack.com/archives/C056QDZARTM/p1723065176374699?thread_ts=1723056506.642999&cid=C056QDZARTM)
      c1272627
    • Zack Tanner's avatar
      refactor static workers to help with parallelization & cache sharing (#68546) · d365ff80
      Zack Tanner authored
      ### What
      During SSG, the fetch cache isn't shared between renders of different
      pages within a single export worker. This means that if **Page A**
      fetches `/foo` and **Page B** also fetches `/foo`, they will not be
      deduped and instead will be fetched from origin within each worker.
      Additionally, we currently only prerender 1 path per worker, which
      doesn't allow us to take advantage of concurrency or smarter groupings.
      
      ### Why
      Currently the export worker is set up to handle indivdual pages. We fire
      off an exportPage request to all of the known paths and jest-worker
      handles concurrency & parallelization.
      
      ### How
      This refactors the export worker to accept an array of paths. For this
      iteration, it doesn't attempt to do any smart grouping of paths (ie ones
      that share a layout, etc), it just tries to create reasonably sized
      groups. It will chunk a minimum of 25 pages per worker, and each worker
      will process `experimental.staticGenerationMaxConcurrency` (defaults to
      2, tbd on final numbers here) exports at a time.
      
      This lets us set up the `IncrementalCache` inside of the worker before
      we process pages. As we process pages, the incremental cache will be
      populated with entries, and subsequent requests will leverage the cache
      rules therein.
      
      This also disables the auto no-cache behavior that we introduced with
      Next 15 during SSG. Unless a fetch is explicitly opting out of caching,
      we'll attempt to cache it during SSG so another worker can re-use it.
      
      Closes NDX-78
      Closes NDX-19
      d365ff80
    • Vercel Release Bot's avatar
      Update Turbopack development test manifest (#68613) · a1c5ca6a
      Vercel Release Bot authored
      This auto-generated PR updates the development integration test manifest
      used when testing Turbopack.
      a1c5ca6a
    • Vercel Release Bot's avatar
      Update Turbopack production test manifest (#68612) · 81525cc7
      Vercel Release Bot authored
      This auto-generated PR updates the production integration test manifest
      used when testing Turbopack.
      81525cc7
    • hrmny's avatar
      chore: port more nextpack scripts (#68586) · 114c2951
      hrmny authored
      ### What?
      
      Ports a few more useful scripts from nextpack, namely:
      
      - `patch-next`
      - `sweep`
      - `build-native` (to clean up incremental artifacts on compiler panics)
      - the macOS compression agent
      114c2951
    • Niklas Mischkulnig's avatar
      Add tests for self-importing packages (#68070) · b564855c
      Niklas Mischkulnig authored
      I've simplified @timneutkens's tests from #66486
      The resolver fix is in https://github.com/vercel/turbo/pull/8820
      
      Closes https://github.com/vercel/next.js/pull/66486
      Related issue: https://github.com/vercel/next.js/issues/66487
      
      ---------
      Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
      b564855c
    • Jiachi Liu's avatar
      Fix favicon merging with customized icons (#67982) · 9568a4f8
      Jiachi Liu authored
      ### What
      
      Support merging the static metadata file conventions `favicon.ico` with
      other customized metadata icon from the module export.
      
      
      ### Why
      
      `favicon.ico` should be displayed everywhere as it's the icon
      representative of the website for all pages. Any customized `icon` in
      metadata export `export const metadata` or `export function
      generateMetadata()` shouldn't override the `favicon.ico` file
      convention.
      
      
      Fixes #55767
      
      ---------
      Co-authored-by: 's avatarhrmny <8845940+ForsakenHarmony@users.noreply.github.com>
      9568a4f8
    • Benjamin Woodruff's avatar
      refactor(turbo-tasks): Merge CELL_COUNTERS and CURRENT_TASK_ID into CURRENT_TASK_STATE (#68607) · 070159a5
      Benjamin Woodruff authored
      ## Why?
      
      - These three task locals were pretty much always entered/exited at the same time.
      - Syntactically, this lead to some awkwardness, as each scope introduces another level of indentation.
      - Each task local adds more entries to the stack traces.
      - While entering/exiting each task local's scope is very cheap, it's not free, and it must happen on every task's await points. One task local instead of three reduces the work that needs to happen.
      
      ## Benchmarking
      
      Any change in performance is too small to benchmark.
      
      ```
      cargo bench -p turbopack-bench -p turbopack-cli -- "hmr_to_eval/Turbopack CSR"
      ```
      
      Manually increased the number of samples and execution time:
      
      ```
      diff --git a/turbopack/crates/turbopack-bench/src/lib.rs b/turbopack/crates/turbopack-bench/src/lib.rs
      index 4e3df12db0..e2f16fb0d6 100644
      --- a/turbopack/crates/turbopack-bench/src/lib.rs
      +++ b/turbopack/crates/turbopack-bench/src/lib.rs
      @@ -127,8 +127,8 @@ enum CodeLocation {
      
       pub fn bench_hmr_to_eval(c: &mut Criterion, bundlers: &[Box<dyn Bundler>]) {
           let mut g = c.benchmark_group("bench_hmr_to_eval");
      -    g.sample_size(10);
      -    g.measurement_time(Duration::from_secs(60));
      +    g.sample_size(50);
      +    g.measurement_time(Duration::from_secs(300));
      
           bench_hmr_internal(g, CodeLocation::Evaluation, bundlers);
       }
      ```
      
      Using a machine configured for low-noise: https://github.com/bgw/benchmark-scripts
      
      **Before:**
      ```
      bench_hmr_to_eval/Turbopack CSR/1000 modules
                              time:   [14.713 ms 14.779 ms 14.862 ms]
      Found 1 outliers among 50 measurements (2.00%)
        1 (2.00%) high mild
      ```
      
      **After:**
      ```
      bench_hmr_to_eval/Turbopack CSR/1000 modules
                              time:   [14.732 ms 14.800 ms 14.886 ms]
                              change: [-1.1606% +0.1132% +1.5420%] (p = 0.86 > 0.05)
                              No change in performance detected.
      Found 1 outliers among 50 measurements (2.00%)
        1 (2.00%) high mild
      ```
      070159a5