Commit graph

802 commits

Author SHA1 Message Date
Jiachi Liu
c5308eb4a8
Respect fetching logging config and Polish logs format (#52973)
Respect to the logging option which was introduced in #49250 that only logs when `experimental.logging` set to `"verbose"`

Polish the logging format a bit that make it more compact and lit
![image](https://github.com/vercel/next.js/assets/4800338/7b41424b-1215-415b-84c9-4619512ba0b4)


Related NEXT-1357
2023-07-27 09:02:42 +00:00
Zack Tanner
c73fdfd87c
Fix file tracing issues for not-found pages (#53231)
This fixes the `.nft.json` output for not-found pages to correctly grab the client reference manifest. We were checking for `entryPoint.name.startsWith('app/')` but then asserting on `entryPoint.name === '/_not-found'` when determining the manifest path.

This also fixes the build output to mark pages with `λ` if the corresponding page has dynamic data. This revealed a separate issue that de-opts all pages into dynamic rendering if the root `NotFound` page bails, tracked in [NEXT-1474](https://linear.app/vercel/issue/NEXT-1474/if-the-root-notfound-page-opts-into-dynamic-rendering-all-pages-do-too)

[slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1683763412272429)
2023-07-27 00:08:53 +00:00
Zack Tanner
22ca85946e
Wrap incremental cache in an IPC server (#53030)
This uses an IPC server (if available) for incremental cache methods to help prevent race conditions when reading/writing from cache and also to dedupe requests in cases where multiple cache reads are in flight. This cuts down on data fetching across the different build-time workers.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-26 23:19:46 +00:00
JJ Kasper
1c5c0ba3ff
Temporarily skip flakey action revalidate (#53134)
These have been flaking for quite a while so skips them more
consistently until they are investigated.

x-ref:
https://github.com/vercel/next.js/actions/runs/5650048471/job/15305721826#step:27:590
2023-07-24 15:37:30 -07:00
Jiachi Liu
d8f4fa8946
Fix not found hangs the build with overridden node env (#53106)
### Why

In #52985 the not found solution introduces `NODE_ENV` to determine if it his the not found boundary and should render the not found, as in the next build mode, we have `/_not-found` as a special route which has a empty parallel route, but in next dev mode so far it his the `parallel-default-route`. This could dependend on the `NODE_ENV` passing to next server but not necessarily.

### What

Fixes #53082
Fixes #53083 

### How

When server actions `not-found` hits, now we create a new loader tree based on the previous one, including `layout` and other components but not the children parallel routes

For production case, to make the rendering independent from the `NODE_ENV`, we're using original pathname to check if it's `/_not-found` to determine if it's production build 404 page

To support replace the loader tree of action, did a little refactor that passing down the loader tree from top level to `bodyResult`. Then we can change the loader tree itself before rendering, in short, we tweak it from original tree to one for not-found case, so server actions could render it properly
2023-07-24 21:00:53 +00:00
akfm
1494283a74
fix: Add Next-Url to http vary in consideration of intercept routes. (#52746)
### Why

We calculate the “next url” depending on the router state and the previous router state so that when you navigate to a route, the proxy matches with that header and returns you the intercepted route if matching

### What 
- Fixes #52745




Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-07-22 21:38:23 +00:00
JJ Kasper
1398de9977
Revert "Revert "Separate routing code from render servers (#52492)"" (#53029)
Reverts vercel/next.js#53016
2023-07-21 14:02:52 -07:00
JJ Kasper
ac62406ca0
Revert "Separate routing code from render servers (#52492)" (#53016)
Temporarily reverts these changes to allow patch release first. 

Reverts: https://github.com/vercel/next.js/pull/52149
Reverts: https://github.com/vercel/next.js/pull/52492
2023-07-21 10:52:19 -07:00
Jiachi Liu
1fefb4a8d2
Reland "Refine the not-found rendering process for app router" (#52985)
Reland #52790
Reverts vercel/next.js#52977

was failed due to failed job
[vercel/next.js/actions/runs/5616458194/job/15220295829](https://github.com/vercel/next.js/actions/runs/5616458194/job/15220295829)

Should be fine to resolve with
https://github.com/vercel/next.js/pull/52979 now

Fixes #52718
Fixes #52739

---------

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2023-07-21 10:09:30 -07:00
JJ Kasper
f57eecde5e
Separate routing code from render servers (#52492)
This breaks out routing handling from `next-server`, `next-dev-server`,
and `base-server` so that these are only handling the "render" work and
eventually these will be deleted completely in favor of the bundling
work being done.

The `router` process and separate `render` processes are still
maintained here although will be investigated further in follow-up to
see if we can reduce the need for these.

We are also changing the `require-cache` IPC to a single call instead of
call per entry to reduce overhead and also de-dupes handling for
starting the server between the standalone server and normal server.

To maintain support for existing turbopack route resolving this
implements the new route resolving in place of the existing
`route-resolver` until the new nextturbo API is fully landed.

After these initial changes we should continue to eliminate non-render
related code from `next-server`, `base-server`, and `next-dev-server`.
2023-07-20 22:13:42 -07:00
JJ Kasper
d7335b75d1
Revert "Refine the not-found rendering process for app router" (#52977)
Reverts vercel/next.js#52790

Reverting temporarily as this breaks turbopack's not found handling due
to the app tree being generated there not having the necessary parallel
routes in the `_not-found` entry x-ref:
0df8aac935/packages/next-swc/crates/next-core/src/app_structure.rs (L677-L681)

x-ref:
https://github.com/vercel/next.js/actions/runs/5616458194/job/15220295829
2023-07-20 20:39:05 -07:00
Jimmy Lai
55eebefbab
app-router: prefetching tweaks (#52949)
This PR tries to address some feedback around prefetching, like in #49607, where they were some warnings because we were over prefetching.

The tweaks in this PR:
- if there are no loading boundary below, we don't prefetch the full page anymore. I made that change a while ago but I think it wasn't the original intent from @sebmarkbage. Fixing that now. So now, we will prefetch the page content until the nearest loading boundary, only if there is any.
- there's now a queue for limiting the number of concurrent prefetches. This is to not ruin the bandwidth for complex pages. Thanks @alvarlagerlof for that one.
- also, if the prefetch is in the queue when navigating, it will get bumped.
- bonus: fixes a bug where we were wrongly stripping headers in dev for static pages

Test plan:
<img width="976" alt="CleanShot 2023-07-20 at 17 53 43@2x" src="https://github.com/vercel/next.js/assets/11064311/2ea34419-c002-4aea-94df-57576e3ecb2e">
In the screenshot you can see that:
- only 5 requests at a time are authorised
- when I clicked on 15, it got prioritised in the queue (did not cancel the rest)
- the prefetch only included the content until the loading boundary




Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-20 21:46:38 +00:00
Jiachi Liu
cb24c555a6
Refine the not-found rendering process for app router (#52790)
### What

This PR changes the flow of not-found rendering process. 

### Why

`not-found.js` was rendered in two ways before:
* 1 is SSR rendering the not-found as 404
* 2 is triggering the error on RSC rendering then the error will be
preserved in inline flight data, on the client it will recover the error
and trigger the proper error boundary.

The solution has been through a jounery:
No top-level not found boundary -> introduce metadata API -> then we
create a top level root not found boundary -> then we delete it due to
duplicated rendering of root layout -> now this

So the solution before this PR is still having a root not found boundary
wrapped in the `AppRouter`, it's being used in a lot of places including
HMR. As we discovered it's doing duplicated rendering of root layout,
then we removed it and it started failing with rendering `not-found` but
missing root layout. In this PR we redesign the process.

### How

Now the rendering architecture looks like:

* For normal root not-found and certain level of not-found boundary
they're still covered by `LayoutRouter`
* For other error renderings including not-found
* Fully remove the top level not-found boundary, when it renders with
404 error it goes to render the fallback page
* During rendering the fallback page it will check if it should just
renders a 404 error page or render nothing and let the error from inline
flight data to trigger the error boundary

pseudo code
```
try {
  render AppRouter > PageComponent
} catch (err) {
  create ErrorComponent by determine err
  render AppRouter > ErrorComponent
}
```

In this way if the error is thrown from top-level like the page itself
or even from metadata, we can still catch them and render the proper
error page based on the error type.

The problematic is the HMR: introduces a new development mode meta tag
`<meta name="next-error">` to indicate it's 404 so that we don't do
refresh. This reverts the change brougt in #51637 as it will also has
the duplicated rendering problem for root layout if it's included in the
top level not found boundary.

Also fixes the root layout missing issue:

Fixes #52718
Fixes #52739

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-07-20 14:12:06 -07:00
Shu Ding
a96a9b0791
Fix client reference manifest for interception routes (#52961)
We have the logic to group the client compiler's entry names to make sure we generate one single manifest file for the page. This is complicated and requires a special step to "group" the entry names because a page can depend on a bunch of files from everywhere.

And currently, the normalization of "entryName → groupName" doesn't cover interception routes' conventions (`(.)`, `(..)` and `(...)`). This PR fixes that.

Closes #52862, closes #52681, closes #52958.
2023-07-20 20:06:44 +00:00
Zack Tanner
4994a428ae
improve error DX on pages with RSC build errors (#52843)
### What?
- Visiting a page in the app router without a proper component export doesn't show the dev overlay, but logs errors to the console
- When it does show the error overlay (e.g. during an HMR event), the error message was sharing the module code itself rather than the component path, making it hard to debug

### Why?
`createComponentTree` can throw these errors before the AppRouter tree is mounted, leaving the errors uncaught by the dev overlay.

### How?
This wraps the server root in the `ReactDevOverlay` when in dev mode with a minimal "HMR" for when the server component is edited (to reload the page).

Closes NEXT-308
2023-07-20 00:32:57 +00:00
Wyatt Johnson
3e821ef189
Support basePath with edge runtime for Custom App Routes (#52910)
Fixes a bug where the edge runtime didn't support `basePath` with Custom App Routes.

- Fixes #49661
2023-07-19 23:54:34 +00:00
Janicklas Ralph
009b6a19d6
Setting up third-parties package (#51194)
This PR Introduces `next/third-parties`

- `@next/third-parties` is a new package in the Next.js monorepo. 
- The package contains collection of components that can be used to
efficiently load third party libraries into your Next.js application.
- This package uses [Third Party
Capital](https://github.com/GoogleChromeLabs/third-party-capital/) under
the hood to fetch the best loading recommendations.
- This PR mainly sets up the package to run a script at build time to
auto generate the components from [Third Party
Capital](https://github.com/GoogleChromeLabs/third-party-capital/)
config.

Packages are grouped by company, for eg:

`import { GoogleMapsEmbed } from '@next/third-parties/google'`


cc: @housseindjirdeh @kara 
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------
2023-07-18 10:52:39 -07:00
Facundo Giuliani
a26bac9604
Update default moduleResolution in tsconfig.json from node to bundler (#51957)
This updates our `moduleResolution` to `bundler` as this matches our heuristics much more closely so is more accurate. This shouldn't be a breaking change is it should be compatible with our previous default. 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-18 15:11:09 +00:00
Shu Ding
7e9627a390
Fix tracking of ContextModule (#52795)
When doing dynamic imports like `import(variable)`, Webpack _tries_ to statically analyze it and creates a regex like context module for it (which includes all possible modules). This `ContextModule` doesn't have a resource path so we need to use the identifier to track it.

Tested with @alexkirsz's repro here https://github.com/vercel/next.js/issues/50243#issuecomment-1628675346 and confirmed that it fixes the problem.

Closes #50243.
2023-07-17 17:41:04 +00:00
JJ Kasper
dc6c22c991
Fix runtime edge not-found handling (#52754)
This ensures we properly detect `not-found` as `runtime = 'edge'` and treat it as such instead of attempting to render it like normal. 

x-ref: https://github.com/vercel/next.js/issues/52648
2023-07-16 22:21:29 +00:00
Jiachi Liu
a28ae633e4
Support metadata exports for server components not-found (#52678)
### What?

Support metadata exports for `not-found.js` conventions

### Why?

We want to define metadata such as title or description basic properties for error pages, including 404 and 500 which referrs to `error.js` and `not-found.js` convention. See more requests in #45620 

Did some research around metadata support for not-found and error convention. It's possible to support in `not-found.js` when it's server components as currently metadata is only available but for `error.js` it has to be client components for now so it's hard to support it for now as it's a boundary.

### How?

We determine the convention if we're going to render is page or `not-found` boundary then we traverse the loader tree based on the convention type. One special case is for redirection the temporary metadata is not generated yet, we leave it as default now.

Fixes #52636
2023-07-14 22:33:47 +00:00
Jiachi Liu
d10f105b74
Fix icons metadata missing from layout (#52673)
### What

This was an issue introduced in #52416 when we check the images and icons property while merging with static file conventions. Where we should check if the properties are present but we only checked if they value is falsy. So when you're using `icons` with array value it breaks.

Now we properly check all the possible case of `metadata.icons` value, so then decide if we are using the static file convention or the icons property of defined metadata.

Also add few more tests cases to cover icons resolving.
2023-07-14 12:04:31 +00:00
Shu Ding
b957f52be3
Fix per-entry client reference manifest for grouped and named segments (#52664)
References for Client Components need to be aggregated to the page entry level, and emitted as files in the correct directory for the SSR server to read from. For normal routes (e.g. `app/foo/bar/page`), we can go through and collect all entries (layout, loading, error, ...) from the current and parent segments, to aggregate all necessary client references.

However, for routes with special conventions like `app/(group)/@named/foo/bar/page`, it needs to be normalized (remove the named slot and group segments) so it can be grouped together with `app/(group)/@named2/foo/bar/loading`.
2023-07-14 01:18:37 +00:00
Jiachi Liu
79227ee74a
Catch layout error in global-error (#52654)
When there's a runtime error showing in root layout (server components), it should be able to catch by `global-error`.

For server components, we caught it and gonna render the error fallback components (either not-found or error page), and the response status is `200`, and since we'll display error dev overlay in developmenet mode so we only render `global-error` for production.

So that you can catch more errors with `global-error` and maybe do potential error tracking on client side.

Follow up of #52573
Closes NEXT-1442

minor refactor: move `appUsingSizeAdjust` into `Metadata` component so that we can just tune the flag as prop
2023-07-14 00:43:40 +00:00
Shu Ding
88084e6b7a
Fix bundle path normalization for /index routes (#52650)
We have some special bundle path handling logic for `/index` routes in
`normalizePagePath`, which is missing in the new
`AppBundlePathNormalizer`. This already broke `/index/page.js` in dev in
the past, and now become noticeable in prod as well because of the
manifest change.


b98469c86b/packages/next/src/shared/lib/page-path/normalize-page-path.ts (L5-L14)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-13 17:36:43 +02:00
Jiachi Liu
9313c51bc4
Ensure root layout only render once per request (#52589)
Introduce a new way to search for `not-found` component that based on
the request pathname and current loader tree of that route. And we
search the proper not-found in the finall catch closure of app
rendering, so that we don't have to pass down the root layout to
app-router to create the extra error boundary.

This ensures the root layout doesn't have duplicated rendering for
normal requests

Fixes NEXT-1220
Fixes #49115
2023-07-13 17:34:31 +02:00
Jiachi Liu
76eec86a6b
Set sizes prop to any for svg icons (#52609)
For `link` tag's `sizes` property, the property is defined as:

> This attribute defines the sizes of the icons for visual media contained in the resource. It must be present only if the [rel](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#rel) contains a value of icon or a non-standard type such as Apple's apple-touch-icon. It may have the following values:
`any`, meaning that the icon can be scaled to any size as it is in a vector format, like image/svg+xml.

x-ref: https://html.spec.whatwg.org/#attr-link-sizes
x-ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link (`sizes` property definition section) 

Closes #52002
Closes NEXT-133
2023-07-13 00:33:27 +00:00
Wyatt Johnson
bb0fecc68f
Move App Pages rendering into bundle (#52290)
Transitions the App Pages renderer into the entrypoint bundle.

- Adjusts the static path detection to handle route module's with App Pages
- Fixes bug in font manifest loading on Edge
2023-07-12 18:28:06 +00:00
Shu Ding
b7e2627422
Avoid loading Next.js config again in render workers (#52587)
This PR ensures that both Webpack and the config won't be initiated in render workers. This is great for performance but also avoids potential issues (e.g. Next.js plugin with side effects). Instead, we pass a serialized config from the router worker to the render workers.

Closes #52366.
2023-07-12 11:21:05 +00:00
Jiachi Liu
b9760b2910
Support global-error for ssr fallback (#52573)
Previously `global-error` only caught the error on client side, this PR adds the support for catching the errors thrown during client components SSR or server components RSC rendering.

Closes #46572
Closes #50119
Closes #50723
2023-07-12 01:54:07 +00:00
Florentin / 珞辰
0648a109eb
add version to function config manifest (#52507)
Adds `version` to function config manifest as suggested in https://github.com/vercel/vercel/pull/10069#discussion_r1255021336
2023-07-10 20:28:59 +00:00
Shu Ding
0fe6e850fe
Fix tracking of client reference manifest (#52505)
The problem was introduced in #52450, that the client reference manifest isn't being tracked and included in the function.

Verified that this fixes the issue.
2023-07-10 14:27:08 +00:00
Tim Neutkens
73e2979cb8
Ensure useParams return array for catch-all routes (#52494)
## What?

Ensures `useParams` matches `params` passed to the page, also matches the docs.

Fixes #50856
Fixes NEXT-1419
2023-07-10 12:04:44 +00:00
Shu Ding
990c58c5ef
Split the client reference manifest file to be generated per-entry (#52450)
This PR changes client manifest generation process. Instead of one big
manifest file that contains client references for the entire app, we're
now generating one manifest file per entry which only covers client
components that can be reached in the module graph.
2023-07-10 09:48:03 +02:00
Jiachi Liu
85033e3add
Override file based images with social images property (#52416)
Metadata API should provide a way to override the filebased metadata
images. As usually for child routes, if there's new social images or
icons are provided, the ones from parent routes should be overridden /
skipped.

The `metadata` object export or `generateMetadata` should be able to do
that. Sometimes users still add other og info (besides images) to
metadata export (both object and `generateMetadata`).
I think we should check if they really have returned images property,
then decide to override.

- For the same level of routes:
- If there's no `openGraph.images` in the returned value, merge with
file based images
- If there's any `openGraph.images` in the returned value, ignore file
based ones

- For child level of routes:
Always override the parent level, ignoring parent level file based
images unless they use `generateMetadata` to merge from
`resolvingParentMetadata` value, then the parent level's file based ones
will present there


Closes NEXT-1418
2023-07-10 09:09:01 +02:00
Jiachi Liu
632a582807
Fix metadata layer webpack rule for server-only (#52403)
After we separating the metadata routes to a separate layer, we didn't apply the webpack alias rules properly to it as it's should still be treated as pure "server" side

This PR fixes the aliasing for that new metadata layer and make it working properly with "server-only"

Fixes #52390
2023-07-09 18:23:51 +00:00
Zack Tanner
412992ad6e
fix: prevent infinite dev refresh on nested parallel routes (#52362)
### What?
HMR causes infinite reloads for parallel routes when the corresponding page component is nested

### Why?
In 4900fa21b078fd1ec1adc5d570fcfb560be8aeb6, code was added to remove `/@children` from the page path (if present) but in 59b36349eb86427ac7b679ac62fa6628c9fc4886, `normalizeParallelKey` removes the @ prefix from children, so this doesn't seem to be catching the scenario it was intended to prevent

### How?
This updates the existing replace logic to consider `/children/page` rather than `/@children/page` -- it doesn't seem like `/@children` is a valid scenario given the `normalizeParallelKey` behavior

Fixes #52342 and addresses the concerns in https://github.com/vercel/next.js/pull/52061#issuecomment-1619145129
2023-07-07 07:41:21 +00:00
Steven
27217146cf
fix: metadatabase warning message (#52363)
This PR is a small grammar change to the warning message since "fallbacks to" is not grammatically correct.
2023-07-07 00:08:10 +00:00
Sebastian Markbåge
b095e9e980
Test Progressive Enhancement of Server Actions (#52062)
Adds a regression test for testing progressive enhancement of Server
Actions. Both when passed from a Server Component and when imported into
a Client Component.

#51723 landed a bit too early which broke this but it'll be fixed again
once React is upgraded.

Co-authored-by: Shu Ding <g@shud.in>
2023-07-06 18:21:59 +02:00
Jiachi Liu
927fc9e220
skip hot reload sync event for applying hmr updates (#52270)
### Issue

x-ref:
https://github.com/vercel/next.js/actions/runs/5469070005/jobs/9957658991?pr=52282#step:27:526
metadata tests are failing as flaky recently, then after digging into
it, noticed it as a hmr issue.

**Steps to repro with metadata test app**

The later (after the 1st one) visited page with client components
imports sometimes throw an full reload refresh warning
> Fast Refresh will perform a full reload when you edit a file that's
imported by modules
outside of the React rendering tree.

Turns out there's some unexpected hmr events when `"sync"` event is
triggered, and client tries to apply the updates but then failed. This
PR excludes the triggering by `"sync"` for RSC pages updates. `'sync'`
event with errors/warnings will still be handled and then `'built'`
event will be handled with hot reload updates

Possibly related to #40184
2023-07-05 17:06:11 -07:00
Shu Ding
8aa9a52c36
Fix tree shaking for image generation module (#51950)
### Issue

When the og module is a shared module being imported in both page and metadata image routes, it will be shared in the module graph. Especially in the edge runtime, since the `default` export is being used in the metadata image routes, then it can't be easily tree-shaked out.

### Solution

Separate the image route to a separate layer which won't share modules with the page, so that image route is always bundling separately and the `@vercel/og` module only stays inside in that layer, when import image metadata named exports (size / alt / etc..) it can be still tree shaked.

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-07-04 18:19:08 +00:00
Zack Tanner
0b87ba29c4
fix: infinite dev reloads when parallel route is treated a page entry (#52061)
### What?
When there's a parallel route adjacent to a tree that has no page
component, it's treated as an invalid entry in `handleAppPing` during
dev HMR, which causes an infinite refresh cycle

### Why?
In #51413, an update was made to `next-app-loader` to support layout
files in parallel routes. Part of this change updated the parallel
segment matching logic to mark the parallel page entry as `[
'@parallel', [ 'page$' ] ]` rather than `[ '@parallel', 'page$' ]`.

This resulted in `handleAppPing` looking for the corresponding page
entry at `client@app@/@parallel/page$/page` (note the `PAGE_SEGMENT`
marker) rather than `client@app@/@parallel/page`, causing the path to be
marked invalid on HMR pings, and triggering an endless fastRefresh.

### How?
A simple patch to fix this would fix this is to update `getEntryKey` to
replace any `PAGE_SEGMENT`'s that leak into the entry which I did in
59a972f53339cf6e444e3bf5be45bf115a24c31a.

The other option that's currently implemented here is to only insert
PAGE_SEGMENT as an array in the scenario where there isn't a page
adjacent to the parallel segment. This is to ensure that the
`parallelKey` is `children` rather than the `@parallel` slot when in
[`createSubtreePropsFromSegmentPath`](59a972f533/packages/next/src/build/webpack/loaders/next-app-loader.ts (L298)).
This seems to not cause any regressions with the issue being fixed in
51413, and also solves this case, but I'm just not 100% sure if this
might break another scenario that I'm not thinking of.

Closes NEXT-1337
Fixes #51951
2023-07-04 12:37:00 +02:00
Tim Neutkens
5d06b79e92
Support scroll: false for Link component for app router (#51869)
### What

Support `scroll={false}` for Link component in app router. This can be
used when you don't need to scroll back to top again when route url
changes. For instance hash query changes, if you want to keep the
scrolling as it is, you can use this option.

### How

Handling the `scroll` option in navigation reducer on client side.  

Fixes #50105
Fixes NEXT-1377

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-07-04 10:25:25 +02:00
Shu Ding
3a87f0005e
Change the Server Actions feature flag to be validated at compile time (#52147)
Currently we are validating the `experimental.serverActions` flag when creating the actual entries for Server Actions, this causes two problems. One is that syntax errors caught at compilation time are still shown, even if you don't have this flag enabled. Another problem is we still traverse the client graph to collect these action modules even if the flag isn't enabled.

This PR moves that check to be happening at compilation time, which addresses the two above but also brings the extra benefit of showing the exact span and module trace that errors:

<img width="974" alt="CleanShot 2023-07-03 at 20 26 34@2x" src="https://github.com/vercel/next.js/assets/3676859/1676b1f6-e205-4963-bce4-5b515a698e9c">
2023-07-03 20:29:57 +00:00
Jiachi Liu
10605a15c1
Renable flaky tests disabled before (#51680)
As we moved to new CI runner in `#50436`, try to re-enable few flaky tests we disabled before
2023-07-03 09:29:28 +00:00
Shu Ding
8eb9730607
Avoid unnecessary resolveExternal calls (#52053) 2023-07-03 10:34:46 +02:00
JJ Kasper
934a7da4d7
Ensure non-implicit unstable_cache tags are propagated (#52058)
This ensures we correctly pass up the non-implicit tags for
`unstable_cache` so that `revalidateTag` can be triggered for ISR paths
properly.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1687900021175649)
2023-06-30 15:27:16 -07:00
Jiachi Liu
4bfc1eaf54
Revert "Optimize inlined Flight data array format" (#52039)
Reverts vercel/next.js#52028

revert temporarily and will re-land in next round release
2023-06-30 16:12:31 +02:00
Shu Ding
0123a9d5c9
Optimize inlined Flight data array format (#52028)
When looking at [some sites](https://rsc-llm-on-the-edge.vercel.app/) with a large amount of chunks streamed, I noticed that the inlined Flight data array can be optimized quite a lot. Currently we do:

```js
self.__next_f.push([1,"d5:[\"4\",[\"$\",\"$a\",null,..."])
```

1. The `self.` isn't needed (except for the initial bootstrap tag) as React itself has `<script>$RC("B:f","S:f")</script>` too.
2. After the bootstrap script tag, all items are an array with `[1, flight_data]` and `flight_data` is always a string. We can just push only these strings.
3. We use `JSON.stringify(flight_payload)` to inline the payload where the payload itself is a string with a lot of double quotes (`"`), this results in a huge amount of backslashes (`\`). Here we can instead replace it to use a pair of single quotes on the outside and un-escape the double quotes inside.

Here's a side-by-side comparison of a small page:

<img width="1710" alt="CleanShot 2023-06-30 at 11 41 02@2x" src="https://github.com/vercel/next.js/assets/3676859/398356ec-91d5-435c-892d-16fb996029e8">

For a real production page I saw the HTML payload reduced by 11,031 bytes, a 3% improvement.

Note that all the tests are not considering gzip here, so the actual traffic impact will be smaller.
2023-06-30 13:27:38 +00:00
Jiachi Liu
54a963b666
Update displayed error message for rsc case (#52004)
We show the "Application error: a client-side exception has occurred (see the browser console for more information)" error incorrectly when a server-side error occurs (a digest is present) when we should be showing an error saying it is in fact a server side error and should check the logs there. This change will make the error message more accurate for users to look up

Fixes NEXT-1263
2023-06-30 11:31:19 +00:00