Commit Graph

114 Commits

Author SHA1 Message Date
Wyatt Johnson
c9d53d4e3e [next] Ensure only pages enable streaming (#11660)
This fixes a regression introduced by #11625 that enabled streaming for
routes on the pages router (these routes do not support streaming).
2024-05-24 15:15:32 -07:00
Wyatt Johnson
61e6af3740 [ppr] Fix for error case involving prefetch data routes (#11638)
Only error when the prefetch data route is present but the route also
has PPR enabled.
2024-05-23 10:28:05 +02:00
Wyatt Johnson
8e44ef5b9d [ppr] Fix static case (#11635)
When PPR is enabled in incremental mode, the previous code used the page information to determine if there was a failure for generating the flight data. This has been moved to the app PPR setting instead.
2024-05-23 05:23:26 +00:00
Wyatt Johnson
73e558913a [ppr] Fix PPR detection for groups (#11625)
Previously, PPR was either all on, or all off. As we've added support for incremental adoption of PPR, the logic for determining if there's a grouping issue had to be adjusted.

This now only considers a group as supporting PPR if a route in the group supports PPR. As we also use this as a grouping key, this still ensures we won't have conflicts.
2024-05-23 04:06:12 +00:00
Zack Tanner
67afc26085 [next]: normalize source path for special app-dir metadata files (#11579)
When specifying a functions configuration in `vercel.json`, we attempt to find source files for all entrypoints.  This attempts to normalize those source paths for some special cases so that we don't show a build warning for completely normal usage.

- `/_not-found` is an entrypoint automatically inserted by Next.js -- if we don't find a source file for it, don't warn, as the user might not have added one
- special metadata files like `favicon.ico` and `opengraph-image.<ext>` will be bundled as `favicon.ico/route.js` but the source file will be the raw extension.
2024-05-13 16:04:16 +00:00
JJ Kasper
5a532a5b94 [next] Fix missing initial RSC headers (#11552)
While investigating https://github.com/vercel/next.js/issues/59883 we noticed the RSC Prerender did not have all the expected headers like the HTML Prerender which caused unexpected revalidation behavior specifically on client-transition as some of these headers are used to detect if a revalidated tag is associated with specific outputs. 

x-ref: https://github.com/vercel/next.js/issues/59883
2024-05-07 07:43:00 +00:00
Jiachi Liu
c1d8522950 [next] rename middleware manifest env (#11549)
Rename `environment` property to `env` from middleware manifest added in
#11390.
Align with https://github.com/vercel/next.js/pull/64521

The `environments` property wasn't working properly before due to
unfinished next.js changes, it should work now after testing with next
build from https://github.com/vercel/next.js/pull/64521. We change it to
a better naming word `env`.
2024-05-06 21:32:07 +02:00
JJ Kasper
52e435aa5d Fix missing .rsc outputs for pages prerenders (#11503)
When generating the outputs for pages when app router is also present we weren't creating the placeholder `.rsc` outputs for all prerender outputs so when a `fallback: false` route was configured in the pages router that could fall through to an app route it causes issues with client-navigation behaving differently than a direct visit. 

This ensures we add the placeholder `.rsc` outputs for all prerenders so that `fallback: false` pages don't have this unexpected behavior.
2024-04-30 20:34:41 +00:00
Zack Tanner
b1adaf76ec [next] Only rewrite next-action requests to .action handlers (#11504)
This only rewrites requests that contain a `next-action` header (explicitly indicating it's a server action). A side effect is that POST requests to a server action on a static route, without a next-action header, won't be marked as streaming (but will still execute normally). This is fine as only the handled action needs to stream. 

This relands .action handling behind a feature flag.
2024-04-30 18:32:54 +00:00
Zack Tanner
5b79603378 Revert "[next] Reland add .action handling for dynamic routes" (#11509)
Reverts vercel/vercel#11487.

This feature will be relanded behind a feature flag.
2024-04-29 10:26:15 -05:00
JJ Kasper
5758838d09 [next] Reland add .action handling for dynamic routes (#11487)
This relands https://github.com/vercel/vercel/pull/11461 fixing the
routes increase by combining with the existing route so we don't hit the
routes limit like we did previously.

---------

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2024-04-24 12:33:16 -07:00
Zack Tanner
64bd6dd057 Revert "[next] add .action handling for dynamic routes" (#11470)
Reverts vercel/vercel#11461 and #11454  while we revisit the approach to produce fewer rewrites.
2024-04-19 18:26:01 +00:00
Zack Tanner
5bb96ea072 [next] add .action handling for dynamic routes (#11461)
Follow-up to:
- https://github.com/vercel/vercel/pull/11454

Adds similar handling for dynamic routes
2024-04-18 19:04:30 +00:00
Zack Tanner
993a60ef71 [next] add streaming prerender group for actions (#11454)
Invoking an action that's a Prerender will currently bypass the static cache (via `experimentalBypassFor`), but the prerender group doesn't support streaming.

This clones the prerender group and adds corresponding rewrites for those requests. Separately, we'll deprecate `experimentalBypassFor`.

Depends on:
- https://github.com/vercel/next.js/pull/64592
2024-04-18 15:47:24 +00:00
JJ Kasper
fd80318743 [next] Remove un-necessary compressed function size calc/constraint (#11442)
Historically, we used to have a compressed function size limit of `50MB` but this is a very old limit and was removed long ago. Considering this limit is removed and it requires additional overhead to calculate, this removes the compressed size limit handling while leaving the uncompressed size limit detection/handling.
2024-04-17 19:50:54 +00:00
Florentin / 珞辰
2461b571af [next] use middleware manifest worker environments (#11390)
This PR adds changes to the Next.js builder to pass the per-worker environment emitted from the Next.js middleware manifest to the created `EdgeFunction` resource.
2024-04-10 08:27:53 +00:00
Wyatt Johnson
4bca0c6d0b [next] Ensure all static routes have static streaming lambda path (#11259)
When there's a match for a prerender, the dynamic query parameters will
not be provided via the `x-now-route-matches`. This ensures that when
generating any static route that the static streaming lambda path is
used if it's provided, ensuring that when a page is generated via
`generateStaticParams`:

```tsx
// app/blog/[slug]/page.tsx

type Props = {
  params: {
    slug: string
  }
}

export function generateStaticParams() {
  return [{ slug: "one" }, { slug: "two" }, { slug: "three" }]
}

export default function BlogPage({ slug }: Props) {
  // ...
}
```

That we use the specific routes (`/blog/one`, `/blog/two`, and
`/blog/three`) for the partial prerendering streaming path instead of
the paramatarized pathname (`/blog/[slug]`) as the rewrites won't be
matched once a match for a prerender has been found.

This additionally updates the tests to ensure that the correct pathname
is observed (this was previously silently failing).
2024-03-14 12:37:48 -06:00
Andy
908e7837d5 [cli][build-utils] Rename variants to flags (#11121)
- Removes all the legacy `flags`
 - Renames the new `variants` to `flags`

Neither the legacy flags, nor the new variants were exposed to anyone, except for the type in build-utils, so there shouldn't be any issues removing/renaming them.
2024-03-08 16:06:23 +00:00
Wyatt Johnson
b1d8b83abb [next] Support pre-generated pages without fallbacks with Partial Prerendering (#11183) 2024-03-01 18:29:31 -07:00
JJ Kasper
d17abf463a Update experimental bundle flag (#11187)
Makes bailing from grouping logic more explicit
2024-02-21 20:53:16 -08:00
Wyatt Johnson
38c5e93625 Add immutability modifiers to types (#11182)
This doesn't change any functionality, and only replaces some mutable types (like `Map`, `Set`, and `Array`) with their immutable versions (like `ReadonlyMap`, `ReadonlySet`, and `ReadonlyArray`). This can help keep functions as pure as possible and improves the readability of some of the involved functions.
2024-02-21 17:50:56 +00:00
JJ Kasper
ea0e9aeaec [next] Add flag for experimental grouping (#11177)
Just adds a flag for experimenting
2024-02-20 18:03:03 -08:00
Andy
8ba0ce9324 [cli] Add Variants to Build Output API (#11098)
Makes adjustments to replace `flags` with `variants`.

Also marks the current `flags` implementation as deprecated, as it
should get removed soon. Which I'll do in a follow up PR.
2024-02-01 10:28:12 +01:00
JJ Kasper
4027a18337 Fix index normalizing for app outputs (#11099)
This ensures we don't apply the index output normalizing for app paths which was previously already gated for prerenders but not all routes.
2024-01-31 22:13:23 +00:00
Ethan Arrowood
0716130e58 Use worker.name instead of edge function name to fix type error in @vercel/next (#11050)
Uses another `name` property instead of the now deprecated one.
2024-01-16 12:56:28 -08:00
Trek Glowacki
44569e6929 Remove unneeded global directives (#10980)
An update to latest `turbo` somehow made these no longer required? 🤷

---------

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-12-20 12:14:10 -06:00
Wyatt Johnson
7b0adf371b [next] App Pages Prerender Manifest Update (#10978)
Previously routes that did not have a `dataRoute` key in the `prerender-manifest.json` would be treated as an App Route. The logic has been updated (for partial prerendering support) to also consider the new `prefetchDataRoute`. Entries with either of these keys are treated as an App Page instead of an App Route.

This also addressed the scenerio where a app route (`route.ts`) with a dynamic segment (`/api/[slug]/route.ts`) which doesn't emit a `.body` during build doesn't cause the build to fail by checking for the file first.
2023-12-19 21:03:18 +00:00
Zack Tanner
ffd2f34c6c [next] ensure function configs apply to route groups (#10855)
`getSourceFilePathFromPage` attempts to match patterns found in `vercel.json` with source files. However, the `page` argument to this function is stripped of route groups, so these files are erroneously skipped and function settings are not applied. 

For app-dir routes which might contain route groups, this checks an internal mapping which maps the "normalized" paths (e.g. `app/dashboard/[slug]/page.js`) to the file-system path (e.g. `app/dashboard/[slug]/(group)/page.js`)
2023-11-21 00:44:46 +00:00
Wyatt Johnson
fd29b966d3 tests: added tests for PPR (#10808)
This adds some tests to the PPR implementation for Next.js. This also
fixes a bug where the static pages were incorrectly generating a header
that falsly indicated that it postponed.
2023-11-08 09:21:51 -07:00
Wyatt Johnson
c94a082f6b Added getRequestHandlerWithMetadata export (#10753)
This adds a new `getRequestHandlerWithMetadata` export if enabled and
available to the exported method.

---------

Co-authored-by: Joe Haddad <timer@vercel.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-11-07 10:32:03 -08:00
JJ Kasper
f5296c3c06 Rework prefetch route handling (#10779)
Follow-up to https://github.com/vercel/vercel/pull/10750 this removes the underscore prefetching from all prefetch outputs and instead only applies it to the index route itself as this causes issues with PPR making these outputs prerenders and being able to interpolate the route param values. 

There is the edge case of a user returning the literal value `index` from `generateStaticParams` but we can tolerate that more than ppr not working as expected.
2023-10-31 18:15:13 +00:00
Zack Tanner
fc90a3dc0b [next] fix re-mapping logic for index prefetches (#10750)
Follow-up to https://github.com/vercel/vercel/pull/10734 -- but considers that the static prefetch associated with `/` might be inside of a dir such as `index/index.prefetch.rsc`. 

To avoid any future matching conflicts, this PR updates to prefix all static prefetches
2023-10-24 20:51:55 +00:00
Zack Tanner
da300030c9 [next] fix build in appDir on windows (#10708)
On Windows, `globPath` is a non-POSIX path (ie `'favicon.ico\\route.js'`) which won't match the paths generated by the `glob` util, since it normalizes Windows separators to Unix separators ([ref](https://github.com/vercel/vercel/blob/main/packages/build-utils/src/fs/normalize-path.ts#L6-L8))
2023-10-16 14:57:38 +00:00
Steven
c523a755f8 Revert "[next] Correct output file tracing and limit calculation (#10631)" (#10651)
This reverts commit e9026c7a69.

This was causing some builds using Turbo + Next.js to fail with:

```
...writing to cache...
--
17:02:42.820 | Traced Next.js server files in: 169.874ms
17:02:42.871 | Error: Config file was not found at "/vercel/output/config.json"
17:02:42.871 | at f3 (/var/task/sandbox.js:239:2647)
17:02:42.872 | at async TCe (/var/task/sandbox.js:245:4681)
17:02:42.872 | at async WBt (/var/task/sandbox.js:261:1990)
17:02:42.872 | at async zBt (/var/task/sandbox.js:261:1791)
```

INC-442
2023-10-03 22:07:56 +00:00
JJ Kasper
e9026c7a69 [next] Correct output file tracing and limit calculation (#10631)
While investigating build times noticed that our lambda creation times were increasing linearly with the number of pages which is unexpected since there are mostly shared dependencies. After further investigation it seems we were falling back to our legacy manual `nodeFileTrace` calls in the builder when we shouldn't have been.

Also noticed we were still doing the un-necessary reading/calculating for uncompressed lambda sizes which is as discussed previously isn't required and the only limit we need to keep enforcing is the uncompressed size which is a lot less expensive to compute. 

As a further optimization this adds proper usage of our lstat cache/sema where it wasn't previously and proper parallelizing where applicable. 

These changes reduce tracing/lambda creation times by 3-5x in larger applications and can fix edge cases where we weren't leveraging our more accurate traces from the build. 

Before: 

```sh
Traced Next.js server files in: 444.05ms
Created all serverless functions in: 1:36.311 (m:ss.mmm)
Collected static files (public/, static/, .next/static): 241.47ms
```

After: 

```sh
Traced Next.js server files in: 10.4ms
Created all serverless functions in: 43.684s
Collected static files (public/, static/, .next/static): 250.828ms
```
2023-10-03 00:00:20 +00:00
Csaba Palfi
a18ed98f2d [next] fix lambda creation for i18n edge pages (#10630)
An issue similar to https://github.com/vercel/next.js/issues/44381
exists whereby vercel creates lambda functions for edge pages when i18n
is configured.

Fixes https://github.com/vercel/next.js/issues/42854

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-10-02 18:57:50 -04:00
Nathan Rajlich
d0d0520111 [next] Use "esbuild" to build package (#10482)
### Before

```
$ time pnpm run build

> @vercel/next@4.0.6 build /Users/nrajlich/Code/vercel/vercel/packages/next
> node build.js

ncc: Version 0.24.0
ncc: Compiling file index.js
ncc: Using typescript@4.9.5 (local user-provided)
1506kB  dist/main/index.js
1506kB  [3345ms] - ncc 0.24.0

real    0m5.210s
user    0m9.083s
sys     0m0.506s

$ ls -l dist/
total 1700
-rw-r--r-- 1 nrajlich staff    2176 Sep 20 15:18 ___get-nextjs-edge-function.js
-rw-r--r-- 1 nrajlich staff    3283 Sep 20 15:18 create-serverless-config.js
drwxr-xr-x 6 nrajlich staff     192 Sep 20 15:18 edge-function-source/
-rw-r--r-- 1 nrajlich staff 1542314 Sep 20 15:18 index.js
-rw-r--r-- 1 nrajlich staff     728 Sep 20 15:18 legacy-launcher.js
-rw-r--r-- 1 nrajlich staff    6807 Sep 20 15:18 legacy-versions.js
-rw-r--r-- 1 nrajlich staff   66662 Sep 20 15:18 server-build.js
-rw-r--r-- 1 nrajlich staff    1583 Sep 20 15:18 server-launcher.js
-rw-r--r-- 1 nrajlich staff    5167 Sep 20 15:18 sourcemapped.js
-rw-r--r-- 1 nrajlich staff    1003 Sep 20 15:18 templated-launcher-shared.js
-rw-r--r-- 1 nrajlich staff     799 Sep 20 15:18 templated-launcher.js
-rw-r--r-- 1 nrajlich staff   83876 Sep 20 15:18 utils.js

$ pnpm pack && ls -lh vercel-next-4.0.6.tgz 
-rw-r--r-- 1 nrajlich staff 373K Sep 20 15:19 vercel-next-4.0.6.tgz
```

### After

```
$ time pnpm run build

> @vercel/next@4.0.6 build /Users/nrajlich/Code/vercel/vercel/packages/next
> node build.mjs

real    0m1.144s
user    0m0.550s
sys     0m0.171s

$ ls -l dist/
total 540
-rw-r--r-- 1 nrajlich staff   2176 Sep 20 15:15 ___get-nextjs-edge-function.js
-rw-r--r-- 1 nrajlich staff 528575 Sep 20 15:15 index.js
-rw-r--r-- 1 nrajlich staff   1680 Sep 20 15:15 legacy-launcher.js
-rw-r--r-- 1 nrajlich staff    901 Sep 20 15:15 server-launcher.js
-rw-r--r-- 1 nrajlich staff    532 Sep 20 15:15 templated-launcher-shared.js
-rw-r--r-- 1 nrajlich staff    316 Sep 20 15:15 templated-launcher.js

$ pnpm pack && ls -lh vercel-next-4.0.6.tgz 
-rw-r--r-- 1 nrajlich staff 104K Sep 20 15:15 vercel-next-4.0.6.tgz
```
2023-09-20 20:01:03 +00:00
Andy
decdf27fb5 [cli][next][build-utils] Variants (#10549)
Co-authored-by: Ethan Arrowood <ethan.arrowood@vercel.com>
2023-09-20 19:42:20 +02:00
Zack Tanner
083aad448e [next] missed a prerender for experimentalBypassFor (#10504)
Missed this in https://github.com/vercel/vercel/pull/10497
2023-09-14 01:19:13 +00:00
Zack Tanner
7a0fed970c [next] provide experimentalBypassFor to prerender from manifest (#10497) 2023-09-12 17:40:49 -05:00
Jimmy Lai
2f461a8b0b next.js: add option to use bundled runtime (#10485)
This PR adds an environment variable that should allow us to test the bundled version for Next.js on Vercel, see https://github.com/vercel/next.js/pull/52997 for reference.

The changes include:
- a new environment variable `VERCEL_NEXT_BUNDLED_SERVER`
- some logic changes that will put app route handlers into their own lambda groups
- extra logic to require early the rendering runtimes (see PR above for details)
2023-09-12 19:45:23 +00:00
Zack Tanner
a732d30c84 [next] fix content-type for RSC prefetches (#10487)
This ensures that the `.prefetch.rsc` requests respond with the correct `content-type` since this is used by Next.js to determine if a request is valid or not (and in the case it's invalid, an mpa navigation will occur)

Fixes: https://github.com/vercel/next.js/issues/54934
2023-09-11 19:04:16 +00:00
JJ Kasper
caaba0d685 [next] fix app dir edge functions with basePath (#10465)
x-ref: https://github.com/vercel/vercel/pull/10394
2023-09-07 22:03:12 +00:00
Zack Tanner
c3c54d6e69 [next]: Fix RSC rewrite behavior (#10415)
- Removes some of the hacks from #10388 that were attempting to resolve an issue with RSC prefetches to `pages` routes in favor of adding rsc rewrites for all dynamic paths, and letting it fall through to a 404 if there's no match
- Fixes an issue where RSC requests were matching the wrong path (filesystem rather than RSC variant) introduced in above mentioned change
  - Closes https://github.com/vercel/next.js/issues/54698
2023-09-07 14:03:14 +00:00
JJ Kasper
4422326865 Add handling to leverage RSC prefetch outputs (#10390)
Implements handling for the RSC prefetch outputs when available that
were added in https://github.com/vercel/next.js/pull/54403
2023-08-23 22:26:58 -07:00
Zack Tanner
09446a8fe8 [next] fix RSC matching behavior & 404 status code on fallback: false (#10388)
Fixes two separate issues for the Next builder:

- `pages` routes unexpectedly matching to RSC routes when prefetching from `app`. This update will attempt to match the route with the corresponding `pages` entry rather than falling back to a catch-all RSC
  - Fixes https://github.com/vercel/next.js/issues/53776
- `fallback: false` returning a successful status code when underlying page as a param (e.g. `/blog/[slug]` would 200 but `/blog/non-existent` would 404)
  - [slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1692817762403579)
2023-08-23 22:30:33 +00:00
JJ Kasper
b1c14cde03 [next] Fix pages and app router i18n handling (#10243)
Ensures app router paths are handled properly when i18n is configured for pages directory. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1687565759424049)
x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1687565759424049)
x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1672781549860349?thread_ts=1671393204.073649&cid=C03KAR5DCKC)

[VCCLI-780](https://linear.app/vercel/issue/VCCLI-780/add-404i18n-invariant-case-in-nextjs-builder)
2023-07-24 23:26:25 +00:00
Zack Tanner
c670e51712 [next] fix 404 page in edge runtime (#10223)
Fixes Next builder to handle edge runtime on 404 pages

[Related Next.js PR](https://github.com/vercel/next.js/pull/52754)
[slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1689312606770609)
2023-07-17 19:48:45 +00:00
Florentin / 珞辰
cae60155f3 [next] support maxDuration in Next.js deployments (#10069)
Follow up PR to
8703c55f9f
which reads the newly created function config manifest and patches in
the options for resource creation.

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-07-14 15:27:06 +02:00
JJ Kasper
e4895d979b [next] Update payload flag (#10147)
x-ref: [slack thread](https://vercel.slack.com/archives/C05E6RJTPJS/p1687898295532579)
2023-06-27 23:34:21 +00:00