1. 21 Apr, 2025 11 commits
    • vercel-release-bot's avatar
      v15.4.0-canary.2 · b90d1600
      vercel-release-bot authored
      b90d1600
    • Benjamin Woodruff's avatar
      fix(turbo-persistence): Fix `verify_sst_content` feature, improve unit test performance (#78388) · a3cfbd5d
      Benjamin Woodruff authored
      ## Why?
      I'm trying to run https://github.com/boshen/cargo-shear over our workspace to remove unused dependencies. It runs `cargo expand` with `--all-features`, which was breaking on this crate.
      
      ## Changes Summary
      
      - Add `opt-level = 1` in dev for this crate.
      - Reduce the iterations used in tests. If we really want tons of iterations, we should use benchmarks or write a fuzzer utility. Unit tests should be small and fast.
      - Increase the test for blobs to use a 65KiB blob size and assert that's larger than the blob threshold.
      - Cleanup: Use the more-correct `u32` type for the `family` field in a few more places instead of `usize` and make the numeric representations of the `KeySpace` enum a bit more explicit.
      
      ## Prior to these changes
      - Building with `--features turbo-persistence/verify_sst_content` would fail with compilation errors
      - Unit tests would take multiple minutes to run
      - The blob test didn't appear to actually test blobs (10KiB < 64KiB)
      
      ## After these changes
      - The `verify_sst_content` feature works and passes unit tests
      - Unit tests finish in about a minute with `cargo test` and `cargo nextest`, this is still slow, but much better than it was.
      - Unit tests actually test blobs as intended.
      
      ![Screenshot 2025-04-21 at 2.12.32 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/HAZVitxRNnZz8QMiPn4a/ff7aa104-c193-4514-9fde-1a6fcc11acf8.png)
      
      ## Potential future work
      It would be useful to be able to adjust the medium and large (blob) size thresholds to allow us to lower those thresholds in tests.
      a3cfbd5d
    • Vercel Release Bot's avatar
      Update Turbopack production test manifest (#78371) · b77356a6
      Vercel Release Bot authored
      This auto-generated PR updates the production integration test manifest used when testing Turbopack.
      b77356a6
    • vercel-release-bot's avatar
      v15.4.0-canary.1 · 68e62be3
      vercel-release-bot authored
      68e62be3
    • Donny/강동윤's avatar
      refactor(turbopack): Remove needless code (#78331) · a0696f22
      Donny/강동윤 authored
      ### What?
      
      - Use `analyze.references()` beacuse we need imports to be in `esm_references`.
      
      ### Why?
      
      It's identical but cleaner.
      
      
      Closes PACK-4397
      a0696f22
    • Wyatt Johnson's avatar
      fix: handle incremental PPR with client segment cache (#78387) · b8675611
      Wyatt Johnson authored
      This pull request introduces changes to enhance the handling of prefetch
      segment data routes in the Next.js build process and adds new test cases
      to validate these updates. Key changes include the addition of a new
      `buildInversePrefetchSegmentDataRoute` utility, modifications to the
      route generation logic, and the introduction of experimental features
      like `clientSegmentCache`. This addresses a bug where conflicting routes
      while incremental PPR was enabled that matched routes incorrectly, for
      example:
      
      ```
      /~/monitoring <- PPR disabled
      /[teamSlug]/monitoring <- PPR enabled
      ```
      
      Would previously cause client segment requests for `/~/monitoring` to
      match `/[teamSlug]/monitoring`. This addresses it by adding early
      rewrites to handle this case. This will be removed in future versions
      when incremental PPR is deprecated.
      
      ### Enhancements to prefetch segment data routes:
      
      * Added a new utility, `buildInversePrefetchSegmentDataRoute`, to
      support inverted prefetch segment data routes, which rewrite from
      segment paths back to prefetch RSC routes. This is particularly useful
      for handling dynamic routes without conflicts when partial prerendering
      is disabled
      (`packages/next/src/server/lib/router-utils/build-prefetch-segment-data-route.ts`).
      * Updated the `PrefetchSegmentDataRoute` type to include `routeKeys` for
      better route matching and added logic for generating these keys
      (`packages/next/src/server/lib/router-utils/build-prefetch-segment-data-route.ts`).
      [[1]](diffhunk://#diff-35b900720f7fd8bc8995f5dad9880b2ffafba0638ec6c949efc9ba34b0acc9cbR15)
      [[2]](diffhunk://#diff-35b900720f7fd8bc8995f5dad9880b2ffafba0638ec6c949efc9ba34b0acc9cbL27-R29)
      * Modified the build process to utilize
      `buildInversePrefetchSegmentDataRoute` for dynamic routes with undefined
      segment paths when `clientSegmentCache` is enabled
      (`packages/next/src/build/index.ts`).
      
      ### Codebase improvements:
      
      * Added `originalAppPath` to the `PageInfo` interface to track the
      original path of app pages and routes, improving route handling logic
      (`packages/next/src/build/utils.ts`).
      * Simplified the logic for appending prefetch segment data routes by
      directly pushing the result of `buildPrefetchSegmentDataRoute` instead
      of using intermediate variables (`packages/next/src/build/index.ts`).
      
      ### Testing and experimental features:
      
      * Added comprehensive unit tests for
      `buildInversePrefetchSegmentDataRoute` to ensure correct behavior and
      compatibility with existing route utilities
      (`packages/next/src/server/lib/router-utils/build-prefetch-segment-data-route.test.ts`).
      * Introduced a new E2E test suite for validating conflicting routes and
      prefetching behavior under the experimental `clientSegmentCache` feature
      (`test/e2e/app-dir/segment-cache/conflicting-routes`).
      * Enabled experimental features like `clientSegmentCache` and `ppr`
      (partial prerendering) in the test configuration to validate their
      integration
      (`test/e2e/app-dir/segment-cache/conflicting-routes/next.config.js`).
      
      <!-- Thanks for opening a PR! Your contribution is much appreciated.
      To make sure your PR is handled as s
      moothly as possible we request that you follow the checklist sections
      below.
      Choose the right checklist for the change(s) that you're making:
      
      ## For Contributors
      
      ### Improving Documentation
      
      - Run `pnpm prettier-fix` to fix formatting issues before opening the
      PR.
      - Read the Docs Contribution Guide to ensure your contribution follows
      the docs guidelines:
      https://nextjs.org/docs/community/contribution-guide
      
      ### Adding or Updating Examples
      
      - The "examples guidelines" are followed from our contributing doc
      https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
      - Make sure the linting passes by running `pnpm build && pnpm lint`. See
      https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md
      
      ### Fixing a bug
      
      - Related issues linked using `fixes #number`
      - Tests added. See:
      https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
      - Errors have a helpful link attached, see
      https://github.com/vercel/next.js/blob/canary/contributing.md
      
      ### Adding a feature
      
      - Implements an existing feature request or RFC. Make sure the feature
      request has been accepted for implementation before opening a PR. (A
      discussion must be opened, see
      https://github.com/vercel/next.js/discussions/new?category=ideas)
      - Related issues/discussions are linked using `fixes #number`
      - e2e tests added
      (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
      - Documentation added
      - Telemetry added. In case of a feature if it's used or not.
      - Errors have a helpful link attached, see
      https://github.com/vercel/next.js/blob/canary/contributing.md
      
      
      ## For Maintainers
      
      - Minimal description (aim for explaining to someone not on the team to
      understand the PR)
      - When linking to a Slack thread, you might want to share details of the
      conclusion
      - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
      - Add review comments if necessary to explain to the reviewer the logic
      behind a change
      
      ### What?
      
      ### Why?
      
      ### How?
      
      Closes NEXT-
      Fixes #
      
      -->
      b8675611
    • vercel-release-bot's avatar
      v15.4.0-canary.0 · 8ed3b934
      vercel-release-bot authored
      8ed3b934
    • Benjamin Woodruff's avatar
      fix(turbo-tasks): Make vc types use repr(transparent) (#78327) · 8ff308e8
      Benjamin Woodruff authored
      I thought this was already here, but @lukesandberg pointed out it wasn't. I'm pretty sure we're doing transmutes in a few places that assume this, so we should have it.
      
      There's likely no change in behavior: The only sane memory layout for these types is the transparent one, but the annotation guarantees it for our unsafe code.
      8ff308e8
    • Maria Vanessa Salim's avatar
      docs: improve userAgent device.type example in userAgent.mdx (#78368) · 5cd6fdfa
      Maria Vanessa Salim authored
      ### What?
      
      Updates the `userAgent` middleware example in the documentation to
      accurately reflect all possible values of `device.type` and demonstrate
      proper handling of desktop browsers (undefined case).
      
      ### Why?
      
      The current example shows a binary mobile/desktop check which doesn't
      accurately reflect the API's capabilities. The `device.type` property
      can actually return multiple values ('mobile', 'tablet', 'console',
      'smarttv', 'wearable', 'embedded', or undefined), but the example only
      shows handling of 'mobile', which could mislead developers.
      
      ### How?
      
      - Updated both TypeScript and JavaScript examples to:
      1. Add comprehensive comments documenting all possible `device.type`
      values
      2. Use proper undefined handling with the OR operator for desktop
      browsers
        3. Maintain consistency between TS and JS versions
        4. Better align with the documented behavior in the API reference
      - Ran `pnpm prettier-fix` to ensure proper formatting
      - Followed the [Docs Contribution
      Guide](https://nextjs.org/docs/community/contribution-guide)
      
      The changes help developers better understand:
      - The full range of device types they can detect
      - How desktop browsers return undefined
      - The proper way to handle device type detection
      - Consistency with the rest of the API documentation
      
      ### Checklist
      
      - [x] Read the [Docs Contribution
      Guide](https://nextjs.org/docs/community/contribution-guide)
      - [x] Ran `pnpm prettier-fix` to fix formatting issues
      - [x] Ensured examples are clear and follow documentation best practices
      - [x] Maintained consistency with existing documentation style
      - [x] Verified the accuracy of the technical information
      
      ---------
      Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
      5cd6fdfa
    • Andrew Clark's avatar
      Reserve bandwidth for most recently hovered link (#78362) · 4857fcee
      Andrew Clark authored
      The prefetch scheduler limits the number of concurrent prefetch
      requests, to avoid saturating browser's internal network queue. As a
      starting point, I had previously hardcoded this to 3 — intentionally
      stingy, to leave room for additional optimizations.
      
      In this PR, I allow the most recently hovered link to exceed the default
      limit. This increased limit only applies to the *most recently* hovered
      link; if a different link is hovered, the previous one is bumped back
      down to the default.
      
      The principle is that when hovering over a new link, we should have
      enough bandwidth to start prefetching its data. (In practice, because we
      don't cancel in-progress requests, it's still possible that we'll fill
      up the queue, but this makes it less likely.)
      
      As part of this change, I changed the implementation of the internal
      Intent priority level. Intent used to assigned to any link that was ever
      hovered over; it would never get bumped back down to Default, even on
      mouseexit. This was intentional at the time, but given this new
      optimizaiton, it makes more sense to downgrade previously hovered links
      to free up the bandwidth.
      4857fcee
    • Andrew Clark's avatar
      Add onInvalidate option to router.prefetch (#77880) · 4df1a08f
      Andrew Clark authored
      This commit adds an `onInvalidate` callback to `router.prefetch()` so
      custom `<Link>` implementations can re-prefetch data when it becomes
      stale.
      
      The callback is invoked when the data associated with the prefetch may
      have been invalidated (e.g. by `revalidatePath` or `revalidateTag`).
      
      This is not a live subscription and should not be treated as one. It's a
      one-time callback per prefetch request that acts as a signal: "If you
      care about the freshness of this data, now would be a good time to
      re-prefetch."
      
      The supported use case is for advanced clients who opt out of rendering
      the built-in `<Link>` component (e.g. to customize visibility tracking
      or polling behavior) but still want to retain proper cache integration.
      When the callback is fired, the component can trigger a new call to
      `router.prefetch()` with the same parameters, including a new
      `onInvalidate` callback to continue the cycle.
      
      (For reference, `<Link>` handles this automatically. This API exists to
      give custom implementations access to the same underlying behavior.)
      
      Note that the callback *may* be invoked even if the prefetched data is
      still cached. This is intentional—prefetching in the app router is a
      pull-based mechanism, not a push-based one. Rather than subscribing to
      the lifecycle of specific cache entries, the app occasionally polls the
      prefetch layer to check for missing or stale data.
      
      Calling `router.prefetch()` does not necessarily result in a network
      request. If the data is already cached, the call is a no-op. This makes
      polling a practical way to check cache freshness over time without
      incurring unnecessary requests.
      4df1a08f
  2. 19 Apr, 2025 2 commits
    • vercel-release-bot's avatar
      v15.3.1-canary.15 · 21d2a32d
      vercel-release-bot authored
      21d2a32d
    • Tobias Koppers's avatar
      [Turbopack] refactor persistent caching from log based to cow approach (#76234) · 0dd0f20a
      Tobias Koppers authored
      ### What?
      
      Instead of collecting all modifications to the task graph in a log
      structure (which ends up taking a lot of memory), use a modified and
      snapshot flag to avoid using more memory than needed.
      
      This way we don't store extra memory before a snapshot is requested.
      Once a snapshot is captured, we store at most twice the memory. We store
      only the memory of the modified tasks.
      
      It works this way:
      
      Idle Phase: (before a snapshot is requested)
      
      * When a task is modified, we only set the modified flag on that task.
      
      Capturing a snapshot want to avoid locking all tasks. So it first
      switches to the Snapshot Phase.
      
      Snapshot Phase: (after a snapshot is captured)
      
      * When a task is modified:
        * If there is already a snapshot, skip
      * If the task has the modified flag set, clone the task and store the
      snapshot.
      * If the task doesn't have the modified flag set, store a None snapshot.
      
      To actually capture the snapshot, go over all modified or snapshot tasks
      (which is stored in a separate map):
      
      * If the task has a snapshot (not None) stored, use that.
      * If the task has only the modified flag set, read the task state and
      capture a snapshot from that.
      * There is a race condition here, when the task is modified inbetween.
      We handle that by having a snapshot flag too.
      
      We have all snapshot captured now. To leave Snapshot Phase, we 
      
      * First unset all modified flags.
      * Switch to Idle Phase.
      * Change all stored snapshots to modified.
      0dd0f20a
  3. 18 Apr, 2025 9 commits
  4. 17 Apr, 2025 18 commits