Commit Graph

185 Commits

Author SHA1 Message Date
Zack Tanner
b735f37fd9 [next]: ensure unmatched rsc rewrites are routed to correct handler (#11688)
Same reasoning as:

- https://github.com/vercel/vercel/pull/11686

Split this into a separate PR so it can be tested/released separately.
2024-06-04 18:52:44 +00:00
Zack Tanner
7457767a77 [next]: ensure unmatched action rewrites are routed to correct handler (#11686)
User defined rewrites are "normalized" so that our internal rewrites are still properly handled. Before normalizing these rewrites, the Next.js builder will attempt to match server action requests to a`.action` variant. Then the user-defined rewrites flow through the afterFiles normalization ([this part](https://github.com/vercel/vercel/blob/fix/unmatched-action-rewrites/packages/next/src/server-build.ts#L254-L279)) so that when we add `.action` in the builder, we don't drop the suffix. 

But this normalization can lead to a malformed `dest`. e.g., if I had rewrite like this:

```js
{
  source: '/greedy-rewrite/static/:path*',
  destination: '/static/:path*',
}
```

The builder would go through this flow on an action request to `/greedy-rewrite/static`:

1. It'll attempt to match it to a `.action` output, so `/greedy-rewrite/static` -> `/greedy-rewrite/static.action`
2. The afterFiles normalization will take place, so the original `dest` of `/static/$1` will become `/static/$1$rscsuff`
3. $1 will be an empty string, because it doesn't match the existing capture group. So now `/greedy-rewrite/static.action` -> `/greedy-rewrite/static/.action`
4. `static/.action` is not a valid output, so it'll 404 and the action will break. 

Existing handling exists for `.rsc` outputs for a similar reason, but only on the index route. I added a similar fix for this in #11688.
2024-06-04 18:05:11 +00:00
Wyatt Johnson
4337ea0654 [ppr] Add missng .rsc route for non-ppr enabled pages (#11681)
When deploying partial prerendering (PPR), there may some pages that are
not enabled for PPR but still appear in the `prerender-manifest.json`.
Due to the branching of the client router, these routes also have to
have a `.rsc` as well as a `.prefetch.rsc` variants in order to prevent
404's. This change adds support for adding the extra route to the
prerender for pages that have PPR disabled.
2024-06-03 17:52:30 -07:00
Zack Tanner
5f561f8cfa [next]: ensure user rewrites match to action outputs (#11628)
The builder normalizes user rewrites that target pages that have special outputs (`.rsc`, `.prefetch.rsc`). When we added support for `.action` outputs, we need to perform this same normalization to ensure that user rewrites still match. If the rewrite was a greedy match (eg `/:path*`) it'd be ok, but more specific rewrites would have the issue.
2024-05-23 19:06:25 +00: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
fe9e27c459 chore: bump react version (#11636) 2024-05-23 05:14:10 +00:00
Wyatt Johnson
464cb26255 chore: bump react versions (#11632) 2024-05-22 19:45:03 -07:00
Zack Tanner
80e0bab0ec [next] Fix Next.js tests (#11610)
Syncs the experimental React dependency to avoid build errors. 

This was updated in:
- https://github.com/vercel/next.js/pull/65864
2024-05-17 22:24:53 +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
Zack Tanner
18d1703d5b [next]: skip action rewrite if RSC header is present (#11576)
When rewriting requests that contain a `next-action` header to a `.action` output, we should do so only in the case where the RSC header isn't present. When a Next.js server action triggers a `redirect`, an intra-app RSC request will be made to that requested URL, with the `next-action` header still present. This means the intra-app request will be incorrectly rewritten, when we only intended to handle the actual action request.

This was patched in Next.js in the following PR:
- https://github.com/vercel/next.js/pull/65615

But it seems like a good idea to be resilient to this here as well.
2024-05-10 21:09:56 +00:00
Zack Tanner
11584b0e9b [next] ensure action outputs are created for edge functions (#11568)
Since we're rewriting `next-action` requests to `.action` outputs, we need to ensure that we also duplicate the edge function handler for it. 

This runs all of the existing Node runtime tests in the Edge runtime as well. However, there's a discrepancy in how `x-vercel-cache` is returned, so for now we instead validate that its responding with `x-edge-runtime`.
2024-05-09 01:39:08 +00:00
JJ Kasper
3023122d4e [next] Update react version in next fixtures (#11566)
We are locking the peerDependency to react v19 beta on canary so we need to update these fixtures to tolerate that. 

x-ref: [slack thread](https://vercel.slack.com/archives/C048KLPEEH1/p1715191372631389)
x-ref: https://github.com/vercel/next.js/pull/65058
2024-05-08 23:33:24 +00:00
Wyatt Johnson
119f80e961 [next] Support Incremental Partial Prerendering (#11560)
This fixes the logic that detects if partial prerendering (PPR) has been
enabled for a project. The new incremental adoption pathway allows
setting the `experimental.ppr = 'incremental'` which the previous code
did not support.
2024-05-08 08:13:39 -06:00
JJ Kasper
50fc27ba57 [next] Remove .prefetch.rsc rewrites for non-PPR (#11540)
Removes .prefetch.rsc rewrites rules for non-PPR, as Next.js doesn't emit any static prefetches otherwise
2024-05-06 18:17:22 +00:00
JJ Kasper
124846a3e6 [next] Fix base path app index RSC handling (#11528)
This ensures we properly name the outputs when a basePath is present for the `index` output as previously we weren't properly routing to the RSC output due to nested `index` naming/route conflict. This only was a noticeable issue with prerender/static index outputs with base path and app router since if the index route was dynamic it would still catch the RSC request and just handle it without the correct naming. 

Fixes: https://github.com/vercel/next.js/issues/64903
2024-05-02 21:07:58 +00:00
JJ Kasper
58c6755e0c [next] Fix interception routes PPR route handling (#11527)
This ensures we properly create `.prefetch.rsc` output aliases for non-prerender outputs when PPR is enabled so that we can properly route which handles the interception route case as that is always dynamic so was missing it's `.prefetch.rsc` output causing the prefetch request to 404 unexpectedly. 

x-ref: [slack thread](https://vercel.slack.com/archives/C070ZMMKVU7/p1714511126337289)
2024-05-01 22:40:04 +00: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
JJ Kasper
3420ba0153 [next] Update test fixture version (#11514)
Noticed in https://github.com/vercel/vercel/pull/11503 that this test
fixture is incorrectly locked to a specific version when we don't want
it to be.
2024-04-30 13:03:36 -07: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
9dab15dc88 [next] add tests for server actions (#11482)
There aren't currently any tests for server actions which have special handling in the builder. This adds tests to help avoid regressions in future Next.js builder work.
2024-04-24 18:10:51 +00: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
Chris
1e6323e2b1 [cli] Ignore VERCEL_ANALYTICS_ID if @vercel/speed-insights is present on the project (#11305)
In the past, we used the `VERCEL_ANALYTICS_ID` environment variable with the previous Speed Insights feature on Vercel to activate specific logic in Next.js, Nuxt and Gatsby for collecting and sending web vitals data.

With the new Speed Insights, that's not required anymore.

We no longer want to set the environment variable when detecting the new `@vercel/speed-insights` package. 
This PR confirms that the variable is not set if the new package is detected.
2024-04-18 15:08:32 +00:00
JJ Kasper
949d84ad1c [next] Ensure _not-found is included properly in app router functions (#11441)
This ensures we properly include `_not-found` assets when present for
app router specific functions as otherwise when attempting to render
`notFound()` case we can hit `MODULE_NOT_FOUND` errors. A test case for
this behavior has been added under `00-app-router-not-found`.

Closes: [NEXT-3084](https://linear.app/vercel/issue/NEXT-3084)
2024-04-17 13:37:39 -07: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
Ethan Arrowood
0b1ff4bf62 [next] add x-forwarded-port test (#11254)
This test reproduces the issue described in https://github.com/vercel/next.js/issues/61133 . Unfortunately, I can only reproduce this issue when deploying to Vercel. Any local server / test results in the header being defined. 

Related: https://github.com/vercel/next.js/issues/61133
2024-03-28 08:20:18 +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
Wyatt Johnson
b1d8b83abb [next] Support pre-generated pages without fallbacks with Partial Prerendering (#11183) 2024-03-01 18:29:31 -07:00
Sean Massa
142a397d8e [tests] fix next.js tests (#11145)
The Next.js change in https://github.com/vercel/next.js/pull/61794 means
that the `Vary` header will contain `Next-Url` less often. We need to
update the assertions on our end to accommodate.
2024-02-13 08:27:46 -06: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
JJ Kasper
3bad73401b Fix rewrite RSC handling with trailingSlash (#11107)
This ensures our rewrite patching to handle RSC requests handles a trailing slash being present with added regression tests.
2024-01-30 22:34:17 +00:00
JJ Kasper
fbe08fe57e [next] Ensure rewrites handle RSC requests (#11005)
This ensures we add handling for our internal `.rsc` suffixes for rewrites since this currently fail to match by default unless the user manually adds handling for this. Updated our test fixture to ensure this is tested properly.
2024-01-02 18:46:31 +00:00
Zack Tanner
ab34a26205 [tests] fix brittle next rewrite probe test (#10934)
It seems the intention of this test was to verify that the rewritten
file matches the original file, but it does so by just asserting on
arbitrary script text, which is brittle and broke as a result of
https://github.com/vercel/next.js/pull/56294

The right way to test this would be to fetch the original script and
compare the contents with the rewritten script, but this relies on
`__NEXT_SCRIPT__` magic which is only available in probe checks. For now
this just asserts on a valid status code, as a chunk that isn't properly
rewritten should 404 in this case.
2023-12-11 16:24:43 -08: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
9472c22bf7 [next] Added more PPR tests (#10823)
This adds additional regression tests for PPR support for Next.js.
2023-11-09 23:45:35 +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
Bryce Kalow
33cc8e0acf fix(next): do not generate conflicting lambdas when using basePath with app router (#10738)
When using `basePath` with statically generated routes, the builder
currently generates lambdas for the root route that conflict with the
prerender functions generated.

E.g. if we have `basePath: "test"` and a root route at: `app/page.js`,
this is currently the output:

```
test
test.rsc
test/index
test/index.rsc
```

The result is that visiting the deployed app at `/test` renders an
incomplete page. On the other hand visiting `/test/index` outputs the
expected markup.

It seems like the intent is that we want to delete the lambdas that
conflict with the prerender functions. I've updated the lambda name
generation logic when doing the deleting to line up with how the lambda
names are generated initially.
2023-11-03 13:25:56 -07: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
f8320417a8 [next] replace next export with output: export in tests (#10756)
`next export` has been deprecated on the latest Next.js canary so these
tests will no longer pass.

This changes it to use `output: export` from `next.config.js` instead.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-10-24 09:41:54 -07:00
JJ Kasper
de84743e10 Fix RSC prefetch for index route with catch-all (#10734)
When matching outputs and we have an `index.{ext}` file it will take priority over dynamic routes which we don't want to match prefetch RSC index outputs unless it's specifically a prefetch request so this remaps this specific file to avoid the overlap. 

x-ref: [slack thread](https://vercel.slack.com/archives/C061DMGDXQW/p1697664158904469?thread_ts=1697647520.783419&cid=C061DMGDXQW)
2023-10-20 15:05:30 +00:00
JJ Kasper
39ce9166ba Update to run Next.js integration with Node.js v18 (#10740)
Co-authored-by: Chris Barber <chris.barber@vercel.com>
Co-authored-by: Steven <steven@ceriously.com>
2023-10-20 09:36:50 -05:00
Chris Barber
5e6ef3d569 Enable source maps in tests (#10725)
The `tsconfig` files were unified with a common configuration in https://github.com/vercel/vercel/pull/10667 including disabling source maps. The source maps greatly increase the distribution size, but they are invaluable when the tests run, so this PR enables source maps for tests including adding a `tsconfig.json` where absent.

Linear: https://linear.app/vercel/issue/ZERO-364/enable-sourcemaps-in-all-testtsconfigjson-files
2023-10-17 15:15:29 +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
Steven
fa8e313222 [next] fix test missing yarn.lock file (#10642)
- Follow up to https://github.com/vercel/vercel/pull/10630

Was passing in the PR
https://github.com/vercel/vercel/actions/runs/6386018083/job/17332012211#step:9:269

But is failing on main
https://github.com/vercel/vercel/actions/runs/6386371621/job/17332970210

Looks like the `yarn.lock` was removed right before merging so this PR
adds it back.

INC-442
2023-10-03 17:22:30 -04:00