1. 07 Aug, 2023 7 commits
  2. 06 Aug, 2023 5 commits
  3. 05 Aug, 2023 5 commits
  4. 04 Aug, 2023 22 commits
    • Lee Robinson's avatar
      docs: fix typo on caching page (#53597) · b7aa7d4a
      Lee Robinson authored
      - reduce: `MISS`
      - reduces: `HIT`
      b7aa7d4a
    • Josh Story's avatar
      Implement new forking technique for vendored packages. (#51083) · e06880ea
      Josh Story authored
      ## Vendoring
      
      Updates all module resolvers (node, webpack, nft for entrypoints, and nft for next-server) to consider whether vendored packages are suitable for a given resolve request and resolves them in an import semantics preserving way.
      
      ### Problem
      
      Prior to the proposed change, vendoring has been accomplished but aliasing module requests from one specifier to a different specifier. For instance if we are using the built-in react packages for a build/runtime we might replace `require('react')` with `require('next/dist/compiled/react')`.
      
      However this aliasing introduces a subtle bug. The React package has an export map that considers the condition `react-server` and when you require/import `'react'` the conditions should be considered and the underlying implementation of react may differ from one environment to another. In particular if you are resolving with the `react-server` condition you will be resolving the `react.shared-subset.js` implementation of React. This aliasing however breaks these semantics because it turns a bare specifier resolution of `react` with path `'.'` into a resolution with bare specifier `next` with path `'/dist/compiled/react'`. Module resolvers consider export maps of the package being imported from but in the case of `next` there is no consideration for the condition `react-server` and this resolution ends up pulling in the `index.js` implementation inside the React package by doing a simple path resolution to that package folder.
      
      To work around this bug there is a prevalence of encoding the "right" resolution into the import itself. We for instance directly alias `react` to `next/dist/compiled/react/react.shared-subset.js` in certain cases. Other times we directly specify the runtime variant for instance `react-server-dom-webpack/server.edge` rather than `react-server-dom-wegbpack/server`, bypassing the export map altogether by selecting the runtime specific variant. However some code is meant to run in more than one runtime, for instance anything that is part of the client bundle which executes on the server during SSR and in the browser. There are workaround like using `require` conditionally or `import(...)` dynamically but these all have consequences for bundling and treeshaking and they still require careful consideration of the environment you are running in and which variant needs to load.
      
      The result is that there is a large amount of manual pinning of aliases and additional complexity in the code and an inability to trust the package to specify the right resolution potentially causing conflicts in future versions as packages are updated.
      
      It should be noted that aliasing is not in and of itself problematic when we are trying to implement a sort of lightweight forking based on build or runtime conditions. We have good examples of this for instance with the `next/head` package which within App Router should export a noop function. The problem is when we are trying to vendor an entire package and have the package behave semantically the same as if you had installed it yourself via node_modules
      
      ### Solution
      
      The fix is seemingly straight forward. We need to stop aliasing these module specifiers and instead customize the resolution process to resolve from a location that will contain the desired vendored packages. We can then start simplifying our imports to use top level package resources and generally and let import conditions control the process of providing the right variant in the right context.
      
      It should be said that vendoring is conditional. Currently we only vendor react pacakges for App Router runtimes. The implementation needs to be able to conditionally determine where a package resolves based on whether we're in an App Router context vs a Page Router one.
      
      Additionally the implementation needs to support alternate packages such as supporting the experimental channel for React when using features that require this version.
      
      ### Implementation
      
      The first step is to put the vendored packages inside a node_modules folder. This is essential to the correct resolving of packages by most tools that implement module resolution. For packages that are meant to be vendored, meaning whole package substitution we move the from `next/(src|dist)/compiled/...` to `next/(src|dist)/vendored/node_modules`. The purpose of this move is to clarify that vendored packages operate with a different implementation. This initial PR moves the react dependencies for App Router and `client-only` and `server-only` packages into this folder. In the future we can decide which other precompiled dependencies are best implemented as vendored packages and move them over.
      
      It should be noted that because of our use of `JestWorker` we can get warnings for duplicate package names so we modify the vendored pacakges for react adding either `-vendored` or `-experimental-vendored` depending on which release channel the package came from. While this will require us to alter the request string for a module specifier it will still be treating the react package as the bare specifier and thus use the export map as required.
      
      #### module resolvers
      The next thing we need to do is have all systems that do module resolution implement an custom module resolution step. There are five different resolvers that need to be considered
      
      ##### node runtime
      Updated the require-hook to resolve from the vendored directory without rewriting the request string to alter which package is identified in the bare specifier. For react packages we only do this vendoring if the `process.env.__NEXT_PRIVATE_PREBUNDLED_REACT` envvar is set indicating the runtime is server App Router builds. If we need a single node runtime to be able to conditionally resolve to both vendored and non vendored versions we will need to combine this with aliasing and encode whether the request is for the vendored version in the request string. Our current architecture does not require this though so we will just rely on the envvar for now
      
      ##### webpack runtime
      Removed all aliases configured for react packages. Rely on the node-runtime to properly alias external react dependencies. Add a resolver plugin `NextAppResolverPlugin` to preempt perform resolution from the context of the vendored directory when encountering a vendored eligible package.
      
      ##### turbopack runtime
      updated the aliasing rules for react packages to resolve from the vendored directory when in an App Router context. This implementation is all essentially config b/c the capability of doing the resolve from any position (i.e. the vendored directory) already exists
      
      ##### nft entrypoints runtime
      track chunks to trace for App Router separate from Pages Router. For the trace for App Router chunks use a custom resolve hook in nft which performs the resolution from the vendored directory when appropriate.
      
      ##### nft next-server runtime
      The current implementation for next-server traces both node_modules and vendored version of packages so all versions are included. This is necessary because the next server can run in either context (App vs Page router) and may depend on any possible variants. We could in theory make two traces rather than a combined one but this will require additional downstream changes so for now it is the most conservative thing to do and is correct
      
      Once we have the correct resolution semantics for all resolvers we can start to remove instances targeting our precompiled instances for instance making `import ... from "next/dist/compiled/react-server-dom-webpack/client"` and replacing with `import ... from "react-server-dom-webpack/client"`
      
      We can also stop requiring runtime specific variants like `import ... from "react-server-dom-webpack/client.edge"` replacing it with the generic export `"react-server-dom-webpack/client"`
      
      There are still two special case aliases related to react
      1. In profiling mode (browser only) we rewrite `react-dom` to `react-dom/profiling` and `scheduler/tracing` to `scheduler/tracing-profiling`. This can be moved to using export maps and conditions once react publishses updates that implement this on the package side.
      2. When resolving `react-dom` on the server we rewrite this to `react-dom/server-rendering-stub`. This is to avoid loading the entire react-dom client bundle on the server when most of it goes unused. In the next major react will update this top level export to only contain the parts that are usable in any runtime and this alias can be dropped entirely
      
      There are two non-react packages currently be vendored that I have maintained but think we ought to discuss the validity of vendoring. The `client-only` and `server-only` packages are vendored so you can use them without having to remember to install them into your project. This is convenient but does perhaps become surprising if you don't realize what is happening. We should consider not doing this but we can make that decision in another discussion/PR.
      
      #### Webpack Layers
      One of the things our webpack config implements for App Router is layers which allow us to have separate instances of packages for the server components graph and the client (ssr) graph. The way we were managing layer selection was a but arbitrary so in addition to the other webpack changes the way you cause a file to always end up in a specific layer is to end it with `.serverlayer`, `.clientlayer` or `.sharedlayer`. These act as layer portals so something in the server layer can import `foo.clientlayer` and that module will in fact be bundled in the client layer.
      
      #### Packaging Changes
      Most package managers are fine with this resolution redirect however yarn berry (yarn 2+ with PnP) will not resolve packages that are not defined in a package.json as a dependency. This was not a problem with the prior strategy because it was never resolving these vendored packages it was always resolving the next package and then just pointing to a file within it that happened to be from react or a related package.
      
      To get around this issue vendored packages are both committed in src and packed as a tgz file. Then in the next package.json we define these vendored packages as `optionalDependency` pointing to these tarballs. For yarn PnP these packed versions will get used and resolved rather than the locally commited src files. For other package managers the optional dependencies may or may not get installed but the resolution will still resolve to the checked in src files. This isn't a particularly satisfying implemenation and if pnpm were to be updated to have consistent behavior installing from tarballs we could actually move the vendoring entirely to dependencies and simplify our resolvers a fair bit. But this will require an upstream chagne in pnpm and would take time to propogate in the community since many use older versions
      
      #### Upstream Changes
      
      As part of this work I landed some other changes upstream that were necessary. One was to make our packing use `npm` to match our publishing step. This also allows us to pack `node_modules` folders which is normally not supported but is possible if you define the folder in the package.json's files property.
      
      See: #52563
      
      Additionally nft did not provide a way to use the internal resolver if you were going to use the resolve hook so that is now exposed
      
      See: https://github.com/vercel/nft/pull/354
      
      #### additional PR trivia
      * When we prepare to make an isolated next install for integration tests we exclude node_modules by default so we have a special case to allow `/vendored/node_modules`
      
      * The webpack module rules were refactored to be a little easier to reason about and while they do work as is it would be better for some of them to be wrapped in a `oneOf` rule however there is a bug in our css loader implementation that causes these oneOf rules to get deleted. We should fix this up in a followup to make the rules a little more robuts.
      
      
      ## Edits
      * I removed `.sharedlayer` since this concept is leaky (not really related to the client/server boundary split) and it is getting refactored anyway soon into a precompiled runtime.
      e06880ea
    • JJ Kasper's avatar
      Update ISR revalidateTag handling (#53595) · e4aecabc
      JJ Kasper authored
      This ensures `revalidateTag()` doesn't cause an async/background revalidation unexpectedly and instead does a blocking revalidate so fresh data is shown right away when a path is using ISR. 
      
      Test deployment with patch can be seen here: https://next-revalidation-test-47rqf8q5s-vtest314-ijjk-testing.vercel.app/
      
      Fixes: https://github.com/vercel/next.js/issues/53187
      e4aecabc
    • Steven's avatar
    • Wyatt Johnson's avatar
      Remove Base Path from usePathname output (#53582) · 1df2686b
      Wyatt Johnson authored
      This removes the `basePath` from the output of `usePathname`. Previously this always resulted in hydration errors, this now strips the `basePath` when it's found/configured.
      
      Now when you configure `basePath`, you don't have to factor it into your application logic and can instead rely on the values always returning the pathname without it.
      
      Fixes #46562 
      1df2686b
    • Will Binns-Smith's avatar
      Update to turbopack-230804.2 (#53588) · 1d8a6335
      Will Binns-Smith authored
      - vercel/turbo#5671
      - vercel/turbo#5675
      - vercel/turbo#5676
      - vercel/turbo#5662
      - vercel/turbo#5663
      1d8a6335
    • Gonzalo's avatar
      EXAMPLE: fix with-supabase signup button style (#53531) · a66aca1e
      Gonzalo authored
      ### What?
      Fix example `with-supabase` https://github.com/vercel/next.js/tree/canary/examples/with-supabase signup button
      
      ### Why?
      Signup button text color is not the right one so the developer is not able to see the text.
      
      ### How?
      Updated the style using tailwind as it is what we are using in the example.
      
      Before:
      ![image](https://github.com/vercel/next.js/assets/1652286/269c3be1-70ee-4b92-9161-4d1c35cbd01c)
      
      After (Fixed):
      ![image](https://github.com/vercel/next.js/assets/1652286/3aa6af87-7958-470d-bf05-d1187963e792)
      a66aca1e
    • William Li's avatar
    • José Olórtegui's avatar
      docs: update webhook snippet for cache revalidation (#53585) · 49d4f8af
      José Olórtegui authored
      
      This PR updates cache revalidation snippets in the docs. It seems that `res` should not be there since you can't find it anywhere in the snippet so I suppose that the intent was to use `NextResponse` instead. Another thing is that now we're checking the existence of the params so typescript doesn't get mad at us. And last I changed the methods to `POST` since AFAIK webhooks normally use the `POST` method.
      
      Please let me know if there's anything left to do on my side.
      
      Have a great day!
      Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
      49d4f8af
    • Steven's avatar
    • Leah's avatar
    • Tobias Koppers's avatar
    • vercel-release-bot's avatar
      v13.4.13-canary.15 · 324814f2
      vercel-release-bot authored
      324814f2
    • Michal Landsman's avatar
      doc: styled-components has stable version (#53539) · 4b13d807
      Michal Landsman authored
      replace rc.1 by stable version
      Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
      4b13d807
    • Jiachi Liu's avatar
    • Jiachi Liu's avatar
      Fix dynamic route not-found boundary matching (#53564) · ab14895a
      Jiachi Liu authored
      ### What & Why
      
      The dynamic not-found boundary didn't work as expected as it was using the `pathname` to match how many levels of the segements should be matched. For dynamic routes this doesn't work, unlike normal page, the unmatched segment can also hit the not found boundary in the same level.
      
      ### How
      
      Use `segment` of loader tree nodes to determine if not-found boundary searching is reached to the end instead of using `pathname`. 
      > NOTE: For production `/_not-found` case since it's a valid page on production and still has the original tree, so we handle that as a special case to use the not found loader tree (with empty child routes) to render.
      
      Fixes #53344
      ab14895a
    • Jiachi Liu's avatar
      Move metadata error under error boundaries (#53551) · cc4879d1
      Jiachi Liu authored
      ### What & Why
      
      Using `notFound()` in `generateMetadata()` or in page will lead to unacught global not found error when you do navigation, this is because `head` cache is actually not inside the error boundary as designed to stay in the beginning of the content. But in this way we won't be able to catch the notFound error thrown from metadata API. So we created a new approach that can separate the error itself from metadata result, and throw as error under the error boundaries, and metadata itself will always be safe to render.
      
      ### How
      
      We use a new promise that resolve the `error` thrown from metadata resolving, and let the render result always return successfully and always has a value, using default metadata when there's error thrown. Create two components, one rendering the metadata tags, and another `MetadataOutlet` to throw the error when the resolving is failed but rendered under error boundaries.
      
      
      
      ```jsx
      const [MetadataTree, MetadataOutlet] = createMetadataComponents(/*...*/)
      const ComponentTree = createComponentTree({ metadataOutlet: <MetadataOutlet /> })
      
      renderRSC(
        <AppRourer head={<MetadataTree />}>
          <ComponentTree />
        </AppRourer>
      )
      ```
      
      `metadataOutlet` will stay next to page component in the layout hierarchy
      
      discuessed with @gnoff 
      
      Minor changes: 
      
      * When there's rendering root layout layer, not found boundary should be `DefaultNotFound` if the custom one doesn't exisit
      
      
      Fixes #53371
      Fixes #53149
      cc4879d1
    • vercel-release-bot's avatar
      v13.4.13-canary.14 · f04dc5ad
      vercel-release-bot authored
      f04dc5ad
    • Tobias Koppers's avatar
    • Tobias Koppers's avatar
      add support for EXPERIMENTAL_TURBOPACK in next build (#53535) · 82280ea8
      Tobias Koppers authored
      ### What?
      
      EXPERIMENTAL_TURBOPACK env var puts next build into turbopack mode
      
      ### Why?
      
      the test cases set this flag
      82280ea8
    • Colin McDonnell's avatar
      Add `--use-bun` to `create-next-app` (#53467) · 57ce4665
      Colin McDonnell authored
      This adds support for `--use-bun` to `create-next-app` to use `bun
      install` when bootstrapping a new project.
      
      ```
      npx create-next-app --use-bun
      ```
      
      As with Yarn and pnpm, it reads from `npm_config_user_agent` to
      determine if the user ran `bunx create-next-app`. If so, it defaults to
      using Bun.
      
      ```sh
      bunx create-next-app
      ```
      
      ## For Contributors
      
      ### Improving Documentation
      
      - [x] Run `pnpm prettier-fix`
      - [x] `pnpm build && pnpm lint` 
      - [x] Added test to
      `test/integration/create-next-app/package-manager.test.ts`
      
      ---------
      57ce4665
    • lijianan's avatar
      chore: remove useless curly brackets from `next/legacy/image` (#53534) · b224f47f
      lijianan authored
      <!-- Thanks for opening a PR! Your contribution is much appreciated.
      To make sure your PR is handled as smoothly 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 #
      
      -->
      
      remove useless parentheses
      b224f47f
  5. 03 Aug, 2023 1 commit
    • Stef's avatar
      Move USER and remove redundant --chown from Dockerfile (#53441) · 39c06ae9
      Stef authored
      
      
      ### What?
      
      In the Dockerfile example:
      
      * Moves the `USER` command above the `COPY`s
      * Removes the `--chown` on the `COPY`s 
      
      > **Note**
      > I don't know for 100% sure this won't have unintended side effects. Part of my motivation for opening this PR is to sense check whether we will be causing a regression by making this change in our own projects.
      > 
      > Please let me know if there's any concerns with this!
      
      ### Why?
      
      Sonar security scanner flags this Dockerfile as having "security hotspots" due to the use of `--chown`
      
      https://rules.sonarsource.com/docker/RSPEC-6504/
      
      ### How?
      
      Make the `--chown`s redundant by setting the current user before doing the `COPY` commands.
      39c06ae9