Commit Graph

1310 Commits

Author SHA1 Message Date
Janka Uryga 82e84e430b feat(after): stabilize unstable_after (#73605)
- rename `unstable_after` -> `after`
- remove `experimental.after` flag (and warn if it's present)

i separated the big find-and-replace into a separate commit so that it's
easier to see what else changed apart from that.

does not touch docs, that's in #73038
2024-12-06 19:59:57 +00:00
Jiwon Choi 3fbb2a6dd6 test: replace check to retry in hmr.test.ts (#73590)
> [!NOTE]
> The "Test new tests for flakes" may fail due to the number of tests in
a single `hmr.test.ts` file.
> The follow-up stacks are to resolve the issue.

### Why?

The test util `check` is deprecated internally, recommended to replace
to `retry`.
2024-12-07 04:29:46 +09:00
Tobias Koppers 43c13f4e28 [Turbopack] add telemetry for persistent caching usage (#73554)
### What?

Report persistent caching as feature
2024-12-06 14:50:52 +01:00
Sebastian "Sebbie" Silbermann 98de5db6d4 Use consistent error formatting in terminal (#71909) 2024-12-06 14:43:59 +01:00
Sebastian "Sebbie" Silbermann 81f6cb4b80 Ensure Issue Overlay sourcemaps externals in Turbopack (#73439)
Closes https://linear.app/vercel/issue/NDX-473/
2024-12-04 10:11:19 +01:00
Sebastian "Sebbie" Silbermann a37ac2040e Bump @swc/core to 1.9.3 (#73420)
Gets the fix for https://github.com/swc-project/swc/issues/9742
2024-12-03 10:08:56 +01:00
Janka Uryga f5e35b87b9 fix(after): allow reading draftMode status in after (#73324)
`after` was too restrictive with `draftMode` -- we generally allow reading `draftMode().isEnabled` anywhere. this is because it isn't really a dynamic API -- it's fine to call it in prerender/'use cache' contexts, because we can just prerender/cache it as `isEnabled = false`, and when it's on, it switches everything to dynamic rendering anyway, so that prerender/cache entry is ignored.

However we disallow `draftMode().enable()/disable()` in `after`, because those methods set a cookie, and `after` executes too late for that.

*(Nothing here will change in the upcoming `after` behavior update -- we fundamentally can't get more permissive than this)*
2024-11-29 11:31:53 +01:00
Jiachi Liu 64f2702413 test: fix canary test with 18.3.1 (#73327) 2024-11-28 19:47:26 +01:00
Jiachi Liu f5b88d917a handle pages router ignored frames (#73280) 2024-11-28 11:58:18 +00:00
Jiachi Liu be19d30b4d Replace the group frames with button for ignored frames (#72964) 2024-11-28 12:27:45 +01:00
JJ Kasper a771ce2ff2 Undeprecate revalidate APIs and rename expire APIs (#73193)
As discussed we are removing the deprecated field from `revalidateTag`
and `revalidatePath` as they aren't going away anytime soon and the new
`expire` APIs will have slightly different semantics so not a 1-1 rename
with no arguments change anymore. We are also adding the `unstable_`
prefix for `expireTag`/`expirePath` while we iterate on them so it's
clear they will change.

---------

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2024-11-27 09:01:04 -08:00
Jiachi Liu 664d888f9e Error on navigation API usage in pages router and middleware (#73100) 2024-11-27 17:00:00 +01:00
Jude Gao e4646d6354 Revert change to ReactRefreshRequire test (#73186)
See https://github.com/vercel/next.js/pull/73105#discussion_r1857278637
2024-11-25 16:05:00 -05:00
Jude Gao bfcbac94f2 (E2E) Log which config file is used for next start (#73105)
# Context

[Test
run](https://github.com/vercel/next.js/actions/runs/11962411287/job/33382985253?pr=73030#step:29:421)
fails due to

```
   ▲ Next.js 15.0.4-canary.22
   - Local:        http://[::1]:35903
   - Network:      http://[::]:35903

 ✓ Starting...
Error: "next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.
    at <unknown> (dist/server/next.js:215:31)
    at async NextServer.prepare (dist/server/next.js:154:24)
    at async initializeImpl (dist/server/lib/render-server.js:92:5)
    at async initialize (dist/server/lib/router-server.js:436:22)
    at async Server.<anonymous> (dist/server/lib/start-server.js:272:36)
```

However, there was no `output: export` specified in the [test
setup](https://github.com/vercel/next.js/tree/jude/which-config-are-we-using/test/integration/edge-runtime-configurable-guards).
**Mysterious!**

# Hypothesis

`next start` recursively finds the `next.config` upwards in the
directory tree and happens to locate an extraneous `next.config` that
specified `output: export`.

# Changes

- Output the config file path in test mode for future debugging
- Short-circuit `findUp` for the broken test by placing an empty config
in the project directory
2024-11-22 14:46:43 -05:00
Jude Gao 9ab8434df7 hmr-test waits for compile signal (#73064)
- The waitFor function now supports a predicate. Unlike retry, waitFor
does not include a timeout. Use it only when the predicate is guaranteed
to evaluate to true before proceeding to the next test. If it runs
indefinitely, Jest enforces a 120-second timeout per test.
- The getCliOutputFromHere utility provides a convenient string getter
that captures CLI output in between.
2024-11-21 15:29:24 -05:00
Jiachi Liu 37f26ac289 Add forbidden and unauthorized APIs (#72785) 2024-11-21 20:59:19 +01:00
Sebastian "Sebbie" Silbermann 8ea2830b6b Rename waitForAndOpenRuntimeError to openRedbox (#72996) 2024-11-21 18:02:26 +01:00
Sebastian "Sebbie" Silbermann 2113aacabd Remove hardcoded timeouts in Redbox test helpers (#73000) 2024-11-21 14:43:23 +01:00
Jiwon Choi 73f547a6de Display where the env was loaded from when enabled typedEnv (#70951)
### Why?

This PR added an indication of where the env was loaded from when
`experimental.typedEnv` was enabled. Also, it allows the user to set
`NODE_ENV=production` to enable the `typedEnv` feature for
`.env.production*` files.

![CleanShot 2024-11-21 at 19 48
20](https://github.com/user-attachments/assets/ce3c7180-f26a-4378-a74f-a5998a363211)

### How?

Modified `@next/env` to pass parsed envs along with the `loadedEnvFiles`
value and used the location to indicate via JSDoc.
2024-11-21 11:47:08 +00:00
Andrew Clark 39cd2f6e99 Allow CacheNode.loading to be a promise (#72872)
In the Segment Cache implementation of prefetching, during a navigation,
it's possible that the prefetch for a segment may already be
in-progress, but we haven't received its data yet. In that case, since
the prefetch is very likely to load faster than the dynamic request, we
might as well use the result, if we can.

This updates type CacheNode.loading to accept a promise for the loading
module data, and updates the LayoutRouter to conditionally unwrap it if
needed. We already use this same strategy in other places, like for
streaming in the main segment data.
2024-11-20 12:35:30 -05:00
Sebastian "Sebbie" Silbermann b5666ce3ed Add support for ignore-listing sources in index maps (#72913)
We now look through each section for the source and
use that section to determine if a frame is ignore-listed.
    
Previously, stacks from Turbopack sourcemaps were
not ignore-listed since they were index maps.
2024-11-20 11:23:43 +01:00
Sebastian "Sebbie" Silbermann 8a53d56d64 Fix sourcemaps for internal client boundaries (#72922) 2024-11-19 10:15:59 +01:00
Sebastian "Sebbie" Silbermann 6427135453 Fix sourcemaps for async Turbopack chunks (#72827)
Works around https://github.com/nodejs/node/issues/52102

Webpack will be harder to patch and I don't know yet where the Webpack runtime is using `vm.runInThisContext`.

Best way to observe change is in https://github.com/vercel/next.js/pull/71909 and `pnpm test-dev-turbo test/development/app-dir/dynamic-io-dev-errors/ -t "should display error when component accessed data without suspense boundary"`.
Before:
```
Error: [...]
    at Page [Server] (<anonymous>)
    at InnerLayoutRouter (.next/server/chunks/ssr/[root of the server]__088b8c._.js)
```

After:
```
Error: [...]
    at Page [Server] (<anonymous>)
    at InnerLayoutRouter (node_modules/.pnpm/file+..+next-repo-2186278d37ae48e2b1397aa86060054592669ed9909b91e96c5af049d12c04c3+packages+n_vk62popbath6ofshgazcbhzdoe/node_modules/next/dist/src/client/components/layout-router.tsx:324:2)
```

Next step is figuring out why the now sourcemapped frames aren't ignore-listed.
2024-11-18 13:51:54 +01:00
Jude Gao 2e97a73de6 use explicit resource management for sandbox (#72780)
Migrated every instance of `sandbox` to use the `using` keyword so that
the `cleanup` will be automatically performed when the execution leaves
the scope.
2024-11-14 06:53:25 -05:00
Jiachi Liu 6b3bdd8e76 refactor: rename error boundary not-found to http-error-fallback (#72586) 2024-11-13 19:38:15 +01:00
Jiachi Liu d5e2701024 test: add wait for the error page navigation (#72760) 2024-11-13 17:46:04 +01:00
Jude Gao 6ade55999f upgrade amphtml-validator to 1.0.38 (#72645)
Tests have been inconsistent due to flaky build-time failures caused by
AMP validation errors:
https://github.com/vercel/next.js/actions/runs/11807856104/attempts/1.

We’re updating the library version with the expectation that this will
resolve the issue.

```
info: undefined
   Generating static pages (9/37) 
   Generating static pages (18/37) 
   Generating static pages (27/37) 
Error occurred prerendering page "/amp-hybrid". Read more: https://nextjs.org/docs/messages/prerender-error
AssertionError: Assertion failed: WebAssembly is uninitialized
    at new module$contents$goog$asserts_AssertionError (evalmachine.<anonymous>:102:1441)
    at module$contents$goog$asserts_doAssertFailure (evalmachine.<anonymous>:103:354)
    at goog.asserts.assertExists (evalmachine.<anonymous>:104:374)
    at Object.module$contents$amp$validator_validateString [as validateString] (evalmachine.<anonymous>:2238:108)
    at Validator.validateString (/tmp/next-install-89c7ccfd9a04886e2e88ccffb9ad709b236d4b8c8398fcdbb34c9c897118b9e9/node_modules/.pnpm/next@file+..+next-repo-99a8e0af0510a7a2958e71c9affe3d5d83d452a304c40ea8b352506d74651d57+packa_6sb2ai4rhstsynpbl53dxgpt7e/node_modules/next/dist/compiled/amphtml-validator/index.js:17:2057)
    at validateAmp (/tmp/next-install-89c7ccfd9a04886e2e88ccffb9ad709b236d4b8c8398fcdbb34c9c897118b9e9/node_modules/.pnpm/next@file+..+next-repo-99a8e0af0510a7a2958e71c9affe3d5d83d452a304c40ea8b352506d74651d57+packa_6sb2ai4rhstsynpbl53dxgpt7e/node_modules/next/dist/export/routes/pages.js:100:34)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async exportPagesPage (/tmp/next-install-89c7ccfd9a04886e2e88ccffb9ad709b236d4b8c8398fcdbb34c9c897118b9e9/node_modules/.pnpm/next@file+..+next-repo-99a8e0af0510a7a2958e71c9affe3d5d83d452a304c40ea8b352506d74651d57+packa_6sb2ai4rhstsynpbl53dxgpt7e/node_modules/next/dist/export/routes/pages.js:134:17)
    at async Span.traceAsyncFn (/tmp/next-install-89c7ccfd9a04886e2e88ccffb9ad709b236d4b8c8398fcdbb34c9c897118b9e9/node_modules/.pnpm/next@file+..+next-repo-99a8e0af0510a7a2958e71c9affe3d5d83d452a304c40ea8b352506d74651d57+packa_6sb2ai4rhstsynpbl53dxgpt7e/node_modules/next/dist/trace/trace.js:153:20)
    at async exportPage (/tmp/next-install-89c7ccfd9a04886e2e88ccffb9ad709b236d4b8c8398fcdbb34c9c897118b9e9/node_modules/.pnpm/next@file+..+next-repo-99a8e0af0510a7a2958e71c9affe3d5d83d452a304c40ea8b352506d74651d57+packa_6sb2ai4rhstsynpbl53dxgpt7e/node_modules/next/dist/export/worker.js:336:18)

```

Note that this failure breaks the production integration test almost 10%
of times.

![CleanShot 2024-11-12 at 23 15
11@2x](https://github.com/user-attachments/assets/89ad041c-22b1-47ad-aa56-58ea3a269811)
2024-11-13 11:21:11 -05:00
Jiachi Liu b96772a649 refactor: remove unused asNotFound property (#72585) 2024-11-13 12:15:10 +01:00
Jude Gao 171970d1c6 Re-enable fetch logging test - HMR (#72640) 2024-11-12 19:51:38 -05:00
Jam Balaya 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 <sam@vercel.com>
2024-11-12 16:07:47 -08:00
Jiwon Choi 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 Gao d6dd69f210 (e2e) module-level patchFileDelay flag (#72439) 2024-11-12 06:29:03 -05:00
Hendrik Liebau 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/강동윤 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
JJ Kasper 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 <1939140+ztanner@users.noreply.github.com>
Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
2024-11-11 19:23:39 +00:00
Jiachi Liu d3d0f8125e capture console issues as console errors (#72468) 2024-11-11 12:17:08 +01:00
Sebastian "Sebbie" Silbermann 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
Jam Balaya 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 <1939140+ztanner@users.noreply.github.com>
2024-11-07 14:42:24 -08:00
Benjamin Woodruff 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
Hendrik Liebau f3533cb223 Show readable hook names in stack frames (#72340) 2024-11-06 08:54:05 +01:00
Jiachi Liu 2ee93c3483 Append owner stack for captured string console error (#72115) 2024-11-06 01:20:52 +01:00
Jude Gao 754417805b (e2e): improve app-hmr test stability (#72345) 2024-11-05 16:44:20 -05:00
Jiachi Liu d988180e81 Display the stitched error instead of react error (#72106) 2024-11-05 22:40:01 +01:00
Benjamin Woodruff 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
Jude Gao 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
Hendrik Liebau 927749c6b2 Strip assetPrefix when resolving external source maps of client chunks (#72258)
When using Turbopack, and importing a server action into a client
component, the source map for the client chunk will be requested if
devtools are open. The filename for this source map request might be
`/_next/static/chunks/[project]__800ed2._.js`, for example. This
scenario was already handled by the dev middleware.

However, it didn't consider that there might also be an `assetPrefix`
defined in the `next.config.js`. In this case, the filename would be
`/some-asset-prefix/_next/static/chunks/[project]__800ed2._.js`. When
resolving the external source map for this file, we need to strip the
asset prefix.

Again, this can only be tested manually.
2024-11-04 12:33:06 +01:00
Sebastian "Sebbie" Silbermann 5de1a68152 Clickable stack trace links in logged terminal errors (#71940)
Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2024-11-01 15:12:33 +00:00
Jude Gao 190b3dadbc Reduce turbo hmr e2e flakiness (#72114)
Running the tests continuously for an hour on my PC, the tests succeeded
with no failure.

```
while pnpm test-dev-turbo test/development/app-hmr/hmr.test.ts; do :; done
```

Will monitor the flakiness after this lands. Hope it reduces it below
20%.
2024-10-31 15:59:30 -04:00
Jiachi Liu a94cf1c977 fix: handle logging cicurlar object (#72078) 2024-10-30 21:52:56 +01:00
Zack Tanner e1e25e16ae use server component transform for segment validation (#72051)
After adding validation that fixing invalid segment configs (when DIO is
enabled), it revealed that errors weren't being displayed in Turbopack,
because `setHMRServerError` wasn't implemented.

This refactors the implementation to use the existing server component
transform when validating if the segments are valid. This has the
benefit of highlighting precisely where the segment is coming, making it
easier to remove. The test that was skipped in Turbopack is also
re-enabled.

<details>
<summary>Screenshot</summary>

![CleanShot 2024-10-29 at 17 03
46@2x](https://github.com/user-attachments/assets/a68c060a-6ae7-4c6c-8243-6c48c2703f66)



</details>
2024-10-30 11:30:37 -07:00