Commit Graph
6467 Commits
Author SHA1 Message Date
Jude GaoandGitHub 171970d1c6 Re-enable fetch logging test - HMR (#72640) 2024-11-12 19:51:38 -05:00
0bc2346e83 Fix static indicator for pure IO case (#72639)
Follow-up to https://github.com/vercel/next.js/pull/72631 this ensures
we properly update the `requestStore` when we detect pure IO case and no
dynamic methods are used like `cookies()` or `headers()` e.g. just a
fetch with no caching opts enabled.

---------

Co-authored-by: Zack Tanner <[email protected]>
2024-11-12 16:34:22 -08:00
3c3710bef4 chore: update getting-started/react-essentials path (#72250)
## Description
At #51579, react-essentials.mdx was deleted.
Some URLs doesn't navigate right pages due to this change.
Then I update to correct path.

- Fixes https://github.com/vercel/next.js/issues/72566

---------

Co-authored-by: Sam Ko <[email protected]>
2024-11-12 16:07:47 -08:00
b888c4249e improved network url in (dev) cli (#72634)
Continues: https://github.com/vercel/next.js/pull/57882 with added test
and rebased history

Closes: https://github.com/vercel/next.js/pull/57882

---------

Co-authored-by: Ward Werbrouck <[email protected]>
2024-11-12 22:23:31 +00:00
JJ KasperandGitHub dd8c465080 Fix static indicator with dynamicIO (#72631)
This ensures we don't incorrectly update the static indicator status
during the dev warmup render which was causing it to show unexpectedly
with dynamicIO enabled.
2024-11-12 21:01:06 +00:00
1b1cb3eece Add compiler.define option (#71802)
Adds a `compiler.define` option to next.config.js to statically replace
any variables during build-time for Turbopack. This is similar to
Webpack's `DefinePlugin`.

Relates to: https://github.com/vercel/next.js/discussions/71476

---------

Co-authored-by: Tim Neutkens <[email protected]>
2024-11-12 21:13:47 +01:00
Hendrik LiebauandGitHub 912d42bbf7 Omit unused args when calling "use cache" functions (#72506)
Using the information byte in a server reference ID, as introduced in
#71463, we can omit unused arguments when calling a `"use cache"`
function. This enables us, for example, to use a cached function in
conjunction with `useActionState` when the function does not need the
previous state, as shown below:

```ts
'use cache'

export async function getCachedRandomValue() {
  return Math.random()
}
```

```tsx
'use client'

import { useActionState } from 'react'
import { getCachedRandomValue } from './cached'

export default function Page() {
  const [result, formAction] = useActionState(getCachedRandomValue, null)

  return (
    <form action={formAction}>
      <p>{result}</p>
      <button>Submit</button>
    </form>
  )
}
```

Previously, in this use case, a new value would have been rendered for
every click. This is because React passes the previous state and the
form data as arguments into the action function. These two arguments are
then included in the cache key, resulting in a new cache key being
generated for every invocation.

_Note: This optimization is currently based purely on the function
signature. It does not yet detect when a param is declared, but not used
in the function body. It's also not yet applied for server actions._
2024-11-12 20:29:10 +01:00
Jiwon ChoiandGitHub c469404824 improve no-img-element lint error message (#72410)
### Why?

To customize Image Optimation, the user can use a custom loader, but
that information was out from the related lint error message.

Closes NDX-181
2024-11-12 21:48:12 +09:00
Jude GaoandGitHub d6dd69f210 (e2e) module-level patchFileDelay flag (#72439) 2024-11-12 06:29:03 -05:00
Hendrik LiebauandGitHub 750d7ea633 Bypass source map dev middleware for client chunks (#72581)
A multi-zone Next.js app might have complex rewrites for its client
assets. For these apps, resolving a source map through the
`/__nextjs_source-map` dev middleware might fail because the asset might
belong to a different app.

Instead of trying to resolve those rewrites (i.e. using `fetch` instead
of `fs`), we can just bypass the source map dev middleware for client
chunks. Because we control how those source maps are generated, we can
safely assume that the `sourceMappingURL` is relative to the filename,
with an added `.map` extension. The browser can just request this file,
and it gets served through the normal dev server, without the need to
route this through the source map dev middleware.

reverts #72258
2024-11-12 11:17:57 +01:00
Donny/강동윤andGitHub f8a10c79bf refactor(turbopack): Remove swc_css (#72602)
### What?

Remove `swc_css` from turbopack. It would not break the existing codebase, so it's fine.
2024-11-12 17:36:48 +09:00
0bc4086dff Add expireTag and expirePath APIs (#72485)
This adds `expireTag()` and `expirePath` APIs which are replacing
`revalidateTag` and `revalidatePath`. As such this also marks
`revalidatePath` and `revalidateTag` as deprecated and marked for
removal.

The arguments passed to these methods match `revalidateTag` and
`revalidatePath` with the exception that `expireTag` can receive
multiple tags now as separate arguments which matches our new
`unstable_cacheTag()` API.

We are wanting to update these APIs as `revalidateTag` naming has caused
some confusion as to when the affected items will be updated. The
underlying behavior of `expireTag` is to mark an entry as out of date
and for it to no longer be used so we are expiring it.

If you call `expirePath('/blog/first'`) the next time that item is
requested it is considered expired so the cache will not be used for it
and a fresh entry will be generated. Similarly for `expireTag('posts',
'blog')` the next time any cache with that tag is requested it's
respective cache will not be leveraged and new cache will be populated.

---------

Co-authored-by: Zack Tanner <[email protected]>
Co-authored-by: Delba de Oliveira <[email protected]>
2024-11-11 19:23:39 +00:00
Jiachi LiuandGitHub d3d0f8125e capture console issues as console errors (#72468) 2024-11-11 12:17:08 +01:00
Vercel Release BotandGitHub 18b357854b Upgrade React from 66855b96-20241106 to 5c56b873-20241107 (#72469) 2024-11-11 10:29:01 +00:00
91e347910f fix: added cache control headers for static app routes (#72521)
This pull request includes several changes to improve cache control
handling and add new test cases for verifying cache headers in the
standalone mode of the application.

Improvements to cache control handling:

*
[`packages/next/src/server/base-server.ts`](diffhunk://#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aL3295-R3298):
Updated cache control conditions to check for `undefined` explicitly
before setting cache headers.
[[1]](diffhunk://#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aL3295-R3298)
[[2]](diffhunk://#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aL3318-R3324)
[[3]](diffhunk://#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aR3354-R3365)

New test cases:

*
[`test/production/standalone-mode/required-server-files/required-server-files-app.test.ts`](diffhunk://#diff-0d083b6c7bd3a8a3e9c5ee854123ada3b72db58220d8b65912b047b082f834a2R104-R129):
Added test cases to verify that the correct cache headers are sent for
app routes and app pages.

New static and dynamic route handlers:

*
`test/production/standalone-mode/required-server-files/app/api/test/[slug]/route.js`:
Added a new dynamic route handler with forced static generation.
([test/production/standalone-mode/required-server-files/app/api/test/[slug]/route.jsR1-R7](diffhunk://#diff-1cf8a2cfdbb6473656b2456af0267556270fbbaa7ee2c37e2f3e6c6fed1e4d21R1-R7))
*
`test/production/standalone-mode/required-server-files/app/test/[slug]/page.jsx`:
Added a new static page with a revalidation interval and a function to
generate static parameters.
([test/production/standalone-mode/required-server-files/app/test/[slug]/page.jsxR1-R9](diffhunk://#diff-32038443ca3e4f28db37a6543966397682c64cf6f34e6dd03fd8096414d23022R1-R9))

- Fixes https://github.com/vercel/next.js/issues/65814

Co-authored-by: Janka Uryga <[email protected]>
Co-authored-by: Sam Ko <[email protected]>
2024-11-10 14:22:09 -07:00
Sebastian "Sebbie" SilbermannandGitHub 9666c48883 Ensure logged errors in Edge runtime include the stack (#72394)
Bumps `edge-runtime` (and friends to not duplicate dependencies further) to include https://github.com/vercel/edge-runtime/pull/1023
2024-11-09 14:36:21 +01:00
Sebastian "Sebbie" SilbermannandGitHub 2ce4e440bd Expand server-source-maps scenarios to cover Edge runtime (#72288)
...and use test patterns more consistently
2024-11-09 14:19:08 +01:00
Janka UrygaandGitHub e5ae38355e fix: decrypt bound args before generating a cache key (#72463) 2024-11-08 21:25:09 +01:00
Zack TannerandGitHub 2484e93d6d temporarily skip flaky turbopack build test (#72488)
Need to investigate why this flakes only in Turbopack. Disabling in that
context for now.
2024-11-07 23:42:10 +00:00
a9492ffa12 chore: update typescript document path (#72482)
## Description
At #72178,
[TypeScript](https://nextjs.org/docs/app/api-reference/config/typescript)
docs was moved.
So update the old URLs.

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

---------

Co-authored-by: Zack Tanner <[email protected]>
2024-11-07 14:42:24 -08:00
ccb8848bae test: remove deleted examples (#72374)
# Summary
Update
[`example.test.ts`](https://github.com/vercel/next.js/blob/canary/test/examples/examples.test.ts)
and
[`turbopack-dev-examples-manifest.json`](https://github.com/vercel/next.js/blob/canary/test/turbopack-dev-examples-manifest.json)
by removing deleted examples.

## Descriptions
[examples: cleanup #57845](https://github.com/vercel/next.js/pull/57845)
deleted ...

- amp-first
- amp-story
- data-fetch
- fast-refresh-demo
- hello-world-esm
- progressive-render
- using-router
- with-app-layout
- with-env-from-next-config-js
- with-loading

[updated the example of modularize-imports to utilize the App Router
#69771](https://github.com/vercel/next.js/pull/69771) deleted ...

- modularize-imports

[docs: Add docs on CSP and nonce generation
#54601](https://github.com/vercel/next.js/pull/54601/files) deleted ...

- styled-jsx-with-csp

[Updated the example of with-draft-js to utilize the App Router.
#70045](https://github.com/vercel/next.js/pull/70045) deleted ...

- with-draft-js

[Remove deprecated library example
#62813](https://github.com/vercel/next.js/pull/62813) deleted ...

- with-react-with-styles

[Remove with-reasonml-todo example
#62812](https://github.com/vercel/next.js/pull/62812/files) deleted ...

- with-reasonml-todo

[Remove with-semantic-ui example
#62811](https://github.com/vercel/next.js/pull/62811/files) deleted ...

- with-semantic-ui

[Updated the example of with-vercel-fetch to utilize the App Router.
#70069](https://github.com/vercel/next.js/pull/70069) deleted ...

- with-vercel-fetch

Co-authored-by: JJ Kasper <[email protected]>
2024-11-07 22:21:12 +00:00
Zack TannerandGitHub 4d37f665f6 ensure fetch is patched before preloading entries (#72363)
If a user creates a custom fetch implementation in module scope, the
logic to preload entries during `next start` will result in fetch not
being patched before the userland implementation. As a result, it won't
opt into any caching heuristics from our patched fetch.

Fixes #71881 (in addition to the other PR in this stack)
2024-11-07 13:04:11 -08:00
1c22d142e0 chore: delete api-routes example completely (#72437)
## Description
At #68771,
[`api-routes`](https://github.com/vercel/next.js/tree/canary/examples/api-routes)
example was renamed
[`route-handlers`](https://github.com/vercel/next.js/tree/canary/examples/route-handlers).
However,
[`.gitignore`](https://github.com/vercel/next.js/blob/canary/examples/api-routes/.gitignore)
wasn't deleted and a new
[`.gitignore`](https://github.com/vercel/next.js/blob/canary/examples/route-handlers/.gitignore)
file isn't updated.

In addition, some `api-routes` names exist in the other place.
That's why I update those.

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

Co-authored-by: JJ Kasper <[email protected]>
2024-11-07 20:00:45 +00:00
Sebastian "Sebbie" SilbermannandGitHub 719a187fcd Expand server-side-dev-errors assertions (/pages) (#72265)
Old assertions hid a lot of issues and didn't really tell us what changed.

`TODO(veil)` to make TODOs easier searchable
2024-11-07 16:48:35 +01:00
Wyatt JohnsonandGitHub f668af2061 [ppr] Fixed deployment tests (#72428) 2024-11-07 10:25:50 +01:00
Jiachi LiuandGitHub f6e9bd9cd5 Ignore error pages for cache revalidate (#72412) 2024-11-06 21:48:32 +01:00
Benjamin WoodruffandGitHub 80384ac110 Revert "feat(turbopack): Add an env var to debug-print the fast refresh invalidation reason (#72296)" (#72421)
Not sure why this is happening, but @kdy1 bisected this commit to a null pointer assertion error in napi: https://vercel.slack.com/archives/C03EWR7LGEN/p1730901839682439?thread_ts=1730899709.760659&cid=C03EWR7LGEN

Reverting until I can repro and root cause.

Closes PACK-3402
2024-11-06 11:10:18 -08:00
Vercel Release BotandGitHub 8278fcc6f1 Upgrade React from 7c8e5e7a-20241101 to 66855b96-20241106 (#72415) 2024-11-06 17:12:33 +00:00
Hendrik LiebauandGitHub 926ca23892 Handle empty ESM client modules (#72404)
If an ESM module only includes a `'use client'` directive and no
exports, which is the case for one of the modules that are included in
`@chakra-ui/system` for example, we must not try to add
`registerClientReference` statements for this module. This is a
regression from #71968.

fixes #72358
closes #72359
2024-11-06 17:20:36 +01:00
Zack TannerandGitHub 19f93c895c fetch cache: revalidate should take precedence over force-dynamic (#72357)
`force-dynamic` will automatically disable caching on a fetch. If `force-dynamic` is set, and there's a `revalidate` value on the fetch, the revalidate value will be a no-op unless you explicitly opt into caching via `cache: 'force-cache'`. This changes the behavior to favor a positive revalidate value over `force-dynamic` when deciding to cache the fetch.
2024-11-06 07:24:00 -08:00
Zack TannerandGitHub 3be4ec6592 bugfix: revalidate + force-cache should work (#72347)
When using `fetch('', { cache: 'force-cache', { next: { revalidate: 5 } })` on a page that bailed out of ISR, we were effectively ignoring both values and treating the fetch as uncacheable, for several reasons:

- When `cache` and `revalidate` are both specified, we were assuming any combination of the two values is invalid, and we'd unset both the revalidate & fetch configs. In actuality these two properties are only problematic when they convey different caching semantics. This check was modified to instead only warn & unset on conflicting values, specifically `cache: 'no-store` and `revalidate: >0` as well as `cache: 'force-cache'` and `revalidate: 0`.
- When `force-dynamic` was set, we'd opt into no-store behavior on the fetch even if the fetch had an explicit cache config, which is incorrect.

Fixes #71881
2024-11-06 06:56:45 -08:00
Hendrik LiebauandGitHub f3533cb223 Show readable hook names in stack frames (#72340) 2024-11-06 08:54:05 +01:00
Jiachi LiuandGitHub 2ee93c3483 Append owner stack for captured string console error (#72115) 2024-11-06 01:20:52 +01:00
a5811a771e Bump TypeScript to 5.6.3 (#72311)
### Why?

To unpin the TS version for testing added at #69889.

Closes NDX-287

---------

Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
2024-11-06 09:02:38 +09:00
Jude GaoandGitHub 754417805b (e2e): improve app-hmr test stability (#72345) 2024-11-05 16:44:20 -05:00
Jiachi LiuandGitHub d988180e81 Display the stitched error instead of react error (#72106) 2024-11-05 22:40:01 +01:00
Wyatt JohnsonandGitHub 20123a80f9 [ppr] Stabilize Chained Prerenders (#72343)
<!-- 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 #

-->

As the new chaining mechanism has been live for several weeks now, we're deprecating the old pathname based approach in favor of the new headers based approach. Pages that need to resume now will require the `Next-Resume: 1` header instead of having to call the `/_next/postponed/resume/<route>` route.
2024-11-05 14:34:20 -07:00
Andrew ClarkandGitHub 4f32116466 [Per-Segment Prefetch] Parent segments must be prefetched before children (#72342)
Based on:
- #72341 

---

Creates an access token that the client passes when requesting a
segment. The token is sent to the client as part of the parent layout's
data.

The token is hash of the parent segment path and the parallel route key.
A subtle detail here is that it does *not* include the value of the
segment itself — a shared layout must produce the same access tokens for
its children regardless of their segment values, so that the client only
has to fetch the layout once.

Because this only affects prefetches, this doesn't need to be secure.
It's just for obfuscation. But eventually we will use this technique
when performing dynamic navigations, to support auth checks in a layout
that conditionally renders its slots. At that point we'll need to add a
salt.
2024-11-05 14:51:18 -05:00
Andrew ClarkandGitHub 2e06e008ca [Per-Segment Prefetch] Add Route Tree prefetch (#72341)
In the new design for prefetching, instead of prefetching all the data
for a page in a single request, the client issues a separate request for
each segment. The benefit of using separate requests is that the
responses can be separately cached. For example, when prefetching
multiple pages that share the same layout, the layout data only needs to
be fetched once. Simlarly, when revalidating a tag, only segments that
access that tag need to be refetched.

The client needs to know about the structure of the route tree in order
to determine which segments can be reused. So, before it prefetches any
actual segment data for a page, it will first fetch information about
the route tree. The route tree contains the necessary data for sending
and caching prefetch requests.

This PR updates the server to respond to route tree prefetches. To
prefetch the route tree, the client sets the
`Next-Router-Segment-Prefetch` to `/_tree`.
2024-11-05 19:15:09 +00:00
Benjamin WoodruffandGitHub 8abe1fd55b feat(turbopack): Add an env var to debug-print the fast refresh invalidation reason (#72296)
Setting the environment variable when building (`next dev`)

```
NEXT_TURBOPACK_INCLUDE_UPDATE_REASONS=1
```

causes `[Update Reasons]` messages to be logged to the terminal console (not in the browser) when a file is changed:

![Screenshot 2024-11-04 at 4.31.16 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/HAZVitxRNnZz8QMiPn4a/1af5a4f0-cfba-4ca8-b188-d6be2064b0dc.png)

These messages will not appear if no reason was recorded when the invalidation happened, so this provided on a best-effort basis.

**Why?** The hope is that this can help debug cases where users get stuck in a fast refresh update loop: https://vercel.slack.com/archives/C03S8ED1DKM/p1730737898652749

Closes PACK-3374
2024-11-05 10:49:41 -08:00
Will Binns-SmithandGitHub 47467160cd Turbopack: use file:// uris for server resources in development (#71984)
Follows up from #71489, extending this to sourcemaps for server bundles.

Test Plan:

- [x] CI
- [x]
https://github.com/vercel/next.js/blob/61dbe6fb00885068e7ae89ed397e2112076a4577/test/development/app-dir/source-mapping/README.md


Closes PACK-3348
2024-11-05 09:31:20 -08:00
Zack TannerandGitHub 3a1e37d788 app build: don't merge dynamic params with query params (#72294)
At build time we merge dynamic params (e.g. `[lang]`) with search params
into the same object used as part of the pages/app renders. This is
semantically incorrect and has led to some unexpected downstream
behavior (such as dynamic params showing up as cache keys in flight data
for app router). Pages router seems to rely on this behavior (for ex,
`useRouter().query` combines both dynamic params with search params).

This avoids mutating `query` and instead combines them specifically in
the pages export case. This also fixes an inconsistency in where we're
reading params in pages render, specifically `getStaticProps` now reads
params from `params` rather than `query` to align with
`getServerSideProps` and not rely on the fact that we happen to merge
them.
2024-11-05 08:54:06 -08:00
Wyatt JohnsonandGitHub 2dee8d99e1 [ppr] Move Resume Data Cache into Postponed State (#72284)
In order to take advantage of the existing plumbing of the postponed state, we're injecting the resume data cache into the postponed state itself, as the data is always co-located. This ensures that stale resumes can utilize the data out of the box without any additional infrastructure configuration.
2024-11-05 09:42:17 -07:00
Sam KoandGitHub daba014016 fix(webpack): update cssnano-preset-default to v7 (#68748)
## Why?

Our default CSS minifier had a bug → https://github.com/cssnano/cssnano/issues/1655, which was also reported (below).

Since it is now fixed upstream, we need to update our cssnano in Next.js.

- Fixes https://github.com/vercel/next.js/issues/68476

## How?

- Update `cssnano-preset-default` to v6
- Add unit test to cover the case for being able to declare layer names

(the added unit test errors in an way that's unreadable on canary)
![CleanShot 2024-11-04 at 22 32 32@2x](https://github.com/user-attachments/assets/ef3a302a-2aec-4b63-9db2-40869daaf5ad)
2024-11-04 22:36:39 -08:00
Wyatt JohnsonandGitHub 2f43ba59e5 [ppr] Resume Data Cache (#72161)
This adds a new ResumeDataCache concept to Next.js. This cache is persisted during production, and used for pre-seeding during development. Every route will generate its own resume data cache that will be used when partial prerendering is enabled. This lets us fill the caches during the prerender, and re-use those cache entries every time the page is resumed. This allows a future where we can reuse stale static shells while also reusing the resume data cache.
2024-11-04 17:59:48 -07:00
Zack TannerandGitHub 1734e91ac8 fix loading bailout condition & server patch mismatch tolerance (#72227)
Pre-PPR on client navigations, we are currently determining whether or
not to render the underlying React components based on the presence (or
lack thereof) of `loading.js`. We'll render components up to the first
segment containing `loading.js`, and then stop at that level.

Similarly, if there's no `loading.js` in the tree at all, we'll return a
mostly empty prefetch. The underlying reason for this is that we cannot
assume a particular tree/subtree doesn't contain expensive invocations:
`loading.js` is a signal we use to detect where some sort of dynamic
call will happen. This heuristic is largely improved with PPR + DIO but
we still need to support this case.

Currently there's a bug that will lead to overfetching. When determining
if we should skip the component tree, we check the presence of loading
at that level, as well as the entire tree. This means that during
partial navigations when the server starts rendering deeper within the
tree rather than starting from the root, the presence of `loading.js` in
an earlier segment would incorrectly tell the router it should render
the page.

This updates the handling to check for a loading segment only within the
partial tree that's being diffed. That way when we recursively call
this, it won't look at earlier segments when deciding if there's a
loading segment deeper in the tree.

This PR also adjusts the server-patch reducer to be more resilient to
mismatching trees. Previously we triggered a hard navigation but this
actually can become a fairly common case if the RSC response doesn't
return initial bytes quickly enough, such as in `dynamicIO` when we're
warming the dev caches prior to a navigation. Instead we'll return the
state in-place and effectively discard the patch because the assumption
is the tree was patched elsewhere.
2024-11-04 15:09:47 -08:00
Jude GaoandGitHub bc5443dd3e patchFile awaits compilation (#72267)
We will wait the server to respond with a compile success message after
a file is patched before proceeding to the next steps in the test to
reduce flakiness.

By doing so, we uncovered a few tests that were passing accidentally due
to flakiness of `patchFile`, and fixed them in the PR.
2024-11-04 17:33:06 -05:00
Andrew ClarkandGitHub 3287d70959 Generate per-segment prefetch responses (#72168)
Follow up to #71113.

This generates a prefetch response for route segments, so the client can
request them individually, and reuse shared layouts between separate
page prefetches.

Since this is exclusive to PPR, segment prefetches are always static and
do not reach the application layer. They are served directly from cache.
(This part was implemented in the previous PR.)

The prerendered segment data is generated (and revalidated)
simultaneously with the prerender of the entire page, to ensure
consistency between parent and child segments. Since we always rebuild
the whole page, we can save an extra render of each segment by reusing
the Flight response that was used to generate the initial HTML.

We do this by decoding the page data using a server-side Flight
consumer, picking out an individual segment's data, then re-encoding it
as its own Flight response. We have to do this once per segment — not
ideal, but for now it's the only way to make sure the side effects from
the original Flight stream (e.g. Float preloads) are transferred to the
per-segment streams.

This PR does not yet include any updates to the client router.
2024-11-04 15:15:46 -05:00
Jiachi LiuandGitHub e9a90d954c test: fix snapshots in next build and lint test (#72283) 2024-11-04 20:52:25 +01:00
f771c6d787 fix(cli): respect SIGTERM and SIGINT exit codes in next build (#64871)
This PR updates the SIGTERM and SIGINT exit codes to 143 and 130
respectively. These updated codes are what other tooling, such as
Nx/Turborepo, expects when running commands that did not completely
successfully due to receiving SIGTERM and SIGINT.

For Nx, the SIGINT (e.g. `Ctrl+C`) causes a bad build cache. Both Nx and
Turborepo will have bad cache when SIGTERM is received, which can happen
in a CI environment if a job times out, runs out of memory, etc.

I have a [repo here](https://github.com/jaysoo/next-cli-signals) that
demonstrates the wrong behavior with Turborepo. By exiting with the
wrong code, it can result in bad cache in CI or Docker.

Closes: https://github.com/vercel/next.js/issues/62906

---------

Co-authored-by: Sam Ko <[email protected]>
Co-authored-by: Zack Tanner <[email protected]>
2024-11-04 09:44:33 -08:00