Commit Graph

516 Commits

Author SHA1 Message Date
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
Sebastian "Sebbie" Silbermann 8ea2830b6b Rename waitForAndOpenRuntimeError to openRedbox (#72996) 2024-11-21 18:02:26 +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
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
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
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
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
Jiachi Liu d988180e81 Display the stitched error instead of react error (#72106) 2024-11-05 22:40:01 +01: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
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
Jiachi Liu 1fb83619d8 Compare error stack to dedupe error (#71798) 2024-10-29 15:24:55 +01:00
Jiachi Liu 14b92e6e13 fix: log the error instance modified extra location info (#71930) 2024-10-29 15:24:41 +01:00
Josh Story 29a573dd77 [dynamicIO] update prerender cache scoping and cache warming for validation (#71822)
Updates the heuristic to scoping prerender caches during dev. A cache
scope will be created for every request if one does not already exist.
If the request is a server action we create a new one. existing caches
already expire after 30 seconds (unchanged)

This updates the prefetch cache purge to be 5 seconds since so we don't
mask short lifetime caches

This also adds cache tracking to the first RSC render of the validation
render. This means we now need to always do a second render regardless
of whether there is a sync abort.
2024-10-24 13:56:23 -07:00
Zack Tanner aeb40b7b47 ensure DIO development segment errors are cleared after correcting (#71811)
This clears segment config errors that are corrected in development mode
when using `dynamicIO`.
2024-10-24 10:51:09 -07:00
Jiachi Liu 899c416ad4 test: re-enable test with note (#71789) 2024-10-24 13:53:24 +02:00
Josh Story 17f4291318 [dynamicIO] refine error message and docs (#71781)
refines the error message for non-prerenderable holes while prerendering
as well as the docs
2024-10-24 00:31:29 -07:00
Jiachi Liu ab1d9eebfa fix: handle server component replay error in error overlay (#71772)
### What

When there's a replay console error showed up, display it in error
overlay.

#### Server Component Page
<img width="480" alt="image"
src="https://github.com/user-attachments/assets/7af65809-1e0e-4aa0-bffb-bc95a376fb02">

#### Server Component Page with Client Components
<img width="480" alt="image"
src="https://github.com/user-attachments/assets/1f8bd507-3e0f-43f3-9240-07c4aec16ab4">

---------

Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
2024-10-24 00:53:58 -04:00
Jiachi Liu dbc94523d5 Enable owner stack in experimental build (#71716) 2024-10-24 02:00:42 +02:00
Jiachi Liu 064970e083 feat: stitch errors with react owner stack (#70393) 2024-10-23 19:28:03 +02:00
Zack Tanner bbad635af2 warn on sync access if dynamicIO is not enabled (#71696)
Since `console.error` is intercepted, this can be frustrating when a 3p
library that hasn't updated to use the async APIs triggers a warning.

This keeps the error behavior when `dynamicIO` is enabled and warns in
other cases.
2024-10-23 07:56:23 -07:00
Jiachi Liu aed6c4c0a0 Fix: revert the bad node binary handling (#71723) 2024-10-23 16:41:15 +02:00
Zack Tanner 3a9a50c2f1 [dynamicIO]: dev navigations should show disallowed dynamic errors (#71595)
This applies similar handling from #71567 to show dynamic IO errors
during client navigations. This also adds a redbox test case for the
initial SSR render.
2024-10-21 23:37:25 -07:00
Josh Story 19e2edcf4a Reland "[dynamicIO] warn for disallowed dynamic in dev" (#71567)
Reverts vercel/next.js#71566 which relands #71526 

merge after 15 is released
2024-10-21 12:33:50 -07:00
Zack Tanner c85914c1f6 Revert "[dynamicIO] warn for disallowed dynamic in dev" (#71566)
We're going to land this after 15.

Reverts vercel/next.js#71526
2024-10-21 10:50:39 -07:00
Jiachi Liu 24da437c9d feat: dedupe consecutive captured console errors (#71483) 2024-10-21 13:05:43 +02:00
Josh Story b18c027ac6 [dynamicIO] warn for disallowed dynamic in dev (#71526)
Previously our rules for allowed dynamic were only enforced in builds.
This is not tenable for serious adoption because you can't spend all day
working on your site and then find out its broken when you build /
deploy.

To address this I've added a simulated prerendering during dev that
should enforce the same rules for rendered routes in dev that would
apply during a build. There is no way to avoid doing additional work to
implement this feature because we need the abort mechanism of SSR to
actually find the dynamic holes that should be disallowed. I was able to
avoid completely duplicating the RSC render however by capturing the
stream chunks available before the first task completes and stashing
them away as a simulated halted RSC payload.

I did have to introduce prospective renders to the RSC render and the
validating SSR render however to work around issues of lazy module
initialization where functions like Math.random and new Date() in module
scope would incorrectly trigger dynamic validation when you would not
expect them to.
2024-10-20 17:41:48 -07:00
Josh Story dab4d00ea1 sync access warnings for Request APIs should include a stack (#71519)
This updates our logging to use Error objects to provide stacks to
better locate where sync access of Request APIs is happening
2024-10-19 16:11:33 -07:00
Hendrik Liebau c54b8a3a36 Assign proper function names to server actions (#71478)
This PR adjusts the server action transforms to assign proper function names for the generated server reference proxies.

- If the original function has a name, this name is used.
- If a function expression is assigned to a variable, the variable's name is used.
- If an anonymous function expression is assigned to a prop, the prop's name is used.

In addition, this PR simplifies the output for exported functions, avoiding unnecessary `registerServerReference` calls.

It also fixes the source mapping of default exported server actions.

**Before:**

<img width="890" alt="before" src="https://github.com/user-attachments/assets/a3d6a5f8-d48e-474d-8f03-b49306fb704f">

**After:**

<img width="890" alt="after" src="https://github.com/user-attachments/assets/8f332690-6c26-46f1-9eef-7680f47ea578">

Next up, we will do the same for `'use cache'` functions.
2024-10-19 00:53:21 +02:00
Josh Story 1f462140b9 [dynamicIO] refine error messaging for sync API access (#71467)
Temporarily removing the dev warnings. I've moved these to be errors in
the build side. In a follow up PR I will use prerendering during dev to
trigger these errors and report them as dev errors as well.

This also updates how we track sync dynamic errors. The main goal is to
have a stack trace of the sync function and separately report all the
component stacks that might contain this function call. It's not
fool-proof b/c the sync api may be called in a way that is not observed
by SSR. The whole debugging story here will improve dramatically with
owner stacks but that is currently experimental only in React.

The plan for future updates is to add a prospective render for SSR so we
can flush out module scope issues like calling Math.random while lazy
initializing a module. This is asserted for RSC in this change (see new
tests) but won't wouldn't pass for SSR b/c we only do single pass
prerendering at the moment.

After that I will add in the prerender-while-render in dev and utilize
the prerender errors to power dev as well.
2024-10-18 15:08:50 -07:00
Jiachi Liu 22eff62579 capture console.error into error overlay (#71424) 2024-10-17 23:47:00 +02:00
Josh Story 9578101692 [dynamicIO] Do not warn on arbitrary param access in browser (#71437)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-10-17 23:12:21 +02:00
Vercel Release Bot cad01db9d2 Upgrade React from cd22717c-20241013 to 77b637d6-20241016 (#71391)
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-10-17 09:48:02 +00:00
Josh Story f93d8178ea [dynamicIO] Error in dev when using sync platform APIs that are dynamic (#71346)
stacked on #71345 

When dynamicIO is enabled certain platform APIs that provide access to
outside state like randomness and current time are augmented to bail out
of prerendering. When running in Dev there is no true Prerender but we
still want to communicate to the developer when they are using APIs that
might not work as they intend in Production. This change adds warnings
when you use these platform APIs during the Prerender portion of the dev
render.
2024-10-16 15:18:49 -07:00
Josh Story 5973081559 [dynamicIO] Implement a warmup prefetch render in dev (#71278)
To seed caches in dev mode we implemented a prefetch if one had not been
done in the recent past. The implementation isn't quite working b/c it
doesn't match the prefetch header properly but the mechanics are there.
One problem however is the prefetch streams so we end up starting the
regular render before the prefetch render is complete.

The ideal cache warmup is to only render until there are no more caches
to fill in the prefetch. Additionally we can disable certain things like
dynamic Request apis and fetches so they stall forever too. This
suggests that there is enough of a difference in the needs of the
prefetch for cache warming that we ought to implement it as it's own
request type. This change implements the mechanics of triggering the
warmup prefetch but does not yet implement the changes to things like
the request or fetch apis behavior. I will follow up with further
changes on top of this commit.
2024-10-15 21:55:51 -07:00
Zack Tanner 3cde42ff72 static indicator shouldn't show for force-dynamic (#71284)
The static indicator shouldn't show for pages that are opted into
dynamic rendering via `export const dynamic = 'force-dynamic'`.
2024-10-14 21:30:11 -07:00
Janka Uryga 701b11c3c4 [after] after is not dynamic anymore (#71231)
# Changes

### 1. `unstable_after()` is no longer dynamic

`after()` can now run at build time and in ISR/revalidations.

the principle is "if it ran, then the callback runs too". i.e. if we
encountered an `after()` call during some render task (build / request /
revalidation), then the callback should run at the end of that task.

note that errors thrown inside `after` during a prerender will fail the
build. this is, amongst other things, intended to support the next
section

### 2. calling dynamic APIs inside `unstable_after()` is banned

before:
```ts
after(() => {
  const cookieStore = await cookies();
  doStuff(cookieStore)
})
```

after:
```ts
const cookieStore = await cookies();
after(() => {
  doStuff(cookieStore)
})
```

tracking dynamic things inside `after` is difficult (can't throw at the
callsite, because we're executing after the callsite is finished, so it
doesn't mesh well with `dynamicIO`). it's simpler if we make the user
hoist the dynamic call outside of `after()`, because then it slots right
into the existing mechanisms/docs/metal models we have for this.

# Notes

one notable limitation is that `tags` and `revalidate` written inside
`after` have no effect. this means that if we do
```ts
after(async () => {
  await fetch('...', { next: { tags: ['my-cool-tag']} })
})
```
and try to call `revalidateTag('my-cool-tag')`, nothing will happen,
because the route is not associated with the tag. same applies to
`revalidate`.

i believe this is acceptable for now, because we expect `after` to be
mostly used to perform side effects, and thus not do a lot of
{cached,tagged,revalidatable} data-fetching. it will be addressed in a
follow up.
2024-10-14 12:56:56 +00:00
Hendrik Liebau 604b87cc28 Increase retry duration for HMR fetch logging tests (#71170)
As we've learned in #70467, compilation times can be quite high in CI,
when testing HMR behaviour. The fetch logging HMR tests are frequently
failing. Increasing the `retry` timeout should mitigate the flakiness.
2024-10-12 02:27:01 +02:00
Hendrik Liebau 5c194b2b47 Increase retry duration from 3 to 5 seconds in RSC HMR cache tests (#70467)
The compilation for HMR changes often takes around 3 seconds in CI, so
we need to increase the duration for the `retry` calls to avoid
flakiness.

[This test
run](https://github.com/vercel/next.js/actions/runs/11036231635/job/30654233890)
shows that it sometimes barely finishes the compilation before the
timeout:

<img width="467" alt="Screenshot 2024-10-11 at 19 14 41"
src="https://github.com/user-attachments/assets/faae5593-3b03-4085-b3e6-54eff5c514bc">

... and sometimes it doesn't:

<img width="591" alt="Screenshot 2024-10-11 at 19 22 48"
src="https://github.com/user-attachments/assets/4441b700-6c79-42dc-bdb6-abf29d7ceeec">
2024-10-11 20:22:33 +02:00