First part adding additional types for the various events that are sent through the websocket to the browser.
Will add additional details / comments on the types after landing these changes in the browser-side code too.
> Layouts do not have access to the current route segment(s). To access route segments, you can use useSelectedLayoutSegment or useSelectedLayoutSegments in a Client Component.
The term "current" is confusing.
It should be only the route segments under the layout. For example: `app/layout.tsx` can not access `app/[slug]`.
Missing word in client component page in docs when discussing the effect of "use client" on a client component's children and imported components. Not sure if 'children' is the appropriate word or whether there should be a reference to imported components too.
Update the code snippet for configuring API Routes to include `maxDuration` as an option.
Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
### What?
Follow-up of #54824
### Why?
Correctly detect the section to look for while autolabeling. The text currently being searched is not present in the issue body, just the template. Example: #54911 where "App Router" is present but was not detected.
This:
- Profiles dev server startup by wrapping most logic in a debug tracing Span
- Sets tracing globals for this case earlier, as they would otherwise be unavailable
- Allows Turbopack traces to be uploaded, as while currently incomplete, they are accurate
Closes WEB-1440
Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
Simplified some logic around `getPagePaths` as well as another normalization function. This instead utilized some flat arrays using push instead of relying on a separate `flatten` method (allowing us to remove it). This also reduced the number of logic checks for this generation.
There's been some confusion on the correct way to add a `nonce`, so took the opportunity here to:
- Add a new docs page for Content Security Policy
- Explained how to generate a `nonce` with Middleware
- Showed how to consume the `nonce` in a route with `headers`
- Updated the `with-strict-csp` example
- Update the `nonce` error message page
- Backlinked to the new page in a few places in the docs
Depends on https://github.com/vercel/turbo/pull/5852
This removes references to the `source_maps` module from Turbopack as it no longer exists in https://github.com/vercel/turbo/pull/5852
Test Plan:
- Opened a Next.js app with `--turbo-experimental`
- Change a file, verify the page is updated with HMR
- Confirm the source map for the updated file is correctly loaded in DevTools
Closes WEB-1483
Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
This updates the check to see if a request is made in middleware to be a bit less brittle so it doesn't break if middleware is located in `/src/middleware` (`params.page` would be `/src/middleware` rather than `/middleware` in that case)
fixes https://github.com/vercel/next.js/discussions/54853
It seems the app router attempts to write its cache to both `.next/cache` and `.next/server` in docker.
This fix should fix standalone output server's error `Failed to update prerender cache... [Error: EACCES: permission denied...` when deployed in a docker container with the example Dockerfile.
Related discussion: https://github.com/vercel/next.js/discussions/51164
It's a bad pattern to do things like `(renderOpts as any).fetchMetrics = staticGenerationStore.fetchMetrics` and receive the updated value in the outside. This PR updates it to use `RenderResults`'s metadata instead.
In the future we should use `Reaedonly<RenderOpts>` and ban `as any` <picture data-single-emoji=":lolsob:" title=":lolsob:"><img class="emoji" width="20" height="auto" src="https://emoji.slack-edge.com/T0CAQ00TU/lolsob/2e754996aebc14fa.png" alt=":lolsob:" align="absmiddle"></picture>
There're various of cases would cause the `beforeRender` performance mark is not existed in the performance entries, learned from the issues description. We have to check if that mark is existed.
This PR also refactors all the mark names and measurement names into constants so that we won't easily mistype them
Fixes#20743Fixes#40903Fixes#47560
Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
### What?
I kindly request the maintainers to review this Pull Request, which aims to migrate the `with-mongoose` example to TypeScript with total type safety.
### Why?
By doing so, we enhance the overall quality and maintainability of the example, aligning it with modern best practices for type-safe codebases.
### How?
I have thoroughly tested the changes to ensure they do not introduce regressions and maintain compatibility with the existing codebase.
Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
### What?
This hooks up Turbopack's `TurbopackResult` issues into Next's HMR
messages.
### Why?
We need to deliver good error messages to devs so that they can quickly
fix any issues.
### How?
This builds up a debounced HMR queue (necessary because of the Turbopack
architecture delivering multiple messages via different async
iterators). If any HRM message contains an issue, we'll send down a
`built` message containing the issues and delay sending the real
messages. Once everything has been resolved, we'll resume sending down
HMR messages.
<img width="990" alt="Screenshot 2023-08-31 at 9 01 20 PM"
src="https://github.com/vercel/next.js/assets/112982/d5421779-2415-4a60-8d95-94f0e1147d6d">
Closes WEB-1484
---------
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
This adds logging to indicate build progress while using Turbopack in the same format that webpack uses. It uses the same store object and sets state to log messages like so:
```
- wait compiling /page (client and server)...
- event compiled client and server successfully in 1366 ms
```
Given:
- An app router page `/`, `compiling /page` is logged
- An app router page `/bar`, `compiling /bar/page` is logged
- An app router route `/api/bar`, `compiling /api/bar/route` is logged
- A page router page `/foo`, `compiling /foo` is logged
- A page router api route `/api/foo`, `compiling /api/foo` is logged
Closes WEB-1476
Optimizes how we handle cache tags for soft tags (auto-added by Next.js)
and normal tags (added manually) and adds differentiating between
`revalidatePath('/blog/first')` and page/layout.
Soft tags are not stored across cache entry and instead auto sent along
when checking cache entries. This allows us to prevent storing
exponential amounts of tags across cache entries while still having the
relationship between them so that single path revalidation can work
properly.
x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1690586837903309)
### What?
In the Payment Element demo, call
[`elements.update()`](https://stripe.com/docs/js/elements_object/update)
when the payment amount value is updated via slider. This ensures
wallets (Apple Pay, Google Pay) display the correct payment amount.
---------
Co-authored-by: Michael Novotny <manovotny@gmail.com>
### What?
Fixes a bug introduced in #54668, where the `/` path would map to the build manifest `.next/server/page/app-build-manifest.json` in App router instead of the correct `.next/server/index/page/app-build-manifest.json`
It also addresses an issue where `not-found` manifests would map to `.next/server/not-found/app-build-manifest.json` instead of the correct `.next/server/not-found/page/app-build-manifest.json`.
### Why?
The `&& type === 'pages'` mean we only rewrote `/` to `/index` in Pages router, where it needs to apply to both App and Pages. Likewise, special-casing `not-found` led to it not finding the manifest.
### How?
Duplicate the logic from d3a107991c/packages/next-swc/crates/next-core/src/util.rs (L65-L76)
Closes WEB-1471
Co-authored-by: Will Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
### What?
There were a few issues with the initial implementation of next-api HMR:
1. We incorrectly errored out when we received a Next.js WebSocket message
2. We didn't handle Next's `span-end` message, leading to another error
3. We listened to the `htmlEndpoint` change events instead of the `dataEndpoint`/`rscEndpoint`, leading to us detecting client-side changes and causing full page reloads
### Why?
HMR is the life-blood of development
### How?
Small fixes to our Turbopack reimplementation of the server-side HRM handlers
Closes WEB-1475