This PR updates the way we preload fonts. Previously we tracked which
fonts we needed to preload for each layer and rendered a `<link
rel="preload" href="..." as="font" />` tag for each preloadable font.
This unfortunately gets blocked by data fetching and we want to be able
to hint these preloads as soon as possible. Now that React support Float
methods in RSC we can use `ReactDOM.preload(..., { as: "font" })` to
implement this functionality
This PR makes the following changes
1. expose a `preloadFont` method through the RSC graph
2. expose a `preconnect` metho through the RSC graph
3. refactor the preloads generation to use `preloadFont` instead of
rendering a preload link
4. If there are no fonts to preload but fonts are being used in CSS then
a `preconnect` asset origin is called instead of rendering a preconnect
link
5. instead of emitting a data attribute per font preload indicating
whether the project is using size-adjust we now emit a single global
meta tag. In the future we may get more granular about which fonts are
being size adjusted. In the meantime the current hueristic is to add
`-s` to the filename so it can still be inferred.
In the process of completing this work I discovered there were some bugs
in how the preconnect logic was originally implemented. Previously it
was possible to get multiple preconnects per render. Additionally the
preconnect href was always `"/"` which is not correct if you are hosting
your fonts at a CDN. The refactor fixed both of these issues
I want to do a larger refactor of the asset loading logic in App-Render
but I'll save that for a couple weeks from now
Additionally, the serialized output of preloads now omits the word
anonymous when using crossorigin so tests were updated to reflect
`crossorigin=""`
Additionally, tests were updated to no longer look for the size-adjust
data attribute on preloads
Additionally, There is a note about leaving a `{null}` render in place
to avoid a conflict with how the router models lazy trees. I'll follow
up with a PR addressing this
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
### What?
Implements resolving of `runtime` and `preferredRegion` in layouts. It
will resolve from the root layout down, each layout can override
`runtime` or `preferredRegion`.
```
app
├── layout.js -> export const runtime = 'edge'
├── page.js -> Edge runtime
└── dashboard
├── page.js -> Edge runtime
└── settings
├── layout.js -> export const runtime = 'nodejs'
└── page.js -> Node.js runtime
```
Adds support for `preferredRegion`. This is similar to `export const
config = { region: ['sfo1'] }` in `pages`.
However, there is a difference. It supports `export const
preferredRegion = 'home'` and `export const preferredRegion = 'edge'`.
`home` refers to the configured default region on your deployment
platform and `edge` refers to "all regions".
### How?
I've implemented a temporary resolving in `entries.ts`.
`preferredRegion` is tracked through the entry module in webpack which
is why it's added to all the loaders that create an entry module, this
prevents having to resolve/parse again later on.
Fixes NEXT-880
Fixes NEXT-1064
Fixes#48905Closes#48933
We bumped `undici` fetch which has a minimum version of 16.8.0 so we need to make sure `next` and `create-next-app` also have the same minimum version.
Since 14.x reaches End-of-Life on [2023-04-30](https://github.com/nodejs/Release), we can drop support for 14 in the next release.
See also:
- Related to #48870
- Related #48941
### What?
In #48928 we decided to error for the missing `id` from `generateImageMetadata` and `generateSitemaps` for better dev DX. This PR also refactors the metadata image urls generation that assumbling the utils together
# What?
This PR just refines some of the typescript types around `nextJest`, specifically refining the argument `customJestConfig` and the return value.
### Why?
Before this PR, the return type of `nextJest` was inferred by typescript as `any` which is inaccurate and would require type casting for typescript to enable it to be used in a jest configuration written in typescript.
I didn't add an issue for this since it was so trivial, but I can do so if it would be helpful.
* Fix the `generateImageMetadata` for non dynamic routes and related
`param` matching (Found during development)
* Fix dynamic routes with number suffix `(\d)` (Fixes#48689)
### What?
Exposing `globalThis.crypto`, based on [Node.js' WebCrypto
API](https://nodejs.org/api/globals.html#crypto_1)
### Why?
Similar to `fetch`, `crypto` is a popular API that is currently not
available on `globalThis` in all active Node.js versions yet.
This can help library authors to create runtime-agnostic packages.
### How?
Node.js already has the WebCrypto API that can be imported, we just
expose it on `globalThis` in Node.js versions where this is not
available.
Closes NEXT-1063
[Slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681821510191059)
The current implementation is throwing wrongly if you set a falsy JS value (like `0` or `null`)
So right now this is fail even it's a legit implementation: `process.counter = 0`
Mostly mirrors the changed made in
https://github.com/facebook/react/pull/26632 to our SWC transform. The
implementation difference is that the AST transformer only adds a
general purpose wrapper call `createServerReference(id)` from an aliased
import, so we can easily change the underlying function in the bundler.
This change only affects the client layer (when `self.config.is_server
=== false`).
Needs to be landed after another React upgrade:
https://github.com/vercel/next.js/pull/48697.
cc @sebmarkbage.
## What
We recently added the searchParams as part of the __PAGE__ key in the
router. There were still a few cases where it incorrectly checked equals
instead of startsWith.
## How
Searched for ` '__PAGE__'` in order to find the leftover cases and
changed them.
<!-- 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 or adding/fixing 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 #
-->
This PR implements preloading of CSS from RSC.
1. The underlying Flight protocol was extended in
https://github.com/facebook/react/pull/26502 to allow sending hints from
RSC to SSR and Client runtimes. React was updated to include these
changes.
2. We now call `ReactDOM.preload()` for each stylesheet used in a
layout/page layer
There are a few implementation details to take note of
1. we were previously using the `.browser` variant of a few React
packages. This was a holdover from when there was just browser and node
and we wanted to use the browser variant b/c we wanted the same code to
work in edge/node runtimes. React now publishes a `.edge` variant which
is like `.browser` but expects to be server only. This is necessary to
get the opt-in for `AsyncLocalStorage`.
2. Even with the above change, AsyncLocalStorage was not patched on the
global scope until after React was loaded. I moved this into a module
which is loaded first
3. The component passed to RSC's `renderToReadableStream` is not
actually part of the RSC module graph. If I tried to call
`ReactDOM.preload()` inside that function or any other function defined
inside `app-render.tsx` file it would actually see the wrong instance of
`react-dom`. I added a new export on the RSC top level export which
exposes a `preloadStyle(...)` function which just delegates to
`ReactDOM.preload(...)`. This makes the preload run in the right module
graph
~There are a couple of bugs in React that this work uncovered that I
will upstream. We may want to delay merging until they are addressed.
I'll update this comment when that is complete.~
1. ~React, during SSR, can emit a preload for a style twice in some
circumstances because late discovered stylesheets don't consider whether
a preload has already been flushed when preparing to reveal a boundary
they are within~
2. ~React, during RSC updates on the client, can preload a style that is
already in the document because it currently only looks for existing
preload links and does not consider if there is a stylesheet link with
the same href.~
~both of these issues will not break functionality, they just make the
network tab look at bit more noisy. We would expect network deduping to
prevent multiple actual loads~
The above React bugs were fixed and included now in the React update in
this PR
---------
Co-authored-by: Shu Ding <g@shud.in>
### What?
Mux reported they're experiencing a specific case where scroll wasn't
applied. I've found a bug when the first element in a layout or page,
the one that React will return from `findDOMNode`, is display: hidden.
At that point the rect is is `0` `0` `0` `0` and the current logic
assumes that means it's in the viewport as it's top `0`.
In order to fix this I've looked at a few ways:
- Scrolling to top when the element is not visible
- Scrolling to the parent element that is visible
- **Scrolling to the closest sibling (nextSibling) of the element that
is visible**
Eventually I landed on the third option after looking at the Mux case,
my reproduction, and the way vercel.com's pages leveraging App Router
are structured.
### How?
Used a while loop to check if the domNode is visible, if not we continue
to the next sibling until one that is visible is found. If none are
found we bail on resolving further.
While looking into this it highlighted that we should add a global
scroll handler in app-router too for the case where none of the
layout-routers apply scroll. With this fix that is less urgent though so
I've added a todo.
Fixes NEXT-1056
<!-- 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 or adding/fixing 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 #
-->
The prefetch method is currently an async method but there's nothing to await. It's updated out-of-band. It shouldn't return a Promise.
I also found a console.log that looked out of place.
### Why
Default font file of `@vercel/og` is not loaded, because the og package is bundled by webpack and we should external it so that `fs.readFileSync` is bundled and manged that can't be traced by nft.
### How
This PR externals `@vercel/og` so that they don't need to be bundled and files can be properly traced
Closes NEXT-1047
Fixes#48704
### What
For dynamic routes you might have different sitemap for different params
* Unloack using `sitemap.[ext]` in your app everywhere
* Support `generateSitemaps()` to create multiple sitemaps at the same time
### How
* Change the metadata regex to allow use sitemap in every routes
* Similar approach to `generateImageMetadata`, we make `sitemap.js` under dynamic routes to a catch all routes, and it can have multiple routes
Closes NEXT-1054
This PR changes `mutableCookies` from `RequestCookies` to a
`ResponseCookies` instance, and it now accepts extra options for each
cookie. Take a look at the tests for more details.
cc @styfle
---------
Co-authored-by: Steven <steven@ceriously.com>
Similar to #47922 but based off the latest server implementation and #48626:
> This PR implements the MutableRequestCookies instance for cookies() based on the current async context, so we can allow setting cookies in certain places such as Server Functions and Route handlers. Note that to support Route Handlers, we need to also implement the logic of merging Response's Set-Cookie header and the cookies() mutations, hence it's not included in this PR.
>
> fix [NEXT-942](https://linear.app/vercel/issue/NEXT-942)
This PR also adds the same support for Custom Routes.
cc @styfle.
fix NEXT-942, fix NEXT-941.
## What?
When investigating #48852 I found that when there's a `segmentPath` set
in the `focusAndScrollRef` it would compare that entire path with the
`segmentPath` of the layout-router. This logic works in cases where the
entire page is rendered but doesn't take into account cases where for
example a suspense boundary is triggered below the common layout.
Because of the order `useEffect` is run in we can already assume that if
a more specific match existed it would have scrolled there. As that is
not the case in e.g. #48852 it ended up opting out of scrolling
entirely. In order to fix that the logic needs to be different, it needs
to check if the layout-router's `segmentPath` matches, if it matches
every level then we can apply scrolling in that layout-router.
## How?
Implemented the opposite of the current logic, running `.every` on the
layout-router segmentPath instead of on the router provided segmentPath.
Fixes#48852
Fixes NEXT-1053
Related PR #48862
<!-- 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 or adding/fixing 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 #
-->
We were adding filling in our cleanup function after we started our server. So If we restarted while the server was starting, we would fire an empty cleanup function which would lead to the server not being cleaned up (once it starts).
The only slight issue is that it won't watch for changes while cleaning up the previous run (waiting for the server from the last run to start and finish).
fix NEXT-1052
It makes more sense to use the `FormData` from `@edge-runtime/primitives` to ensure the version and implementation are aligned, and avoid importing extra modules (as we always import the Edge Runtime).
Part of #47759 (which had been reverted twice so here we only land a part of the change), relates to NEXT-926. Thanks to #48506 we can soon switch between these two channels during runtime.
Also fixes a problem of `renderKind` (only revealed after upgrading React), it should be also based on the `match` kind.
This is currently an overhead, that we check a module's layer (`mod.buildInfo.rsc?.type === RSC_MODULE_TYPES.client`) and put all client modules in the client reference manifest, but the manifest is only used for accessing these entry modules. So here we change the util to check if it's an client entry instead.
With this change the client manifest of a test app decreased from 177 KB to 70 KB.
Ref: 5b609e264f/packages/next/src/build/analysis/get-page-static-info.ts (L50-L64)
### What?
Mux reported that their website does not scroll to hash when clicking a search result. Found it's related to `server-patch` triggering and overriding the hashFragment. That should be preserved similarly to `apply`.
### How?
handleMutable had a default of `null` instead of using the existing value. It should use the existing value.
### What?
Update `@swc/helpers` to `v0.5.1`.
### Why?
Webpack merges `@swc/helpers@v0.4.x` and `@swc/helpers@v0.5.x`, due to `resolve.alias` config in 2f6ff0dab3/packages/next/src/build/webpack-config.ts (L1070-L1072)
To workaround it, `@swc/helpers@v0.5.1` reexports from entries just like `v0.4`.
### How?
Closes WEB-948
Fixes#48593
A change here: (#48202) 958150d
Caused a URL to be joined with `path.join`, which on Windows inserts a backslash character. Changing to `path.posix.join` fixes this.
Breaks next build on Windows when paths like `favicon.ico` are in the source dir.
Fixes#48603
When you're using `config` object with `runtime` we'll show a warning and recomment you to move to `export const runtime = ...` for runtime property as it's documented as recommended. This PR adds a error for `next build` to avoid logs are truncated during multi-workers build and you're aware of the config which doesn't take effect with seeing the error
Follow up for #48630
link [NEXT-426](https://linear.app/vercel/issue/NEXT-426)
We currently use `URLSearchParams` to represent `FormData` but it's not really the same thing. And in Node.js 16 there's no `FormData` available so we can polyfill it via Undici.
Updates the name of Next.js Analytics to Next.js Speed Insights
closes ALY-579
---------
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
### What?
Compiles Next.js core files using the same default target as client-side
files, ensuring that `async`/`await` and such are not turned into
generators.
The client-side files are all opted into compilation during dev/build
already so if you create a browserslist config that will still apply in
the same way. This change only changes the output of the core files.
### How?
Moved the default we use in Next.js into a separate `.js` file so that
it can be imported from the taskfile-swc plugin, this way we're using
the same defaults.
<!-- 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 or adding/fixing 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 #
-->
Draft Mode is very similar to Preview Mode but doesn't include any
additional data.
This PR implements support for Draft Mode in `pages` and a future PR
will implement support in `app`.
fix NEXT-992
When sending a multipart form data, we currently wait until the entire update finishes before we decode it via `decodeReply`. This way is universal in both runtimes (as we don't have `decodeReplyFromBusboy` in Edge), but also not efficient.
This PR changes it to use `decodeReplyFromBusboy` in the Node runtime, which can decode the payload during streaming as well as file update support.
Same purpose as #48297, but without the React channel branching logic to
make it easier to land. Since we have #48478 reverted, we only need to
consider `pages` and `app` inside the require hook.
> This PR aims to improve the current require hook by implementing two
key changes. Firstly, it ensures that the initialization occurs at the
top of the module level for correctness. Secondly, we now set the
NEXT_PREBUNDLED_REACT environment variable at the process level to
ensure that we don't mix the two types of rendering processes and we
always resolve the correct React package.
>
> These improvements are made possible by the changes introduced in PR
https://github.com/vercel/next.js/pull/47857.
>
> Closes [NEXT-231](https://linear.app/vercel/issue/NEXT-231).
This will likely fix#45258 too.
---------
Co-authored-by: JJ Kasper <jj@jjsweb.site>
This PR implements new cache semantics for the app router on the client.
## Context
Currently, on the App Router, every Link navigation is prefetched and
kept forever in the cache. This means that once you visit it, you will
always see the same version of the page for the duration of your
navigation.
## This PR
This PR introduces new semantics for how the App Router will cache
during navigations. Here's a TL;DR of the changes:
- all navigations (prefetched/unprefetched) are cached for a maximum of
30s from the time it was last accessed or created (in this order).
- in addition to this, the App Router will cache differently depending
on the `prefetch` prop passed to a `<Link>` component:
- `prefetch={undefined}`/default behaviour:
- the router will prefetch the full page for static pages/partially for
dynamic pages
- if accessed within 30s, it will use the cache
- after that, if accessed within 5 mins, it will re-fetch and suspend
below the nearest loading.js
- after those 5 mins, it will re-fetch the full content (with a new
loading.js boundary)
- `prefetch={false}`:
- the router will not prefetch anything
- if accessed within 30s again, it will re-use the page
- after that, it will re-fetch fully
- `prefetch={true}`
- this will prefetch the full content of your page, dynamic or static
- if accessed within 5 mins, it will re-use the page
## Follow ups
- we may add another API to control the cache TTL at the page level
- a way to opt-in for prefetch on hover even with prefetch={false}
<!-- 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 or adding/fixing 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 #
-->
link NEXT-1011
### What
`export const runtime = 'experimental-edge'` also work for pages. This
PR add tests for that.
Closes NEXT-426
Follow up for #46631 that to fully remove all related code of the
`experimental.runtime`
This PR corrects the file names of chunks in the flight manifest.
Previously we assume that the chunk file is always named as
`(requiredChunk.name || requiredChunk.id) + '-' + requiredChunk.hash`
and located in `static/chunks`. This isn't always true (see the comment)
especially when a chunk was generated via `import()`. Another mistake
was that we assume that one chunk only generates one file, but it's
actually possible that it depends on multiple files.
This should address many of the "Chunk failed to load" errors.
Closes [#47173](https://github.com/vercel/next.js/issues/47173), fixes
NEXT-847
fix#47173
Closes NEXT-684, closes#43396.
This PR implements a temporary workaround to address the issue that some
browsers are always caching CSS resources during the lifetime of a
session. We re-introduce the versioning query to the resource to avoid
that, and then use Mutation Observer to do GC manually on the client.
Once Float handles that by itself, we can probably remove this.
Note that correctly handling GC here is **required** for correctness,
not an optimization. That's why it took us a while to address this (even
this PR is still a temporary workaround). Imagine that if you have:
```css
h1 {
color: red;
}
```
and then you changed it to:
```css
h1 {
font-size: 300px;
}
```
During HMR, if we don't remove the old resources but only insert the new
one, both will be applied and you will still see the `<h1>` in red,
which is wrong.
Here's a recording of this PR working correctly in Firefox:
https://user-images.githubusercontent.com/3676859/233132831-b88e4d8d-aec9-48c4-9aa7-7c7a149b377d.mp4
Use should only need to configure one `metadataBase` as fixed domain or
url but metadata image routes can still work properly with `VERCEL_URL`
in preview deployments
If you configured `new URL('https://mydomain.com')`, it will work for
canonical url all the time since it's for SEO.
For preview deployments metadata image routes will work with deployment
url as they're always bound with deployment.
For production deployments metadata images routes can be alias to the
configured `metadataBase` as they could be the expected exposed domain
Follow up for #47910
link NEXT-887
If `this.serverOptions.dir` is `'.'` or missing (which seems to be the
case in Vercel's `___next_launcher.cjs`), this code was calling
`require(join('.', '.next', 'server', 'instrumentation'))` which is
`require('.next/server/instrumentation')`; notably, require treats this
differently from `require('./.next/server/instrumentation')`, which is
actually what we need here.
Use `path.resolve` instead so that we pass an absolute path to
`require`, which I confirmed fixes the issue.
### What?
Currently `pushState` / `replaceState` happens in `useEffect`. This
causes a problem with timing as the history navigation will happen the
moment the new page has been rendered. In short that means that you'll
see the new route rendered before the history entry is injected. This
causes some issues:
- Scroll position for back/forward navigation (popstate) is not
preserved correctly
- Safari takes a snapshot of the current page at the point of navigation
that is then used to show when you "swipe to back" on iPhone/iPad/Mac
### How?
This PR changes the approach to `useInsertionEffect` based on the advice
from @sebmarkbage. This runs before the new page contents get committed
so it ensures the history navigation is captured before additional
rendering happens.
<!-- 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 or adding/fixing 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
### Why?
### How?
Closes NEXT-
Fixes #
-->
### What?
Attempt to close WEB-920.
This PR implements next.config.js's `modularizeImports` option to
turbopack. It tries to read next.config.js, and then apply transforms as
same as `next-swc` does. Internally it interops betwen next.config.js's
PackageConfig to swc's PackageConfigs, as it doesn't have necessary
attributes for the Vcs / deserialization.
x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681781435607369)
For static metadata files, we should always generate static routes
instead of generate dynamic routes, so that they won't be deployed as
serverless functions which executing file reading in deployment
We decided in https://github.com/vercel/next.js/pull/48308 that we won't
use `turbo` when packing packages for tests.
This PR removes all code associated with that effort. The whole thing
fas behind a flag, so it shouldn't affect anything.
fix NEXT-1025
### What?
The team working on vercel.com reported that multiple pages were being
compiled when opening a single page. Investigated this a bit and found
it was caused by the matching logic (that also triggers compiling of
matched pages) running before middleware runs.
### How?
Removed this matcher logic, as far as I can tell it's not actually being
used. Probably a leftover from when we provided `page` as a middleware
parameter before we made middleware run in front of all resolving.
Fixes NEXT-999
Fixes NEXT-806
<!-- 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 or adding/fixing 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 #
-->
Currently POST requests to `"use server"` entries are not correctly
handled, and this PR partially fixes the behavior. Note that the
`isMultipartAction` case is still missing as we can't simply use
`busboy`. Later we'll unify the implementation here to always use
FormData via Undici.
Fixes NEXT-1026.
We've supported `export const config = { ... }` to sepecify `runtime`
etc. configs for pages under `app/` for a while. This PR is going to
drop it and only support `export const [config name] = [config value]`
per config
Add a warning if the legacy usage is detectd
Closes NEXT-1016
### What?
This PR ensures the jest configuration is json-serializable. It also
adds a bunch of typescript types.
### Why?
Jest requires that the configuration be json-serializable. See #47407
for details on the issues caused when it isn't. However, prior to this
commit, we were passing the entire next config as a property in the swc
jest transformer options. The next config includes some fields that are
not serializable, such as some functions.
### How?
In this PR we instead pluck the fields out of the next config that we
actually need and pass only those into the swc transformer.
This PR also adds a bunch of more precise typescript types where we were
previously just using `any`. This helps confirm that the configs are
being threaded through correctly. I think this type safety is enough to
confirm this commit and adding tests would just be redundant.
Closes NEXT-901
Fixes#47407
fix NEXT-901 ([link](https://linear.app/vercel/issue/NEXT-901))
---------
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
### What?
Rename originUrl to fetchUrl for clarity.
Also remove remove it from origin fetch annotation because the data is
redundant.
### Why?
- The word fetch better matches the other two parameters fetchType and
fetchIdx
- Because the fetch/origin URL is the actual URL being performed on the
origin fetch, it will always be duplicate data
### What?
In environments where `FileSystemCache` is used, the cache for static
resources such as image files will be broken.
### Why?
Because `fs.readFile(path, 'utf8')` tries to read a file as a `string`.
### How?
Change to use `fs.readFile(path)` to always read files as binary
(`Buffer`).
### What?
This PR fixes misordered CSS `<link>` tags. CSS imports in inner layers
(e.g. a page) should always take precedence over outer layers (e.g. root
layout), but currently it's reversed.
### Why?
In layouts we usually define more general styles like globals, resets,
and layout specific things. And in inner layers and pages, things need
to be more detailed and override upper layers if there're any conflicts.
Previously we defined the component segment as
```tsx
<>
<Component {...props} />
{assets}
</>
```
which is necessary because of `findDOMNode` - if we put `assets` before
the component, we can't find the correct scrolling DOM and position for
that layer.
However, with `assets` being the last Float will receive the reversed
order of resources.
### How?
I changed the `createComponentTree` function to return a `Component` and
`assets` pair, so in the Layout Router they're no longer passed to the
scroll wrapper altogether but separately.
Closes NEXT-983
Fixes#47585, fixes#46347.
fix NEXT-656
---------
Co-authored-by: JJ Kasper <jj@jjsweb.site>
This PR fixes parallel routes navigation with `prefetch={false}`. This
was broken because the optimistic tree created when navigating with
prefetching disabled resulted in a state where the router tree was
expecting an incorrect node to be rendered and suspended until the
imaginary data arrived.
The fix consists of updating the method that creates the optimistic tree
in order to bailout of the optimistic tree creation when there are
multiple parallel routes for the current node.
<!--
## For Contributors
### Improving Documentation or adding/fixing 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 #
-->
fix#48122
link NEXT-1020
---------
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
This PR fixes a bug with interception where the rewritten path passed an
incorrect segment data on production, resulting in a 404.
The fix consists of moving the rewrite pre-processing step that rewrites
the dynamic segment from the originating path to when we actually
generate the rewrite. This is needed because that step does not run on
production. Now it does and signals correctly to the app-render that the
value for the segment can be determined from the path.
Also enables prod testing, which I had forgotten to enable.
<!-- 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 or adding/fixing 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 #
-->
fix#48406
link NEXT-1017
### What?
* Support `generateMetadata(props)` to dynamically generate multiple
metadata images at the same time
```js
// /app/opengraph-image.tsx
import { ImageResponse } from 'next/server';
export async function generateImageMetadata({params}) {
const images = await ...;
return images.map((img, idx) => ({
size: { width: 1200, height: 600 },
alt: img.text,
contentType: 'image/png',
id: idx,
}));
}
export default async function ({params, id}) {
const text = await getTextFor(id);
return new ImageResponse(
(
<div
style={{...}}>
{text}
</div>),
{ width: 1200, height: 600 },
);
}
```
### How?
Use `<metadata image>/[[...__metadata_id__]]/route.js` to catch all
metadata images id, and then use this `params.__metadata_id__` as id
argument for dynamic generate image.
If there's param, then we create `<metadata image>/<id>`, if there's
only 1 static image without dynamic `generateImageMetadata` then we keep
use `<metadata image>`
Closes NEXT-896
This ensures we don't fail to return the full body when storing to
fetch-cache in edge-runtime. Also ensures the fetch cache tests are
running for Node.js v16 correctly.
Fetch handling was also failing on Node.js v16 due to react's use of
`res.clone()` being broken with undici which is fixed in the latest
version of edge-runtime so this bumps that.
x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1681310566927429)
Ensure we handle the use-case where a React Server Component using
`fetch` encounters a `204` response.
---------
Co-authored-by: JJ Kasper <jj@jjsweb.site>
### What?
Fixes a bug where `fetch()` to a page that calls `redirect()` would hang
infinitely.
### How?
The `Location` header was missing. The reason this wasn't surfaced
before is that we also inject the `<meta>` tag to redirect which the
browser would pick up to redirect too.
Fixes NEXT-997
<!-- 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 or adding/fixing 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 #
-->
This updates the app route handler signature to be more correct to
prevent the issue with type casting:
```diff
- (request: Request, ctx) => Response
+ (request: NextRequest, ctx) => Promise<Response> | Response
```
This also ensures that the context paramter has the correct types:
```diff
type AppRouteHandlerFnContext = {
- params?: { [param: string]: any }
+ params?: Record<string, string | string[]>
}
```
Since exiting in `setTimeout()` can cause a race condition with sending
the result from the worker and we don't want to destroy workers when
trying to leverage them as it has a perf impact this ensures we create
unique workers per usage and destroy them afterwards.
x-ref: https://github.com/vercel/next.js/pull/47716
Fixes: https://github.com/vercel/next.js/issues/48061
This PR fixes issues where rendering a new parallel route would reset
the scroll state of the page. This would be very apparent if you
scrolled down the page and opened a modal in a parallel route.
After a bit of investigating, I found out that the scroll behaviour
worked like this:
- after a navigation, we say to the router that we should auto-scroll if
possible
- but we don't specify which node of the tree should scroll
- so what happened is that the first router node to run the auto-scroll
effect would steal the auto-scroll, even though it might have been
destined for another node
The fix consists of
- when we received the flight patch, we compute all new segment paths
that will be rendered and add them to the scroll ref
- when the router says that we should autoscroll, the autoscroll
components will now read those paths and compare them with their segment
path and if yes, they will autoscroll
<!-- 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 or adding/fixing 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 #
-->
link NEXT-974
Closes#48222.
This PR introduces a new utility function that checks the resource path,
module type, and loaders to replace the existing CSS regex in the Flight
loaders and plugins. The new function is more robust and can be extended
to correctly support other libraries such as `vanilla-extract`.
cc @SuttonJack and @SukkaW (this could be related to the other issue
we've discussed too).
When collecting static icons we need both collect the one from layout
and page, but for root level route `/` we missed the `favicon.ico`
before so when other icon existed, the root page's collected icons will
cover root layout collected ones, which resulted into favicon missing
Fixes#48147
Closes NEXT-976
### What
Support `opengraph-image.alt.txt` and `twitter-image.alt.txt` for static
og/tw metadata image when they need to specify alt txt.
Closes NEXT-990
### Why
for og/tw images, you could have multiple images, so it's tricky to set
alt in metadata exports with alt text. For static case we want it can
work with static files, `.alt.txt` files will be the type to provide alt
text content
### What?
The change in #47985 breaks the URLs of static image files like
`/(group)/opengraph-image.png` to `/opengraph-image.png-012345`.
References from `/` are also broken.
### Why?
This is because only `opengraph-image.ts` and `opengraph-image.tsx` are
considered.
### How?
In this Pull Request, we are trying to solve the problem by including
similar support for `opengraph-image.png` and `opengraph-image.jpeg`.
---------
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
In a previous PR (https://github.com/vercel/next.js/pull/46753), the
`originalSource` was saved to be passed along through the build process.
This was done a bit too late in the flow, which made `originalSource`
include some transformations.
Because `originalSource` is used for display purposes, we need it
unmodified. This PR preserves `originalSource`.
This PR fixes an issue where throwing a notFound error in a parallel
route at the top level at the root level would trigger a notfound
boundary at the parallel route level, which meant in practice that you
could still see the other slots being rendered below.
This behaviour is undesirable and was caused by the fact that we were
inserting a default one at each top-level parallel route. This is not
longer needed as we have a global one in `app-router.tsx`
<!-- 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 or adding/fixing 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 #
-->
fixes NEXT-968
This PR adds a new marker for intercepting siblings routes + adds some
validation to intercepting routes ( you shouldn't use (..) at the top
level!)
also fixes a bug with any interception from `/` when navigating from a
child route
the new marker, `(.)`, makes it easier to model cases like
```
/profile/[id]
/profile/[id]/photos/[id]/
```
With the current syntax available, you’d need to do:
```with (..):
/profile/[id]/(..)[id]/photos/[id]
with (...):
/profile/[id]/(...)profile/[id]/photos/[id]
with (..)(..):
/profile/[id]/(..)(..)profile/[id]/photos/[id]
```
now, with (.)
```
/profile/[id]/(.)photos/[id]
```
<!-- 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 or adding/fixing 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 #
-->
link NEXT-935
also fixes NEXT-970
fixes NEXT-973
This PR basically adds support for processing multiple router payloads.
Previously we were only handling one payload at a time but now that we
introduced parallel routes, we need to be able to render and return
separate parts of the layout separately.
Before, the single payload was generated in a DFS manner: we traversed
the router state and rendered the first segment of the tree that we
found needed rendering. In practice, this meant that we could miss
adjacent segments that might need to be re-rendered as well.
Now, we iterate all branches of the tree and return an array of flight
patches to be applied on the client correctly.
fixes NEXT-971
<!-- 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 or adding/fixing 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 #
-->
This unblocks further optimization opportunities as well as fixes for
systematic problems such as NEXT-227. After this PR, only production
mode of non-app projects will be running on the legacy main process
mode.
---------
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Without `top: 0` the route announcer triggers subtle layout shift in
Blink/Chrome.
BTW, this mostly (possibly only?) occurs on pages with specific overflow
proprty combinations on `<html/>` and `<body/>`, and only when rendering
inside a custom element like the `<next-route-announcer />` portal.
(Changing the portal into `<div/>` seems to make the layout shift
disappear, but that would be far more invasive change than just adding
`top:0`.)
---------
Co-authored-by: Shu Ding <g@shud.in>
For now, this isn't a strong requirement as normal `fetch` requests will
still work with `react@next`. But in the future, form related props e.g.
`action=` and `formAction=` requires the experimental build.
Fixes NEXT-954.
Reverts vercel/next.js#48038
fix NEXT-926
---
The root cause was that when copying the package.json, I removed all
fields except for a few (such as `exports`) but missed the `browser`
field. That caused the client bundle to resolve to the Node.js version
of React DOM, and then we had the `async_hooks` error. Added it back in
99c9b9e51f8b0d4e4503ece9d07bce09161f3341.
I reproduced the error with next-site earlier and confirmed that this
fix is good.
### What?
Report additional telemetry related to cached fetches:
- Fetch Index number to group related fetches (cache-get, cache-set,
origin)
- Origin URL map cache key to original upstream URL
### Why?
This is needed for fetch cache telemetry on the Vercel platform.
### How?
Telemetry is provided through optional parameters added to the fetch
call configuration. It is similar to the `next: {revalidate: X}` and
`{next: { internal: true }}` fields.
The origin URL and fetch index are calculated in the patch-fetch
function and are passed down to the caching classes as needed. These
fields are optional and ignored by the `FileSystemCache`.
### What?
Our current logic of detecting if a route allows dynamic params or not
(`fallback`) is flawed, and this PR fixes it.
### Why?
Right now, if no `generateStaticParams` is specified we return
`fallback: undefined` during dev. However, for an app with multiple
params, it may have multiple `generateStaticParams` defined in different
levels. If some level isn't covered by any `generateStaticParams`, we
still can't determine the fallback value.
### How?
I added a naive implementation to check if all params are covered by
`generateStaticParams` in the current or inner layers.
Closes NEXT-946
### What?
This PR makes the parent layout of parallel routes re-render when the
parallel route segments are different or when either of them has a
refetch marker.
Example:
```
.
└── app/
├── page.ts
├── layout.ts
├── foo/
│ └── page.ts
└── @modal/
├── default.js
└── foo/
└── page.ts
```
Here if you navigated to `/foo` from `/`, `@modal/foo/page` would never
get re-rendered because the tree would only re-render from
`foo/page.ts`.
This PR adds a check that checks the router state on navigation to see
if the parallel route segments diverge on navigation. Here we would be
checking that `@modal/default` is different from `@modal/page` so we
would re-render.
Also added some logic to make sure that refetch routes are processed
first when handling parallel routes.
### Why?
See example
Closes NEXT-966
Fixes #
<!-- 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 or adding/fixing 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 #
-->
This accomplishes 2 things:
1. binds the turbopack dev server to the IPv6 unspecified address
2. initializes our router with the same hostname/port of the turobpack
server
The first matches the behavior of the Node.js dev server. The IPv6
unspecified address is similar to IPv4's `0.0.0.0` address, allowing us
to accept connection from anywhere. Importantly, it _also_ allows
accepting IPv4 connections, making this address truly universal.
The second means the `request` parameter to any middleware will have the
correct origin, and the request's URL can be used to craft fetch
requests to API endpoints. `new URL(req.url).origin` will be the origin
of the turbopack dev server.
Fixes https://github.com/vercel/turbo/issues/4456
Fixes WEB-855
With the addition of the query prefix we can hit the max length for PCRE
named matches so this reduces the prefix length and ensures we go
through the param name validation still
x-ref: https://twitter.com/simonecervini/status/1644123851003928579
### What?
Change the caching logic for fetch-cache to only cache successful
responses.
### Why?
Currently fetch-cache will cache any response, without checking the http
status code. But situations like 500 and 304 and others should not be
cached, because we want to re-fetch from the origin.
### How?
Add an extra check before deciding to call `incrementalCache.set()`
---------
Co-authored-by: JJ Kasper <jj@jjsweb.site>
This ensures the prefix for route params is stripped when pulled from
the revalidate headers. Also updates tests accordingly.
x-ref: https://github.com/vercel/next.js/pull/47930
The first implementation had limitation wrt to static routes so this is
a "simpler" approach to making interception work. This also fixes a few
bugs.
In this PR:
- changed the computation of the referrer route to now live on the
client state, since it's the only place where you can accurately keep
track of that. One router state was not sufficient, we needed a delta of
two states to guess which route had changed when having parallel routes
in the tree.
- uses rewrites as the basis for interception now instead of route
handlers, this means that we have to do some sketchy logic to make the
rules work since they only handle regexes whereas we have
`path/like/[this]`
- dev server now reloads rewrites as well when needed
<!-- 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 or adding/fixing 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 #
-->
### What
This issue is introduced in #47688, we need to do the same work for
rendering single component which collecting the assets and then render
with root layout + root not found
Fix#47970
Related #47862 (partially fix the css issue but not link issue)
### How
This PR encapsulates the preload and stylesheets assets collection and
rendering process, and move them into a helper, and share between the
component rendering and the root not found rendering
### Fixing a bug
Follow-up to https://github.com/vercel/next.js/pull/47761: It seems that
`handleHardNavigation` needs to take `as` instead of `url`, in order to
be consistent with the rest of the code.
Without this, it seems to cause an issue if you are using a link that
uses legacy `as` prop which matches the bloom filter (and therefore
`__appRouter` is set as `true`).
However, I spent couple hours trying to come up with a failing test case
without this change but unfortunately couldn't come up with one.
x-ref: [Slack
Thread](https://vercel.slack.com/archives/C017QMYC5FB/p1680668865572729?thread_ts=1680225393.243459&cid=C017QMYC5FB)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
This pull request extends the type checking functionality of the
`typedRoutes` feature, which is currently available in the `<Link
href={Route}>` component, to the following `router` APIs:
`router.push()`, `router.prefetch()`, and `router.replace()`. The
implementation leverages the existing work done for the `<Link>`
component, allowing for a straightforward integration of type checking
into the aforementioned `router` APIs.
fix NEXT-501
### What
When using dynamic metadata image rouets (such as `opengraph-image.js`)
under group routes, the generated urls were still normalized. In this
case it might have conflicts with those ones not under group routes. For
instance `app/(post)/opengraph-image.js` could have same url with
`/app/opengraph-image.js`. In reality we want them to be different
route, unlike layout or pages.
### How
So when we found `()` or `@` signs from the metadata image urls, we'll
generate a unqiue suffix (`-\d{6}`) and append to the generated url. So
they can be isolated from the ones are not under special convention
routes.
Closes NEXT-937
For twitter and og image nested properties we should render them as
snake case according to [og spec](https://ogp.me/) and [twitter card
docs](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started).
For typing we keep them as camel case and then convert them to snake
case during render
This issue is reported in #47960 that user thinks the types are
incorrect, but turns out twitter metadata didn't render it correctly
Closes#47960
This ensures we prefix the dynamic route params in the query so that
they can be kept separate from actual query params from the initial
request.
Fixes: https://github.com/vercel/next.js/issues/43139
This is a follow-up PR on https://github.com/vercel/next.js/pull/46577
after it got nasty conflicts.
Basically, just restart `dev` when `next.config.ts` it will just restart
instead of printing that message asking you to restart.
fix NEXT-639