Commit graph

6068 commits

Author SHA1 Message Date
Jiachi Liu
6b578f08d9
Mark dynamic as client component (#38574)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-07-13 09:27:09 +02:00
Shu Ding
d403218ce0
Fix independent CSSModule missing from flight manifest (#38575)
In certain cases, mini-css-extractor will create independent `CSSModule` to the module graph, which doesn't have a user request or resource. Hence we can't match them in the flight manifest plugin like before. This PR adds a work around to use `mod.type` and `mod._identifier` to get such CSS assets.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-13 05:00:56 +00:00
Jiachi Liu
b251e552c6
Handle dev fouc for layout styling (#38557)
* Handle dev fouc for layout styling

* refactor

* fix renderOpts.dev

* dedupe css loading

* keep css module id in dev
2022-07-13 01:43:44 +02:00
Shu Ding
70a53e0789
Optimize Edge SSR bundle size (#38570)
Both `Buffer` and `node-html-parser` are not necessary to be introduced to the Edge SSR bundle. This makes the bundle size 25% smaller.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-12 23:39:18 +00:00
Shu Ding
f0d56190f7
Fix injecting CSS link tags before page content (#38559)
* inject the link tags before page content in layout router

* fix flight handling during client navigation

* fix buffering

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-07-12 22:54:42 +02:00
Tim Neutkens
81b554f3c1
Rename todos (#38560)
Renames todos to split them / make it easier to find what has to be done for the new router.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-12 16:32:27 +00:00
Gal Schlezinger
62eb16b603
Upgrade edge-runtime + make EdgeRuntime value overridable with an env var on compilation (#38331)
This PR introduces an environment variable that allows to modify the `EdgeRuntime` value on compilation time.
This is done to allow cloud providers like Vercel to have a different value, and enable user code and 3rd party libraries to have different code paths depending on the Edge Functions provider.

## Related

- Related to #30739

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-07-12 15:18:59 +00:00
Tim Neutkens
114e151c23 v12.2.3-canary.2 2022-07-12 14:46:07 +02:00
Tim Neutkens
cd5709825c
Handle development error when Server Component throws (#38550)
Handles the case where an error is introduced which causes a Fast Refresh and then it's fixed.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-12 12:44:53 +00:00
Shu Ding
c2b40d0773
CSS modules support improvements for Server Components (#38536)
Improve CSS modules support in server components.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-07-12 09:42:46 +00:00
Donny/강동윤
9342a6ccc7
feat(next-swc/auto-cjs): Detect __esModule (#38181)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

---

 - Closes #38117
2022-07-12 03:17:09 +00:00
JJ Kasper
883a52ede9
v12.2.3-canary.1 2022-07-11 18:12:44 -05:00
Balázs Orbán
e7b6b1939d
fix: don't use optional chaining in ESLint rule (#38534)
Fixes #38530

Should we consider adding a build-step to lint rules to be able to use TS/modern JS?

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-11 22:59:33 +00:00
OJ Kwon
68047112d6
refactor(next/swc): disable default features for crash report (#38531)
As we have disabled crash reporter for now, this PR removes feature from `default` to not to include it in `next-swc` as well. Feature itself remains so we can adjust it later by enabling it depends on the progress.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-07-11 21:29:50 +00:00
Sanjaiyan Parthipan
8ee05b749b
Update some dependencies' versions :) (#38427)
Hi,

I have updated some version of packages. 

- @swc/helper
- json5
- terser
- postcss
- nanoid
- use-sync-external-store (ReactJs pollyfill)
- microbundle

Updated version of #38328 

_Extremely sorry if I made any mistakes :(_

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-07-11 20:32:49 +00:00
OJ Kwon
0036a3d136
fix(next/build): correct payload for plugin telemetry (#38468) 2022-07-11 12:39:02 -05:00
Thiago Morales
645f70128f
Pass missing incrementalCacheHandlerPath to IncrementalCache instance (#38433)
# Description
Hi guys! First all, thanks for provide a way to use some custom external cache resource for ISR feature. _(done here: https://github.com/vercel/next.js/pull/37258 and https://github.com/vercel/next.js/pull/37326)_

I managed to get it working by creating my custom external cache resource _(using redis)_ that implements the new `CacheHandler`. _(overriding my own `get` and `set` methods and using the FileSystemCache as fallback as well)_  

I'm planning to release some kind of plugin to encapsulate and parse the client's `next.config.js` and bring an initial support for redis using this new Next.js feature.

So, I really don't know if this was intentional, but I noticed that the new `incrementalCacheHandlerPath` prop wasn't passed to the `IncrementalCache` instance in `base-server`.

This PR just connects the wires for this feature, and also provide the default value (`undefined`) to the relative experimental prop config. _(to avoid the warnings as shown below)_

<img width="858" alt="Screen Shot 2022-07-07 at 19 37 46" src="https://user-images.githubusercontent.com/4661217/177882897-831ade73-26ba-493a-b0cf-3de62cfd708f.png">
2022-07-11 16:53:17 +00:00
Jiachi Liu
409d37615b
Enable css import in rsc server side (#38418)
* Enable css in server components

* inject server css into flight

* refactor and fix test

* fix lint

* resolve css from module deps

* fix dev & prod inconsistentce, collect client css

* simplify

* dedupe duplicated css chunks

* remove ssr link injection and css flight

Co-authored-by: Shu Ding <g@shud.in>
2022-07-11 17:23:21 +02:00
Donny/강동윤
f694e6c42f
chore(deps): Update swc (#38347)
This PR updates swc to fa66ee86e5
2022-07-11 15:10:57 +00:00
Tim Neutkens
0887d283e1 v12.2.3-canary.0 2022-07-11 14:35:12 +02:00
Tim Neutkens
b014343259
Handle dynamic routes / catchall routes in on-demand-entries (#38512)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-07-11 14:34:10 +02:00
Tim Neutkens
419765affe
Add refreshing of Server Components (#38508)
* Add todo

* Reload page when server component changes

* Implement router.reload() that refreshes full tree
2022-07-11 14:02:46 +02:00
stefanprobst
dc3bd761b4
fix: fix bundle-analyzer plugin types (#38255)
* chore: fix bundle-analyzer types

* Add test for bundle analyzer type

* fix lint

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-07-10 14:13:24 -05:00
Tim Neutkens
2d9875983c
Handle on-demand-entries and error overlay for server components (#38480) 2022-07-10 19:18:48 +02:00
OJ Kwon
d920a17162
build(ci): enable rustls as default (#38471)
* build(ci): enable rustls as default

* test build
2022-07-09 16:24:38 -05:00
Jiachi Liu
1cd37793a4
Fix app dir page detection (#38475)
## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-07-09 14:58:16 +00:00
Tim Neutkens
8282c819fd
Remove dynamic params from query in new router (#38466)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-07-09 14:33:51 +02:00
Tim Neutkens
689626c6a4 v12.2.2 2022-07-09 13:18:55 +02:00
Tim Neutkens
4e21a240a5 v12.2.2-canary.0 2022-07-09 11:44:49 +02:00
OJ Kwon
05759e09bf
fix(next/build): disable next-swc crash reporting temporarily (#38472)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2022-07-09 10:32:10 +02:00
Steven
2fa96822e7
Fix warning next/future/image semicolon (#38454)
## Bug

- [x] Fixes #38404
- [x] Fixes #38431 
- [x] Integration tests updated
2022-07-08 16:24:03 +00:00
Tim Neutkens
050d13e0c8
Make catchall parameters consistent with existing router (#38456)
Ensures catchall parameters are passed as an array to `params` instead of as a string.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-08 14:47:21 +00:00
Tim Neutkens
a4668f29b6
Add handling for back/forward (popstate) between old and new router (#38453)
Handles the case where you navigate between routes in `pages` and `app`.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-08 13:54:52 +00:00
Tim Neutkens
b421fa27fb
Add support for optional catchall with new router (#38444)
Follow-up of #38439.

Found a small issue with booting `next start` that is now resolved.
Also added optional catchall routes support.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-08 10:29:41 +00:00
Jiachi Liu
3da3df2359
Fix client entry point prefix (#38445)
client prefix should depend on the pages type
2022-07-08 10:08:37 +00:00
Tim Neutkens
41bedf67db
Add support for catchall with new router (#38439)
Adds support for `[...slug]` dynamic segments.

I found there's an inconsistency in query/params providing and added a quick fix for it now. Will update the handling in a follow-up PR to ensure it's consistently providing dynamic params outside of `query`.

Follow-up of #37551 and #38415.


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-08 08:47:59 +00:00
Balázs Orbán
6faf84ff3b
Update README.md (#38371)
* Update README.md

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-07-07 23:00:34 -05:00
JJ Kasper
ef90539968
v12.2.1 2022-07-07 18:01:56 -05:00
JJ Kasper
e9ffd9bec4
v12.2.1-canary.5 2022-07-07 15:49:30 -05:00
JJ Kasper
2989c8aeb9
Add app-path-routes manifest (#38420)
This outputs a separate manifest for leveraging during deploy to handle the new app outputs. Also ensures dynamic routes from `app` our output in the `routes-manifest` correctly along with fixing the `react-dom` import. 

x-ref: https://github.com/vercel/next.js/pull/37551
2022-07-07 20:42:44 +00:00
Tim Neutkens
aa0ba3c30a
Ensure server components entries are not part of the pages buildmanifest (#38416)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-07-07 22:17:17 +02:00
OJ Kwon
46dde0dd4a
feat(next/swc): setup native next-swc crash reporter with platform supports (#38221)
This is second attempt to https://github.com/vercel/next.js/pull/38076 . Most of changes are identical to previous PR. Main difference is introducing features `native-tls` and `rustls` for the sentry's downstream feature. Few platform targets we build (mostly where we cross compiles) fails to find native openssl for the specified target. For those, we falls back to rustls instead. The only exception is aarch64_windows, neither openssl nor rustls can be compiled straightforwardly, For those platform we bail out and do not init sentry at all. There are nearly 0 users on aarch64_windows anyway. We could try to located target's openssl binary, but the effort required seems not worth enough. 

Also PR changed `server_name` property to not to include real device hostname to avoid possible PII concerns.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-07 17:37:50 +00:00
Tim Neutkens
0299f14a7e
Add param names into the tree (#38415)
- Remove cache value that was incorrectly nested deeper
- Remove extra useEffect (already applied during hydration based on the `useReducer` input)
- Add dynamic parameter name into the tree

Follow-up to #37551, cleans up some code and prepares for catch-all and optional catch-all routes.
2022-07-07 13:52:07 +00:00
JJ Kasper
3411794607
v12.2.1-canary.4 2022-07-06 16:33:16 -05:00
Tim Neutkens
f113141389
Implement new client-side router (#37551)
## Client-side router for `app` directory

This PR implements the new router that leverages React 18 concurrent features like Suspense and startTransition.
It also integrates with React Server Components and builds on top of it to allow server-centric routing that only renders the part of the page that has to change.

It's one of the pieces of the implementation of https://nextjs.org/blog/layouts-rfc.

## Details

I'm going to document the differences with the current router here (will be reworked for the upgrade guide)

### Client-side cache

In the current router we have an in-memory cache for getStaticProps data so that if you prefetch and then navigate to a route that has been prefetched it'll be near-instant. For getServerSideProps the behavior is different, any navigation to a page with getServerSideProps fetches the data again.

In the new model the cache is a fundamental piece, it's more granular than at the page level and is set up to ensure consistency across concurrent renders. It can also be invalidated at any level.

#### Push/Replace (also applies to next/link)

The new router still has a `router.push` / `router.replace` method.

There are a few differences in how it works though:

- It only takes `href` as an argument, historically you had to provide `href` (the page path) and `as` (the actual url path) to do dynamic routing. In later versions of Next.js this is no longer required and in the majority of cases `as` was no longer needed. In the new router there's no way to reason about `href` vs `as` because there is no notion of "pages" in the browser.
- Both methods now use `startTransition`, you can wrap these in your own `startTransition` to get `isPending`
- The push/replace support concurrent rendering. When a render is bailed by clicking a different link to navigate to a completely different page that still works and doesn't cause race conditions.
- Support for optimistic loading states when navigating

##### Hard/Soft push/replace

Because of the client-side cache being reworked this now allows us to cover two cases: hard push and soft push.

The main difference between the two is if the cache is reused while navigating. The default for `next/link` is a `hard` push which means that the part of the cache affected by the navigation will be invalidated, e.g. if you already navigated to `/dashboard` and you `router.push('/dashboard')` again it'll get the latest version. This is similar to the existing `getServerSideProps` handling.

In case of a soft push (API to be defined but for testing added `router.softPush('/')`) it'll reuse the existing cache and not invalidate parts that are already filled in. In practice this means it's more like the `getStaticProps` client-side navigation because it does not fetch on navigation except if a part of the page is missing.

#### Back/Forward navigation

Back and Forward navigation ([popstate](https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event)) are always handled as a soft navigation, meaning that the cache is reused, this ensures back/forward navigation is near-instant when it's in the client-side cache. This will also allow back/forward navigation to be a high priority update instead of a transition as it is based on user interaction. Note: in this PR it still uses `startTransition` as there's no way to handle the high priority update suspending which happens in case of missing data in the cache. We're working with the React team on a solution for this particular case.

### Layouts

Note: this section assumes you've read [The layouts RFC](https://nextjs.org/blog/layouts-rfc) and [React Server Components RFC](https://reactjs.org/blog/2020/12/21/data-fetching-with-react-server-components.html)

React Server Components rendering leverages the Flight streaming mechanism in React 18, this allows sending a serializable representation of the rendered React tree on the server to the browser, the client-side React can use this serialized representation to render components client-side without the JavaScript being sent to the browser. This is one of the building blocks of Server Components. This allows a bunch of interesting features but for now I'll keep it to how it affects layouts.

When you have a `app/dashboard/layout.js` and `app/dashboard/page.js` the page will render as children of the layout, when you add another page like `app/dashboard/integrations/page.js` that page falls under the dashboard layout as well. When client-side navigating the new router automatically figures out if the page you're navigating to can be a smaller render than the whole page, in this case `app/dashboard/page.js` and `app/dashboard/integrations/page.js` share the `app/dashboard/layout.js` so instead of rendering the whole page we render below the layout component, this means the layout itself does not get re-rendered, the layout's `getServerSideProps` would not be called, and the Flight response would only hold the result of `app/dashboard/integrations/page.js`, effectively giving you the smallest patch for the UI.

---

Note: the commits in this PR were mostly work in progress to ensure it wasn't lost along the way. The implementation was reworked a bunch of times to where it is now.

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-07-06 21:16:47 +00:00
Damien Simonin Feugas
6e2c3821cf
feat: build edge functions with node.js modules and fail at runtime (#38234)
## What's in there?

The Edge runtime [does not support Node.js modules](https://edge-runtime.vercel.app/features/available-apis#unsupported-apis).
When building Next.js application, we currently fail the build when detecting node.js module imported from middleware.

This is an blocker for using code that is conditionally loading node.js modules (based on platform/env detection), as @cramforce reported.

This PR implements a new strategy where:
- we can build such middleware/Edge API route code **with a warning**
- we fail at run time, with graceful errors in dev (console & react-dev-overlay error)
- we fail at run time, with console errors in production

## How to test?

All cases are covered with integration tests.
To try them live, create a simple app with a page, a `middleware.js` file and a `pages/api/route.js`file.
Here are iconic examples:

### node.js modules
```js
// middleware.js
import { NextResponse } from 'next/server'
// static
import { basename } from 'path'

export default async function middleware() {
  // dynamic
  const { basename } = await import('path')
  basename()
  return NextResponse.next()
}

export const config = { matcher: '/' }
```
```js
// pags/api/route.js
// static
import { isAbsolute } from 'path'

export default async function handle() {
  // dynamic
  const { isAbsolute } = await import('path')
  return Response.json({ useNodeModule: isAbsolute('/test') })
}

export const config = { runtime: 'experimental-edge' }
```

Desired error (+ source code highlight in dev):

> The edge runtime does not support Node.js 'path' module
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

Desired warning at build time:

> A Node.js module is loaded ('path' at line 2) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

- [x]  in dev middleware, static, shows desired error on stderr
- [x]  in dev route, static, shows desired error on stderr
- [x]  in dev middleware, dynamic, shows desired error on stderr
- [x]  in dev route, dynamic, shows desired error on stderr
- [x]  in dev middleware, static, shows desired error on react error overlay
- [x]  in dev route, static, shows desired error on react error overlay
- [x]  in dev middleware, dynamic, shows desired error on react error overlay
- [x]  in dev route, dynamic, shows desired error on react error overlay
- [x]  builds middleware successfully, shows build warning, shows desired error on stderr on call
- [x]  builds route successfully, shows build warning, shows desired error on stderr on call

### 3rd party modules not found

```js
// middleware.js
import { NextResponse } from 'next/server'
// static
import Unknown from 'unknown'

export default async function middleware() {
  // dynamic
  const Unknown = await import('unknown')
  new Unknown()
  return NextResponse.next()
}
```
export const config = { matcher: '/' }
```
```js
// pags/api/route.js
// static
import Unknown from 'unknown'

export default async function handle() {
  // dynamic
  const Unknown = await import('unknown')
  return Response.json({ use3rdPartyModule: Unknown() })
}

export const config = { runtime: 'experimental-edge' }
```

Desired error (+ source code highlight in dev):

> Module not found: Can't resolve 'does-not-exist'
Learn More: https://nextjs.org/docs/messages/module-not-found

- [x]  in dev middleware, static, shows desired error on stderr
- [x]  in dev route, static, shows desired error on stderr
- [x]  in dev middleware, dynamic, shows desired error on stderr
- [x]  in dev route, dynamic, shows desired error on stderr
- [x]  in dev middleware, static, shows desired error on react error overlay
- [x]  in dev route, static, shows desired error on react error overlay
- [x]  in dev middleware, dynamic, shows desired error on react error overlay
- [x]  in dev route, dynamic, shows desired error on react error overlay
- [x]  fails to build middleware, with desired error on stderr
- [x]  fails to build route, with desired error on stderr

### unused node.js modules
```js
// middleware.js
import { NextResponse } from 'next/server'

export default async function middleware() {
  if (process.exit) {
    const { basename } = await import('path')
    basename()
  }
  return NextResponse.next()
}
```
```js
// pags/api/route.js
export default async function handle() {
  if (process.exit) {
    const { basename } = await import('path')
    basename()
  }
  return Response.json({ useNodeModule: false })
}

export const config = { runtime: 'experimental-edge' }
```

Desired warning at build time:

> A Node.js module is loaded ('path' at line 2) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

- [x]  invoke middleware in dev with no error
- [x]  invoke route in dev with no error
- [x]  builds successfully, shows build warning, invoke middleware with no error
- [x]  builds successfully, shows build warning, invoke api-route with no error

## Notes to reviewers

The strategy to implement this feature is to leverages webpack [externals](https://webpack.js.org/configuration/externals/#externals) and run a global `__unsupported_module()` function when using a node.js module from edge function's code.
For the record, I tried using [webpack resolve.fallback](https://webpack.js.org/configuration/resolve/#resolvefallback) and [Webpack.IgnorePlugin](https://webpack.js.org/plugins/ignore-plugin/) but they do not allow throwing proper errors at runtime that would contain the loaded module name for reporting.

`__unsupported_module()` is defined in `EdgeRuntime`, and returns a proxy that's throw on use (whether it's property access, function call, new operator... synchronous & promise-based styles).

However there's an issue with error reporting: webpack does not includes the import lines in the generated sourcemaps, preventing from displaying useful errors.
I extended our middleware-plugin to supplement the sourcemaps (when analyzing edge function code, it saves which module is imported from which file, together with line/column/source)

The react-dev-overlay was adapted to look for this additional information when the caught error relates to modules, instead of looking at sourcemaps.

I removed the previous mechanism (built by @nkzawa ) which caught webpack errors at built time to change the displayed error message (files `next/build/index.js`, `next/build/utils.ts` and `wellknown-errors-plugin`)
2022-07-06 20:54:44 +00:00
okmttdhr, okp
69f8024aa1
Call Error.getInitialProps for the top level error (#21240)
* fix: Call Error.getInitialProps to pass `err`

* test: Call Error.getInitialPropsfoe the top level error

* test: Update build output limit

* test: Add tests for top level error

* Revert "test: Call Error.getInitialPropsfoe the top level error"

This reverts commit 81fa0c38c704ae6feb79a65eba316362bbebc939.

* test: Fix failing test
2022-07-06 13:44:15 -05:00
Gal Schlezinger
708688dd26
[edge] enable edge compiler source maps by default (#38365)
since we no longer have a single compiler for browser & edge, we can enable
source map generation by default for all edge functions. This would make it
much easier to debug and understand what's happening when deploying to prod
as the log statements will show us the actual code location instead of post
bundling and minified location.

This also removes the experimental flag as it's not needed anymore.
2022-07-06 18:17:57 +00:00
Jiachi Liu
a16d8dd4cd
Filter proper chunks from chunk group for client components (#38379)
Client components might result in a page chunk or a standalone splitted chunk marked in flight manifest, this PR filters out the page chunk for standalone chunk so that while loading a client chunk (like for `next/link`) it won't load the page chunk to break the hydration. `chunk.ids` is not enough for getting required chunks, so we get the chunks from chunk group then filter the required ones.

tests: Re-enable few previous rsc tests
chore: refactor few webpack api usage

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-07-06 17:35:20 +00:00
Maia Teegarden
f2b8a6b60f
Enable swc minifier in create next apps (#38215)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-06 17:14:01 +00:00
stefanprobst
6b4b037396
chore: shorten image blur svg placholder (#38157)
trying to shorten the svg blur placeholder on `next/future/image`:

- is the `xlink` namespace needed?
- are self-closing tags allowed?

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-06 15:34:24 +00:00
Anders Søgaard
e5be344932
Correctly check if width is lte 0 in Image Optimization API (#38226)
This PR corrects a mistake where a negative number could pass, as a number greater than 0.

This is due to negative numbers being a truthy value in JS.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-06 14:09:29 +00:00
Gal Schlezinger
56e760a203
[build] validate the exported config values (#38370)
Right now if people will accidentally export a typo like `runtime: 'experimental-egde'` we will fail silently.
This commit ensures we will throw and fail loudly when such typos occur.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-07-06 11:06:57 +00:00
Shu Ding
085085ebf1
Fix global CSS file imports (#38339)
Follow up of #38310 and #38329, this PR adjusts the loader rules to allow importing global CSS files from the app dir.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-05 23:07:13 +00:00
Wyatt Johnson
329f6cb9ac
Handle Client Rewrites Correctly (#38340)
When an API route is detected for the `getRouteInfo` method (a route with a `/api` prefix), we should redirect the user to the original destination instead of the rewritten destination. This makes the behaviour consistent with how rewrites have been documented thus far.

The reproduction described in #37783 now causes an invariant violation error (for redirecting to the same URL), but this is instead related to the fact that the router (when rehydrated) attempts to redirect the user again to the correct destination. This should be corrected either in this PR or in a future one that addresses the hydration behaviour directly.

## Bug

- Related to #37783
- Related to #37949

## Example

With the following `next.config.js`:

```js
/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  async rewrites() {
    return {
      beforeFiles: [
        {
          source: '/:path(.*)',
          has: [{ type: 'query', key: 'json', value: 'true' }],
          destination: '/api/json?from=:path',
        },
      ],
    }
  },
}

module.exports = nextConfig
```

The following link:

```jsx
<Link href="/not/real?json=true">
  <a>Take me to JSON</a>
</Link>
```

When clicked, will navigate the user to `/not/real?json=true` and have it's contents served by `/api/json` and not simply redirected to `/api/json` which is incorrect.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-07-05 22:44:38 +00:00
Hannes Bornö
469c5030ba
Display stack trace when error occurs in API route (#38289)
## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-07-05 21:33:58 +00:00
JJ Kasper
f716f7047c
Honor NEXT_MANUAL_SIG_HANDLE flag in standalone mode (#38346) 2022-07-05 16:06:15 -05:00
JJ Kasper
764f7d42d4
v12.2.1-canary.3 2022-07-05 12:09:24 -05:00
Shu Ding
2dc1359149
Fix CSS modules imported from client components in app dir with next build (#38329)
Continue the work in #38310, this PR includes CSS files as chunks in the manifest for each client component, and then make sure the flight client loads the CSS files correctly.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-05 16:37:50 +00:00
Gal Schlezinger
42ee877e71
[edge] favor browser exports for edge compiler (#38319)
this is a regression from the previous implementation where Next.js compiled Middleware using
the client compiler. We used to favor the browser exports over the `module` and `main`,
which allowed packages like `debug` to work without any changes on Edge Functions. This is
no longer the case, and this commit fixes that.

Side note: I believe that in the future we will also have a different key to symbolize edge
deployments. Maybe it will be `winter` to refer to WinterCG, but only time will tell!

Another side note: we need to add support for import maps for advanced use cases.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-07-05 09:16:14 +00:00
Shu Ding
7ced791d1e
Fix CSS modules imported from client components in app dir (#38310)
* css modules support

* add test case

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-07-05 00:35:29 +02:00
JJ Kasper
9d22da476b
Ensure trailing slash is handled correctly with middleware (#38282)
* Ensure trailing slash is handled correctly with middleware

* update source modifying

* undo extra change
2022-07-04 09:31:07 -05:00
Gal Schlezinger
672736c408
[edge] Make runtime addressable in compile time (#38288)
this commit allows to use EdgeRuntime as a dead code eliminator identifier:

```ts
if (typeof EdgeRuntime !== "undefined") {
  console.log("will be stripped away");
} else {
  console.log("will be kept in the bundle");
}
```

which means we're replacing `EdgeRuntime` with a literal

## Related

- Fixes #30739

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-04 12:54:07 +00:00
Jiachi Liu
d6090178fe
Fix: convert head instances to array (#38252)
* fix: convert head instances to array

* fix test
2022-07-01 20:59:04 -05:00
JJ Kasper
274980f057
v12.2.1-canary.2 2022-07-01 19:49:58 -05:00
Jiachi Liu
bfaffbdd3f
Alias react and react-dom by default (#38245)
Previously we use custom webpack alias for specific react versions for non server side node runtime aliases. This PR alias the entire folders of `react/` and `react-dom/` so that no more alias in next.config is required but only the nodejs require hook.

* Alias `react` and `react-dom` by default
* Use `react@experimental` to run server components integration test
* Drop with-react-17 test util, add `__NEXT_REACT_CHANNEL` as an env var for testing and development to specify the react channel is 17 or new experimental version
2022-07-01 23:57:45 +00:00
JJ Kasper
a1504f4cf4
Ensure page.server.js matches correctly (#38236)
* Ensure app/page.server.js matches correctly

* update check
2022-07-01 12:15:27 -05:00
Richard B
157655700a
fix: declare NextBundleAnalyzer as a type (#38168)
* fix: declare NextBundleAnalyzer as a type

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-30 15:48:00 -05:00
OJ Kwon
2150d1aee6
feat(next/build): send next-swc plugins telemetry (#38116)
* Requires prerequisite PR https://github.com/vercel/next-telemetry/pull/84

This PR adds telemetry to send list of the experimental swc plugins from next.config.js. Implementation largely mimics existing plugins telemetry for next_package (https://github.com/vercel/next.js/blob/canary/packages/next/telemetry/events/plugins.ts), with small modification to read swc plugin package instead.

One notable difference is swc plugin telemetry can be sent without version. This is due to swc plugins can be specified with absolute path without any npm pkg resolutions.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-30 19:05:35 +00:00
Jiachi Liu
f21a9dd5cb
Fix pageProps is missing when route changes (#38178)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-30 18:13:07 +00:00
Michael Novotny
edd395a7d3
Adds tests to ensure eslint-plugin-next's available rules are properly exported and recommended rules are correctly defined. (#38183)
* Adds tests to ensure `eslint-plugin-next`'s available rules are properly exported and recommended rules are defined correctly.

* Condenses imports.

* Sets default recommended value.

* replace Object.hasOwn for node 14

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-30 11:31:33 -05:00
Long Zheng
ab314605af
Check for performance.getEntriesByName before calling (#38186)
* Check for performance. getEntriesByName

* Refactor check

Co-Authored-By: Sukka <github@skk.moe>

Co-authored-by: Sukka <github@skk.moe>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-30 11:06:53 -05:00
Jiachi Liu
5e2ad29309
Migrate rsc tests to app dir tests (#38158)
### Tests 
* keep node & edge for streaming
* separate rsc tests from streaming tests
* move rsc tests to app-dir, disable the broken ones for now
2022-06-29 23:12:57 +00:00
JJ Kasper
8a5c59b7f1
Ensure @swc/helpers do not rely on hoisting (#38174)
This ensures we properly alias and internalize `@swc/helpers` so that we don't rely on package managers hoisting this dependency for the build to work properly. This also disables the external helpers with `jest` as this can also require hoisting to work and doesn't provide as much of an optimization. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: [slack thread](https://vercel.slack.com/archives/C0289CGVAR2/p1656437059151439)
2022-06-29 22:47:44 +00:00
OJ Kwon
66b83f4506
fix(next/swc): set cache dir explicitly (#38175)
This PR amends behavior of swc's cache by setting it explicitly under `distDir` from next.js config.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-29 21:59:52 +00:00
JJ Kasper
c64af8aa34
v12.2.1-canary.1 2022-06-29 15:06:44 -05:00
JJ Kasper
0b762433f5
Revert "feat(next/swc): setup native next-swc crash reporter" (#38170)
Revert "feat(next/swc): setup native next-swc crash reporter (#38076)"

This reverts commit 42e3365575.
2022-06-29 14:51:12 -05:00
Shu Ding
da84abc588
Fix chunk path resolution (#38162)
The `chunkFilenameMap` should take priority over the webpack built-in one here.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-29 19:28:48 +00:00
JJ Kasper
70c0b20885
v12.2.1-canary.0 2022-06-29 13:57:24 -05:00
Sukka
55769e2cac
fix(#38106): use swc client config to pre-compile shared lib (#38137)
## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes #38106.

Currently, the `shared/lib` directory (**which will also be shipped to legacy browsers**) is precompiled under `swcServerOptions`, which targets Node.js 12 and is way too modern:

- The public class field syntax is only supported since Chrome 72, Firefox 69, Edge 79, and Safari 14.1.
- Webpack currently doesn't support the public class field syntax as well (which causes the issue #38106)
- `async/await` syntax is also supported in Node.js 12 but not in the legacy browsers.

The PR fixes the issue by pre-compiling the `shared/lib` directory using `swcClientOptions` (which targets the ES5).

Note:

- The only way to validate the fix is to run an integration test case on a legacy browser.
- The output size is increased by a little. But the size impact can be minimized by enabling `@swc/helpers` (which I will bring up in the next PR)
2022-06-29 16:34:03 +00:00
Dom Sip
82e63e3d74
docs(readme.md): remove broken 404 links (#38104) 2022-06-29 13:17:58 +02:00
Steven
4df0778ce8
Fix error when next/future/image is missing width or height (#38132)
This PR fixes the case when `next/future/image` is missing the width or height props.

It also fixes a case when `100%` or `100vh` were incorrectly parsed as `100` pixels.
2022-06-29 10:43:59 +00:00
JJ Kasper
876d4d1214
Add default experimental values (#38135)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-29 12:21:04 +02:00
JJ Kasper
fcccaafa33
Fix failing to set initial ISR cache item in new folder (#38136)
This ensures we create any nested folders necessary when setting initial ISR cache entries with the filesystem cache. Also adds a regression test for this. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/38130
2022-06-29 09:45:15 +00:00
Michael Novotny
c83f94cf8b
Readds missing @next/next/no-assign-module-variable ESLint rule. (#38134)
Readds `@next/next/no-assign-module-variable` ESLint rule that was inadvertently removed in #34335 during the resolution of many merge conflicts.

This PR will get us back to a good / working state. I'll see if I can add a test to ensure all rule are accounted for in a separate PR.

Fixes #34335.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-29 02:54:47 +00:00
Shu Ding
0ecbcc6d54
Fix unnecessary flight render passes (#38133)
Currently `renderToReadableStream` will be called whenever the component is re-rendered, but the result should actually be cached (per request).

Thanks to @sebmarkbage for pointing out.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-29 00:30:55 +00:00
OJ Kwon
42e3365575
feat(next/swc): setup native next-swc crash reporter (#38076)
This PR attempts to setup native crash reporter for `next-swc`. Currently, it uses sentry internally, but it is subject to change depending on the usecase & needs. In any case it won't be breaking changes since this is not transparent to the end users.

PR sets up basic, minimal setup to collect crash reports only at the moment. We may want to expand & collect more data in native next-swc, but it is not clear what we need to collect / and I believe most cases next.js's js context can collect those data via existing telemetry. Crash report is an exception native handler can perform much better by having it in native context directly. While this is sent to different endpoint than telemetry, it is considered as same opt-in configuration. If telemetry is disabled, crash reporter won't collect as well. 

The information collected by the reporter is minimally configured by sentry's sdk. These are the informations collected for example: 

- device arch / family / model
- os kernel version / name / version
- runtime (rust) version / channel
- sentry sdk
- panic backtrace
- next.js release version
- device host name

There's no per-system uuid configurations yet.

It may need some audit if we need to omit some data included in above, while most of them seems ok to me.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-28 23:49:21 +00:00
OJ Kwon
a3ffd1ce6e
fix(next/config): update default config for the experimental (#38123)
Minor fix to recent experimental configs. While the latest next.js includes support for those experimental features, currently it emits warnings like

```
You have defined experimental feature (swcPlugins) in next.config.js that does not exist in this version of Next.js
```

As validation checks the existence of default values even though config itself allows them to be optional. PR does not attempt to change validation logics, only amends it by having empty default values.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-28 21:20:29 +00:00
JJ Kasper
cb2ba0c75d
Fix invalid config warning for runtime config (#38122) 2022-06-28 15:54:45 -05:00
Steven
1feaac0398
Remove unused layoutRaw config (#38120)
Removes the `layoutRaw` experimental config which was forgotten in a previous PR #38006
2022-06-28 19:19:46 +00:00
JJ Kasper
632feb6b73
v12.2.0 2022-06-28 09:21:07 -05:00
JJ Kasper
ed35138edc
v12.1.7-canary.52 2022-06-28 08:35:37 -05:00
Kiko Beats
9cc1c3c576
Upgrade Edge Runtime (#38105) 2022-06-28 07:48:23 -05:00
JJ Kasper
3eb9caeb6a
v12.1.7-canary.51 2022-06-27 23:35:41 -05:00
JJ Kasper
d959d283fb
Ensure client cache keys match between prefetch and transition (#38089)
* Ensure client cache keys match between prefetch and transition

* handle some middleware cases

* lint-fix

* fix lint rename
2022-06-27 23:32:59 -05:00
JJ Kasper
a72e136c79
Ensure history navigation is correct after query update (#38086) 2022-06-27 21:08:08 -05:00
Steven
0cb1253638
Remove unnecessary <noscript> from next/future/image (#38080)
We don't need to include `<noscript>` for `next/future/image` since it uses native lazy loading instead of the `IntersectionObserver` (https://github.com/vercel/next.js/pull/37927).

The only case when we still need `<noscript>` is for `placeholder="blur"` because it requires client-side JS to switch the from blur image to final image on load.
2022-06-28 00:58:50 +00:00
JJ Kasper
52763de94a
v12.1.7-canary.50 2022-06-27 18:52:05 -05:00
JJ Kasper
58033c4a3c
Fix resolving dynamic routes when on returns a redirect (#38079)
* Fix resolving dynamic routes when on returns a redirect

* Update fix and add test case
2022-06-27 18:47:32 -05:00
Javi Velasco
ca621ced66
Add init to some NextResponse methods (#38071)
* Add `init` to some `NextResponse` methods

* Add NextResponse.redirect test and fix headers

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-27 18:39:00 -05:00
Ali Yusuf
d7e83704bf
fix(next): bind new stream functions with base incomingMessage object (#37806)
Closes: #37805

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-27 20:56:14 +00:00
JJ Kasper
7e3355dd9f
v12.1.7-canary.49 2022-06-27 15:12:26 -05:00
JJ Kasper
40cf3ce63a
Add error for renaming of unstable_revalidate (#38070)
* Add error for renaming of unstable_revalidate

* update test

* run test for dev too
2022-06-27 14:28:41 -05:00
JJ Kasper
e3fb62b6bf
Add invariant with debug information when failing to load static file (#38075) 2022-06-27 14:15:09 -05:00
Balázs Orbán
77f9a6a72f
feat(cli): report eslint-config-next version in next info (#38062)
* feat: report `eslint-config-next` version in `next info`

* update test
2022-06-27 14:04:47 -05:00
Kiko Beats
5819dd5540
Upgrade Edge Runtime (#38069)
This new version renamed `globalThis.Edge` into `globalThis.EdgeRuntime`.
2022-06-27 18:44:02 +00:00
Gal Schlezinger
da07c72460
[middleware] avoid fetching a chunk for api endpoints on middleware redirect (#37949)
avoid fetching a chunk for api endpoints on middleware redirect.
This still makes a request to the data endpoint, not sure if this is a good idea,
but a rewrite _can_ happen from that data request.

## Related

- Fixes #37944
- Fixes https://github.com/vercel/next.js/issues/37783



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-27 18:18:42 +00:00
Houssein Djirdeh
82dce6ce8e
[Script] Allow next/script to be placed in _document body (#37894)
Fixes https://github.com/vercel/next.js/issues/37741. Allows `next/script` to be placed inside of `_document` body in addition to `Head`.

## Bug

- [X] Related issues linked using `fixes #number`
- [X] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-27 17:56:53 +00:00
Steven
5ea3f6c4ab
Remove layout raw image experiment (#38006)
This PR removes experimental `layout="raw"` from `next/image` since it was moved to `next/future/image` in #37927
2022-06-27 15:11:15 +00:00
stefanprobst
42e214e508
chore: make experimental images options optional (#38030)
this makes all `experimental.images` options optional, so they can be toggled individually.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-27 01:23:39 +00:00
Jiachi Liu
a5f8382ee3
Rename page runtime edge to experimental-edge (#38041)
* Rename page runtime edge to experimental-edge

* fix ut

* fix lint

* PageRuntime -> ServerRuntime

* rename constant
2022-06-26 20:02:24 -05:00
JJ Kasper
252d3b72f4
Ensure we do not ignore module not found errors during build (#38026)
* Ensure we do not ignore module not found errors during build

* lint-fix
2022-06-26 19:34:58 -05:00
Jiachi Liu
948f736fac
chore: rename middleware ssr loader and flight manifest to edge related (#38042)
middleware-ssr-loader -> edge-ssr-loader
middleware-flight-manifest -> flight-manifest
2022-06-26 21:01:26 +00:00
Gal Schlezinger
22206651a6
[eslint-plugin-next] remove no-server-import-in-page rule (#38028)
This rule was good and kinda made sense when we had nested Middleware.
Now that we have a single Middleware, one might extract logic into different places
and I don't think we should limit importing `NextResponse` or `NextRequest`.

## Related

- Closes #36239
- Closes #37309



## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-26 12:43:15 +00:00
Mikis Woodwinter
2b451ee69a
feat(cli): allow configuration of http-server's timeout configuration (#35827)
* feat: add keep-alive timeout params for next-start

* feat: add keep-alive timeout args to next-cli's start

* docs: add docs for keep-alive timeouts

* docs: fix grammar & typos

* refactor: handle NaN for args

* test: add tests for timeout args

* revert: remove headersTimeout option

* fix: remove input validation for keepAliveTimeout arg

* feat: add input-range validation for keepAliveTimeout arg

* Error and tests for range validation

* Make sure timeout actually changes

* Fix error messsage

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

Co-authored-by: Hannes Bornö <hannes.borno@vercel.com>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: Steven <steven@ceriously.com>
2022-06-26 13:26:51 +02:00
JJ Kasper
6781a52559
Fix invalid warning for existing experimental flag (#38027) 2022-06-25 23:05:02 -05:00
Sukka
c85c41043d
fix(#37981): handle legacy link behavior with number type children (#38013)
## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes #37981.

When handling the legacy link behavior on the current version of Next.js, it only wraps single string child in `<a>` tag. The PR fixes the issue by also wrap single number child in `<a>` tag, too.
2022-06-25 20:07:40 +00:00
JJ Kasper
f4fb3e0377
Fix eslint-config-next peer dep issue (#38009)
It seems `npm` fails to resolve the `next` `peerDependencies` field for `eslint-config-next` and this field isn't necessarily needed so this removes it to ensure upgrading doesn't require the `--force` flag.  

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/pull/38008#discussion_r906629793
2022-06-25 12:08:14 +00:00
Damien Simonin Feugas
cb882b7e70
fix: hardcoded protocol in request url (#37925)
* fix: hardcoded protocol in request url

* test: covers custom server using https

* Apply suggestions from code review

* fix test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-24 19:31:23 -05:00
Steven
f6ee4c06b9 v12.1.7-canary.48 2022-06-24 19:56:15 -04:00
Steven
71e25d4f54
Fix npm publish to include future folder (#37999)
* Fix npm publish to include `future` folder

* Fix webpack config and add a test

* lint-fix

* Change static import to url string

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-24 18:30:30 -05:00
Lee Robinson
8ce2790026
On-demand ISR updates. (#37955)
* On-demand ISR updates.

* Apply suggestions from code review

* lint-fix

* Update docs/basic-features/data-fetching/incremental-static-regeneration.md

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-24 16:59:23 -05:00
Steven
8302a3ff7c
Move rimraf from root packages using it (#37996)
In a previous PR (#37278), the dependencies for benchmarks were moved to a subdirectory.

This ensures the same is done for other packages using `rimraf` which means we can remove it from the root package.json
2022-06-24 21:08:52 +00:00
JJ Kasper
20d6792542
Move outputStandalone config (#37994) 2022-06-24 14:58:35 -05:00
Steven
086746538c v12.1.7-canary.47 2022-06-24 14:58:49 -04:00
Javi Velasco
a8757135e2
Fixes for middleware compilation errors (#37984)
* Refactor `runDependingOnPageType`

* Throw specific error when the compiled middleware cannot be found

* Do not render `MiddlewareNotFoundError` on dev

* Allow to invalidate compilers by type

* Show compile errors when middleware fails to build

* Add tests
2022-06-24 13:50:49 -05:00
JJ Kasper
edd798e526
Fix hard navigation guard on popstate and handle fetching fresh data (#37970)
* Fix hard navigation guard on popstate and handle fetching fresh data

* undo link changes and handle middleware cases

* update tests
2022-06-24 10:50:41 -05:00
Lee Robinson
07a6d4a880
Remove Middleware warning message. (#37973)
* Remove Middleware warning message.

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-24 10:43:36 -05:00
Steven
e28d03c5a4
Add experimental next/future/image component (#37927)
This PR introduces a new experimental component, `next/future/image`, which is inspired by the existing experimental `layout="raw"`.

The difference is that much of the code has been deleted in order to reduce client-side code as well as reduce complexity:

- No `layout` prop
- No `loader` config (although `loader` prop works)
- No `IntersectionObserver`, use native `loading="lazy"` 
  - No `lazyBoundary`
  - No `lazyRoot`
- No `fill` (yet) so width & height are required
- No `objectFit` (use `style` instead)
- No `objectPosition` (use `style` instead)

This improves performance because native `loading="lazy"` doesn't need to wait for React Hydration and client-side JS.

In a future PR, we will modify `next/image` to remove `layout="raw"` since this new component supersedes it.

## Feature

- [x] Integration tests added
- [x] Documentation added
- [x] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`
2022-06-24 14:56:05 +00:00
JJ Kasper
8a0f86a8e8
v12.1.7-canary.46 2022-06-23 21:12:22 -05:00
JJ Kasper
7bb247ca8f
Move styled-jsx type reference (#37964)
Follow-up to https://github.com/vercel/next.js/pull/37902 this moves the reference to avoid a change in `next-env.d.ts`. Also updates our doc note on the `next-env.d.ts` file to be more explicit about it being ignored.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-23 19:26:08 +00:00
JJ Kasper
7c484a80a6
Ensure cache-control is correct when returning redirect (#37958) 2022-06-23 13:23:30 -05:00
Leah
95449e6632
feat: enable styled-components css prop swc transform by default (#37962) 2022-06-23 18:08:22 +00:00
Balázs Orbán
f15fb7c65a
feat(cli): support examples without package.json (#37910)
Previously our CLI assumed that when using an `--example` flag, the example contains a `package.json` file. There are examples though, like `with-docker-compose` which does not have one. In that case, we can simply clone the directory and show a success message.

<details>
<summary>
Full list of examples without <code>package.json</code>:
</summary>
<ul>
<li>custom-server</li>
<li>page-transitions</li>
<li>parameterized-routing</li>
<li>reproduction-template</li>
<li>with-chakra-ui-typescript</li>
<li>with-cookie-auth</li>
<li>with-docker-compose</li>
<li>with-dotenv</li>
<li>with-facebook-chat-plugin</li>
<li>with-firebase-authentication</li>
<li>with-firebase-authentication-serverless</li>
<li>with-glamorous</li>
<li>with-global-stylesheet</li>
<li>with-global-stylesheet-simple</li>
<li>with-graphql-faunadb</li>
<li>with-markdown</li>
<li>with-material-ui</li>
<li>with-next-auth</li>
<li>with-next-i18next</li>
<li>with-next-multilingual</li>
<li>with-next-routes</li>
<li>with-now-env</li>
<li>with-pretty-url-routing</li>
<li>with-prisma</li>
<li>with-redux-toolkit</li>
<li>with-redux-toolkit-typescript</li>
<li>with-sentry-simple</li>
<li>with-strict-csp-hash</li>
<li>with-styled-jsx-postcss</li>
<li>with-sw-precache</li>
<li>with-typescript-styled-components</li>
<li>with-universal-configuration-build-time</li>
<li>with-universal-configuration-runtime</li>
</ul>
</details>

Fixes #37884

In a follow-up PR, we can try to detect if an example contains a README.md file only, and if the example was moved, we could either try getting it from the new location or at least show a better message. (Eg.: using a magic comment that we can parse)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-23 17:28:14 +00:00
Leah
7c20918bc7
feat: enable configuration of styled-components transform and enable css prop support (#37861)
This allows configuring / overriding the default options of the `styled-components` swc transform and allows using the `css` prop support, which was already implemented, but not available.

Edit: made the CSS prop transform run before the display name, so it gets picked up by that and receives the (deterministic) name.

Relates to #30802
2022-06-23 16:55:05 +00:00
Jiachi Liu
3881bbd3ec
Drop experimental.reactRoot in favor of auto detection (#37956)
* Drop experimental.reactRoot in favor of auto detection

* fix it hydraion metric
2022-06-23 18:33:16 +02:00
JJ Kasper
11b13074f1
Ensure special chars in middleware matcher is handled (#37933) 2022-06-23 09:13:40 -05:00
JJ Kasper
f246e781bb
v12.1.7-canary.45 2022-06-22 17:25:10 -05:00
JJ Kasper
89bc9c66ea
Ensure resolvedUrl is correct with fallback rewrites (#37932)
* Ensure resolvedUrl is correct with fallback rewrites

* fix-lint

* normalize slash
2022-06-22 17:02:46 -05:00
Shu Ding
b04cdc9f2f
Fix next/head in _app in RSC pages (#37928)
* fix next/head in _app with rsc

* revert change

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-22 21:56:26 +02:00
Hoon Oh
1a0346e68d
fix: keep _ssgManifest.js output uniform (#37906)
Hello,

This PR sorts paths array before generating `_ssgManifest.js` to keep output of static HTML exports uniform.
Before this change, the output of `_ssgManifest.js` would almost always change, which in result changes the static HTML export artifact's checksum every time.
2022-06-22 17:54:01 +00:00
Gal Schlezinger
92915e47f7
Remove NextResponse.json as we already have it defined from inheriting Response (#37887)
Lately, `Response.json` was introduced as a standard static method.
That means we can remove our implementation of `NextResponse.json` piggyback on `Response.json`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-22 16:03:31 +00:00
Hannes Bornö
2ff660c25a
Remove full reload overlay and warn in CLI instead (#37874)
- Always perform a full reload when needed without blocking with the overlay.
- Old client warnings re-added.
- Post client warning to dev server and print it in the CLI. 


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-22 15:41:23 +00:00
JJ Kasper
c4dc081e70
Fix styled-jsx types when package is not hoisted (#37902)
This ensures we expose the `styled-jsx` types correctly even when the package is not hoisted from next's `node_modules` e.g. when using `pnpm`. We had an existing test that covered this although it installed `styled-jsx` at the top-level as a workaround so the test has been updated to remove this workaround. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/pull/37828#discussion_r901164193
2022-06-22 12:09:22 +00:00
Jiachi Liu
a1b8a96082
refactor: merge duplicated render page logic (#37897)
Simplify rendering page logic (render page and match dynamic routes) in `renderToResponse`
2022-06-21 23:56:53 +00:00
JJ Kasper
5b854f31f5
v12.1.7-canary.44 2022-06-21 16:20:06 -05:00
Jiachi Liu
2608e7d865
Migrate middleware ssr to edge functions (#37708)
x-ref: #31506

This PR migrates existing SSR on edge from middleware to edge functions implmentation. So that we can get rid of limitation of middleware and resolve the conflicts between middleware and edge SSR routes.

* Adding edge functions matching route in middleware catch all route,keep the order as `middleware catch all` -> redirects/rewrites -> `edge catch all` -> others
* Dropping middleware related code for edge SSR: removing client info and preflight request handling
2022-06-21 19:04:48 +00:00
JJ Kasper
1f68a5df52
v12.1.7-canary.43 2022-06-21 13:17:00 -05:00
JJ Kasper
e8a1320e2a
Ensure next-server tracing uses tracing root config (#37888)
As noticed in https://github.com/vercel/next.js/pull/37596 it seems we aren't locking the `next-server` tracing to the tracing root which can allow files outside of the folder to be included unexpectedly.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-21 18:11:32 +00:00
Donny/강동윤
ee7648ae0a
Update swc (#37607)
* Update swc

* Update again

* fixup

* Bump

* Update

* fixup

* Update test refs

* Update minifier

* Parser

* Update swc

* Bump version

* Update

* fixup

* Update test refs

* Bump

* Update `@swc/helpers`

* lockfile

* lints

* FIx

* [TRY] Update @swc/core
2022-06-21 10:51:47 -05:00
Jan Nicklas
3b7254538d
resolve swc-plugin paths (#37412)
This PR uses `require.resolve` to allow using node module paths as SWC plugin names similar to Babel.
This works for:
- absolute file paths
- node modules
- node module paths

## Bug

- [x] Related issues: fixes #37409
2022-06-21 15:37:13 +00:00
Sukka
ad728f4e61
Fix <Image/>'s lazyRoot and other optimizations (#37447)
The PR fixes `<Image />` and `<Link />` components' extra re-renders, `lazyRoot` has no effect, and applies some other optimizations.
2022-06-21 14:01:17 +00:00
JJ Kasper
d8bfa7b112
Fix compile time log after error (#37863) 2022-06-21 11:04:57 +02:00
Javi Velasco
ffa378901f
Include i18 and basePath on middleware with custom matchers (#37854)
When generating the RegExp for middleware using the `matcher` option we are not taking into consideration i18n and basePath. In this PR we include them always which should we the middleware default. In a followup PR we will provide an option to opt-out in the same way we do with rewrites and redirects defined from Next.js config.
2022-06-20 22:34:03 +00:00
JJ Kasper
89333da141
v12.1.7-canary.42 2022-06-20 10:44:11 -05:00
Gal Schlezinger
9184d6d342
[edge api] allow wasm usage (#37836)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-20 15:08:40 +02:00
JJ Kasper
122899bd37
Add hard navigation guard and fix middleware rewrite cases (#37815)
This adds a guard for whenever we do a hard navigation over a client-navigation to ensure we aren't redirecting to the same URL that we are currently on as this can cause infinite redirecting. This also fixes some cases with middleware rewrites without i18n enabled and expands our middleware suite to test both with i18n and without. 

This also fixes a race condition with the query updating where a user could attempt a route transition and it then gets overridden by the query updating and prevents firing router events during the query updating as these can be false signals of a transition.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/37804
2022-06-20 11:31:19 +00:00
Gal Schlezinger
4ed0b78ab6
Allow Edge Functions to receive body (#37822)
This PR enables Edge API endpoints to receive a body.
This wasn't in the original PR, as thankfully pointed out by @zaiste in [this comment](https://github.com/vercel/next.js/pull/37481#discussion_r899440567) 🙏

## Related

- Fixes #37821

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-20 09:46:52 +00:00
JJ Kasper
081c21bc1c
Revert "Enable externalHelpers when pre compiling Next.js' code" (#37829)
Revert "Enable `externalHelpers` when pre compiling Next.js' code (#37164)"

This reverts commit 4671010169.
2022-06-19 13:19:23 -05:00
Sukka
4671010169
Enable externalHelpers when pre compiling Next.js' code (#37164)
* chore: enable `externalHelpers` for pre-compile

* chore(devDeps): update @swc/core@1.2.203
2022-06-19 10:03:50 -05:00
Gal Schlezinger
e05c31df17
Throw an error when target: 'serverless' is used with Middleware (#37819)
Serverless target is deprecated, so we don't support it in Middleware as it's a new feature,
but we need to have a good error message for that. This commit solves that.

## Related

* Fixes #37433



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-19 13:17:18 +00:00
JJ Kasper
8577c4f07b
Detect pnpm correctly when installing missing dependencies (#37813)
This ensures we properly detect `pnpm` when installing missing dependencies. This also adds test coverage to ensure we properly detect the correct package manager. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1655568091661719)
2022-06-19 12:33:23 +00:00
Hannes Bornö
2313ee093a
Display full refresh warning even when error has occurred (#37425)
If you end up in a state where an error happened and you also should be warned about a full refresh  - you get stuck. The full refresh is blocked by the warning but the error is shown instead.

Tests didn't catch this because the refresh warning never showed in `__NEXT_TEST_MODE`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-19 00:00:14 +00:00
Sukka
5c88484f04
fix(config): only warn experimental feature when used (#37755)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order 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 that you're making:
-->

```js
// next.config.js
module.exports = {
  experimental: {
    legacyBrowsers: false,
    sharedPool: true,
    newNextLinkBehavior: false
  }
}
```

With the current implementation, using the config above will warn the usage of experimental features. However, those are the preset values that are defined in `defaultConfig` which means actually no experimental feature has been enabled at all.

The PR changes to only check if experimental features are actually enabled (have different values than the ones defined in `defaultConfig`).
2022-06-18 07:44:37 -04:00
Alex Castle
af9d92207e
Use SVG blur technique for raw layout images (#37022)
This PR switches to using an SVG filter for blurring placeholder images, rather than a CSS filter. It's based on the technique described in @cramforce's [blog post](https://www.industrialempathy.com/posts/image-optimizations/#blurry-placeholder).

One change I made to @cramforce's version was to increase the stdDeviation property of the SVG (which controls the gaussian blur strength) from .5 to 50. Smaller values than this tended to look bad, as our technique for generating the blurry placeholder image tends to produce images with sharp contrast between the pixels, which looks bad when blown up unless it's blurred by a substantial amount.

This PR currently only affects the experimental `layout="raw"` but I expect to eventually apply it to all images. CC: @styfle @kara
2022-06-17 21:16:20 +00:00
JJ Kasper
67e937d821
v12.1.7-canary.41 2022-06-17 10:44:25 -05:00
JJ Kasper
85e643be83
Ensure query params are populated correctly with middleware (#37784)
* Ensure query params are populated correctly with middleware

* update test

* dont match edge ssr

* fix query hydrate check

* fix lint

* update test
2022-06-17 10:28:25 -05:00
Damien Simonin Feugas
c2b8006485
refactor(middleware): leverages edge-runtime builtins to decorate errors in dev (#37718)
### What's in there?

This is a followup of https://github.com/vercel/next.js/pull/37695.
For the dev server to clean stacktraces, we're decorating errors caught during code evaluation (`getServerSideProps` or middleware).
However, when these errors are asynchronously raised, we can't decorate them before processing them, leading to this fallback logic:

bf7bf8217f/packages/next/server/dev/next-dev-server.ts (L775-L779)

Thanks to latest improvement of the edge-runtime in 1.1.0-beta.4, we can now catch unhandled rejection and uncaught exception, and decorate them.

### How to test?

Please reuse the existing tests who already covered these cases:
`pnpm testheadless --testPathPattern middleware-dev-errors`


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-17 15:06:30 +00:00
Javi Velasco
2d5d43fb75
Refactor server routing (#37725)
This PR fixes an issue where we have a middleware that rewrites every single request to the same origin while having `i18n` configured. It would be something like: 

```typescript
import { NextResponse } from 'next/server'

export function middleware(req) {
  return NextResponse.rewrite(req.nextUrl)
}
```

In this case we are going to be adding always the `locale` at the beginning of the destination since it is a rewrite. This causes static assets to not match and the whole application to break. I believe this is a potential footgun so in this PR we are addressing the issue by removing the locale from pathname for those cases where we check against the filesystem (e.g. public folder).

To achieve this change, this PR introduces some preparation changes and then a refactor of the logic in the server router. After this refactor we are going to be relying on properties that can be defined in the `Route` to decide wether or not we should remove the `basePath`, `locale`, etc instead of checking which _type_ of route it is that we are matching.

Overall this simplifies quite a lot the server router. The way we are testing the mentioned issue is by adding a default rewrite in the rewrite tests middleware.
2022-06-16 21:43:01 +00:00
JJ Kasper
5730ed0f61
Ensure eslint-config warning/errors are correct (#37760)
* Ensure eslint-config warning/errors are correct

* fix tests
2022-06-16 16:04:44 -05:00
Steven
b7d057453d
Add images.unoptimized: true for easy next export (#37698)
In a previous PR (#19032), we added a hard error during `next export` if the default Image Optimization API is being used because it requires a server to optimized on demand. The error message offers several different solutions but it didn't consider that by the time someone runs `next export`, they are probably done writing their app.

So if `next export` is a hard requirement, the quickest path forward is to disable Image Optimization API. So this PR adds a new configuration option to `next.config.js`:

```js
module.exports = {
  images: {
    unoptimized: true
  }
}
```

### Update
Upon further discussion, we might want to avoid doing this just for images and instead introduce a top-level config to indicate export is coming and then handle errors or warn for [unsupported features](https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features).

```
module.exports = {
  nextExport: true
}
```

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-16 20:20:17 +00:00
Steven
448ba2b384
Enhance experimental feature warning (#37752)
This improves the warning thats printed when you have experimental features enable so its clear which ones are enabled (in parenthesis) and where they are enabled (in next.config.js or next.config.mjs)

## Before

```
warn  - You have enabled experimental feature(s).
```

## After

```
warn  - You have enabled experimental features (reactRoot, serverComponents, scrollRestoration) in next.config.js.
```
2022-06-16 19:59:47 +00:00
JJ Kasper
37de4f989a
Remove previous query param deleting warning (#37740) 2022-06-16 13:41:44 -05:00
JJ Kasper
9bd1751ce5
Update to skip middleware for unstable_revalidate (#37734)
* Update to skip middleware for unstable_revalidate

* lint fix
2022-06-16 11:22:35 -05:00
Seiya Nuta
0bf9233e14
[middleware] Warn dynamic WASM compilation (#37681)
In Middlewares, dynamic code execution is not allowed. Currently, we warn if eval / new Function are invoked in dev but don't warn another dynamic code execution in WebAssembly.

This PR adds warnings for `WebAssembly.compile` and `WebAssembly.instantiate` with a buffer parameter (note that `WebAssembly.instantiate` with a **module** parameter is legit) invocations. Note that other methods that compile WASM dynamically such as `WebAssembly.compileStreaming` are not exposed to users so we don't need to cover them.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-16 14:59:30 +00:00
Andrei Stefan
6b829d8bd6
fix(eslint): allow <img> in conjunction with <picture> (#37504) (#37570)
* fix(eslint): allow <img> in conjunction with <picture> (#37504)

* Apply suggestions from code review

* add space

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-15 21:13:52 -05:00
JJ Kasper
1fcbc3ec60
Update pre-compiled (#37729)
Seems this got out of sync pre-release so this re-syncs the compiled files

Fixes: https://github.com/vercel/next.js/runs/6907047235?check_suite_focus=true

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-15 20:51:51 +00:00
JJ Kasper
016ce59a97
v12.1.7-canary.40 2022-06-15 14:40:38 -05:00
JJ Kasper
808e558ade
Ensure rewrite query params with middleware are available in router (#37724)
* Ensure rewrite query params with middleware are available in router

* Ensure header matches deploy and add test case

* update check
2022-06-15 14:32:44 -05:00
Jiachi Liu
40b0dae558
chore: bump react dev dep to 18.2 (#37697)
* chore: bump react dev dep to 18.2

* fix test and exclude inc cache path for edge

* update compiled

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-15 10:14:43 -05:00
Gal Schlezinger
7193effcc0
Fix shallow routing with rewrites/middleware (#37716)
Shallow route changes did not work for rewritten pages when Middleware
was used, and made hard refreshes, although it was possible with static rewrites.

This happened because the router has a manifest of the static rewrites,
allowing static rewrites to map the route before comparing with the
local cache.

Middleware rewrites are dynamic and happening on the server, so we
can't send a manifest easily. This means that we need to propagate
the rewrites from the data requests into the components cache in
the router to make sure we have cache hits and don't miss.

This commit does exactly that and adds a test to verify that it works.

This fixes #37072 and fixes #31680

_Note:_ there's one thing that is somewhat an issue though: if the first
page the user lands on is a rewritten page, and will try to make a
shallow navigation to the same page--we will make a `fetch` request.
This is because we don't have any client cache of the `rewrite` we just
had.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-15 15:09:13 +00:00
JJ Kasper
bf7bf8217f
Ensure navigating with middleware parses route params correctly (#37704) 2022-06-15 09:09:51 -05:00
Javi Velasco
de7b316446
Improve Middleware errors (#37695)
* Improve stack traces in dev mode

* Refactor `react-dev-overlay` to support the Edge Compiler

* Serialize errors including the compiler `source`

* Adopt the new `react-dev-overlay` displaying it for middleware errors

* Improve tests

* fix rsc cases

* update test

* use check for dev test

* handle different error from node version

Co-authored-by: feugy <damien@vercel.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-14 19:58:13 -05:00
Balázs Orbán
0dda1b9f6c
fix(ts): expose DynamicOptionsLoadingProps type (#37700)
Fixes #37683

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-15 00:33:18 +00:00
Javi Velasco
c501842311
Add test combining middleware & config rewrites (#37667)
* Add test combining middleware & config rewrites

* Add `afterFiles` test

* update some tests

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-14 17:31:33 -05:00
JJ Kasper
b65e10ea7a
v12.1.7-canary.39 2022-06-14 12:03:57 -05:00
JJ Kasper
a01aa4de6a
Revert "Revert "Revert "Avoid unnecessary router state changes""" (#37692)
Revert "Revert "Revert "Avoid unnecessary router state changes"" (#37593)"

This reverts commit 78cbfa06fb.
2022-06-14 12:00:11 -05:00
JJ Kasper
097574d4c3
Optimize middleware regex handling (#37688)
* Optimize middleware regex handling

* fix data route matching for middleware
2022-06-14 11:50:05 -05:00
JJ Kasper
75053a06f8
v12.1.7-canary.38 2022-06-13 22:11:26 -05:00
JJ Kasper
e7f08ef040
Ensure custom middleware matcher is used correctly in client manifest (#37672)
* Ensure custom middleware matcher is used correctly in client manifest

* lint-fix

* patch e2e case

* fix rsc case

* update test

* add missing normalize
2022-06-13 22:07:40 -05:00
Michael Novotny
5211ac5cae
Adds consistency to ESLint rules. (#34335)
* Adds consistency to ESLint rules.

* Fixes lint errors.

* Fixes manifest.

* Adds missing title.

* Fixes copy / paste error.

Co-authored-by: Lee Robinson <me@leerob.io>

* Update errors/no-script-in-document.md

Co-authored-by: Lee Robinson <me@leerob.io>

* Update errors/no-sync-scripts.md

Co-authored-by: Lee Robinson <me@leerob.io>

* Updates a couple of rule descriptions.

* Adds redirects.

* Fixes unit tests.

* Removes duplicated section.

* Updates `no-before-interactive-script-outside-document` description.

* Fixes lint.

* Fixes integration tests.

* Adds description to `no-before-interactive-script-outside-document` documentation.

* Removes `link-passhref` from rules list.

* Updates remaining `pages/_middleware.js` references.

* Adds consistancy to messaging in new `no-styled-jsx-in-document` rule.

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-13 21:17:42 -05:00
Steven
ec4df71352
Fix Image Optimization cache-control regression with external images (#37625)
In a previous PR (#34075), the ISR behavior was introduced to the Image Optimization API, however it changed the cache-control header to always set maxage=0. While this is probably the right behavior (the client shouldn't cache the image), it introduced a regression for users who have CDNs in front of a single Next.js instance (as opposed to [multiple Next.js instances](https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration#self-hosting-isr)).

Furthermore, the pros of client-side caching outweight the cons because its easy to change the image url (add querystring param for example) to invalidate the cache.

This PR reverts the cache-control behavior until we can come up with a better long-term solution.

- Fixes #35987
- Related to #19914 
- Related to #22319 
- Closes #35596
2022-06-13 22:13:55 +00:00
JJ Kasper
77c96a19b3
v12.1.7-canary.37 2022-06-13 15:50:25 -05:00
JJ Kasper
668466bc07
Fix rewrite/dynamic interpolation E2E cases (#37669) 2022-06-13 15:46:19 -05:00
Gal Schlezinger
b62bb97b6f
Re-introduce Edge API Endpoints (#37481)
* Re-introduce Edge API Endpoints

This reverts commit 210fa39961, and
re-introduces Edge API endpoints as a possible runtime selection in API
endpoints.

This is done by exporting a `config` object:

```ts
export config = { runtime: 'edge' }
```

Note: `'edge'` will probably change into `'experimental-edge'` to show
that this is experimental and the API might change in the future.

* Support `experimental-edge`, but allow `edge` too

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-13 11:17:44 -07:00
JJ Kasper
07420998c1
v12.1.7-canary.36 2022-06-13 10:32:27 -05:00
JJ Kasper
6f698405dd
Update matched path params priority (#37646)
This ensures we use the correct dynamic route params favoring params from the URL/matched-path over route-matches. This also ensures we properly cache `_next/data` requests client side when the page is not a `getServerSideProps` page. 

x-ref: https://github.com/vercel/next.js/pull/37574

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-13 13:34:08 +00:00
Joe Previte
6108f10799
feat(next export): add warning if using getInitialProps (#37642)
This PR builds on the work from @hattakdev (PR went stale: https://github.com/vercel/next.js/pull/14499) and adds a new `integration` test for the new warning.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

![image](https://user-images.githubusercontent.com/3806031/173214117-f5159f3a-778c-4177-894d-78e7bb0c80e7.png)

## To run locally
1. `pnpm build` 
2. `pnpm testonly test/integration/export-getInitialProps-warn/test/index.test.js`

Fixes #13946

## Notes

<details>
<summary>Click to toggle see</summary>

I know the `contributing.md` doc said to avoid adding new tests to `integration`. It also said new tests should be written in TypeScript.

I wasn't sure where to put the tests for this so I went with `integration`. I also didn't see many other tests written in TS in this part of the codebase so I stuck with `.js`. 

</details>

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-13 02:34:23 +00:00
Damien Simonin Feugas
ae44779bcb
chore: narrows regexp to enable middleware source maps (#37582)
* chore: narrows regexp to enable middleware source maps

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-10 20:22:03 -05:00
JJ Kasper
1463f0d1bc
v12.1.7-canary.35 2022-06-10 18:24:42 -05:00
JJ Kasper
f8ebb19dc5
v12.1.7-canary.34 2022-06-10 15:23:31 -05:00
Jiachi Liu
12b726fd15
Strip next internal queries for flight response (#37617)
Strip next internal queries in inline flight response

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-10 20:08:24 +00:00
Steven
2addf464d2
Bump @vercel/nft 0.20.0 (#37602)
* Bump @vercel/nft 0.20.0

* Filter out wasm files

* Revert filter that is no longer needed

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-10 13:10:52 -05:00
JJ Kasper
607ff2b322
Update to process redirects/rewrites for _next/data with middleware (#37574)
* Update to process redirects/rewrites for _next/data

* correct matched-path resolving with middleware

* Add next-data header

* migrate middleware tests

* lint-fix

* update error case

* update test case

* Handle additional resolving cases and add more tests

* update test from merge

* fix test

* rm .only

* apply changes from review

* ensure _next/data resolving does not apply without middleware
2022-06-10 12:35:12 -05:00
Shu Ding
78cbfa06fb
Revert "Revert "Avoid unnecessary router state changes"" (#37593)
Reverts vercel/next.js#37572, with a new test case added about `routeChangeComplete`.
2022-06-09 15:48:50 +00:00
JJ Kasper
b4298f9541
Ensure check-precompiled exits correctly on failure (#37592)
* Ensure check-precompiled exits correctly on failure

* update compiled
2022-06-09 10:09:18 -05:00
Shu Ding
c613608bfc
Fix client entry unexpectedly created in app dir (#37561)
fix client entry unexpectedly created
2022-06-09 16:58:10 +02:00
Jiachi Liu
0bfdf0e0d1
Fix react root env missing in NextServer (#37562)
* Fix react root env missing in NextServer

* switch to useId instead of using process.env var

* add production test

* extend timeout

* fix test

* fix lint

* use version to detect if enable react root
2022-06-09 15:43:38 +02:00
Gal Schlezinger
9155201807
[middleware] support destructuring for env vars in static analysis (#37556)
This commit enables the following patterns in Middleware:

```ts
// with a dot notation
const { ENV_VAR, "ENV-VAR": myEnvVar } = process.env;

// or with an object access
const { ENV_VAR2, "ENV-VAR2": myEnvVar2 } = process["env"];
```

### Related

- @cramforce asked this fixed here: https://github.com/vercel/next.js/pull/37514#discussion_r892437257



## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-09 11:49:58 +00:00
Kiko Beats
76083210ed
Middleware: remove req.ua (#37512)
This PR moves the internal logic associated with `req.ua` into an explicit method the user should to call to have the same behavior.

**before**

```typescript
// middleware.ts
import { NextRequest, NextResponse } from 'next/server'
export function middleware(request: NextRequest) {
  const url = request.nextUrl
  const viewport = request.ua.device.type === 'mobile' ? 'mobile' : 'desktop'
  url.searchParams.set('viewport', viewport)
  return NextResponse.rewrites(url)
}
```

**after**

```typescript
// middleware.ts
import { NextRequest, NextResponse, userAgent } from 'next/server'
export function middleware(request: NextRequest) {
  const url = request.nextUrl
  const { device } = userAgent(request)
  const viewport = device.type === 'mobile' ? 'mobile' : 'desktop'
  url.searchParams.set('viewport', viewport)
  return NextResponse.rewrites(url)
}
```

This potentially will save the extra 17 kB related to the size of `ua-parser-js`
2022-06-09 11:10:21 +00:00
JJ Kasper
0c986cd767
v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
Shu Ding
23295ef34b
Revert "Avoid unnecessary router state changes" (#37572)
Reverts vercel/next.js#37431
2022-06-08 21:51:40 +00:00
JJ Kasper
2ea3e92a21
v12.1.7-canary.32 2022-06-08 11:55:39 -05:00
Damien Simonin Feugas
08ed362b82
chore: reworks nested middleware error message (#37513)
* chore: reworks nested middleware error message

* chore: fix invalid path in nested middleware error message

* Update to show nested middleware error together

* update

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-08 11:51:26 -05:00
Damien Simonin Feugas
09f48a7590
fix(eslint): false positive for legit next/server imports (#37515)
* fix(eslint): next/server error when next is not in the root

* chore: fix lint issue and posix compatibility

* chore: make it portable
2022-06-08 11:08:59 -05:00
Javi Velasco
7584b02b34
Remove Middleware Preflight (#37490)
* Refactor data fetching to support getting headers

* Relax `getNextPathnameInfo` type

* Add test for middleware internal redirects

* Export `ParsedRelativeUrl` type

* Refactor `getMiddlewareEffects`

* Move rewrite i18n test to middleware rewrite tests

* Fix bug parsing pathname info

* Normalize data requests to page requests for middleware

* Ensure there is a header `x-nextjs-matched-path` for middleware rewrites on data requests

* Extract `getDataHref` to a function

* Stop using `getDataHref` for flight

* Always set the query in `dataHref` independently of if it is SSG

* Add test for recursive rewrites

* Refactor dynamicPath validation to `matchHrefAndAsPath`

* Add `dataHref` to `FetchDataOutput`

* Extract `matchesMiddleware` function

* Add `hasMiddleware` option to `fetchNextData`

* Move preflight test

* Remove preflight test

* Add middleware prefetch tests

* Remove preflight

* Attempt to reduce bundle size

Include `withMiddlewareEffects` and `matchHrefAndAsPath` into `router`

Bring `getDataHref` back to `page-loader`

Bring `resolveDynamicRoute` back to `router`

* Reduce arg duplication for `withMiddlewareEffects`

* Remove some async/await and spreads to reduce bundle size

* Upgrade `edge-runtime` & clone `Request` on redirects to mutate headers

* Add some rewrite tests

Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-08 10:41:28 -05:00
Damien Simonin Feugas
977ff52472
fix(#37106): middleware can not be loaded from src folder (#37428)
## Bug
fixes #37106

Please note that, as for `pages/` the `src/middleware` file is ignored when `/middleware` is present.

## How to test

1. Rebuild next.js `pnpm build`
2. Run dedicated tests: `pnpm testheadless --testPathPattern middleware-src/`
2022-06-08 14:10:05 +00:00
Sukka
40778597a5
chore: remove unused safari nomodule fix (#37541)
`safariNomoduleFix` was first introduced back in the year 2019 (#7704) as a part of the `modern` experimental feature. The experiment is ended and the feature is removed a year later in #19275. However, the unused `safariNomoduleFix` is never removed, until now.
2022-06-08 11:56:15 +00:00
Jiachi Liu
16fd15b526
Migrate head side effects to hooks (#37526)
* rewrite head side effects component in hooks
* remove mapping from element to children in head manager since they're already the children of `<Head>`

When move `SideEffect` to hooks, the effects scheduling is earlier than life cycle. We're leverage layout effects and effects at the same time, always cache the latest head updating function in head manager in layout effects, and flush them in the effects. This could help get rid of the promises delaying approach in head manager.

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2022-06-08 11:26:57 +00:00
Gal Schlezinger
88d0440ad4
[middleware] Support any method when fetching a Request instance (#37540)
There was a bug that ignored `Request` options when one was given to the `fetch` function:

```ts
const request = new Request("https://example.vercel.sh", { method: "POST" });
await fetch(request);
```

The code above was expected to make a `POST` request, but instead it
made a `GET` request.

This commit fixes it and adds some tests to verify that fetching with a
`Request` object works as expected, and therefore resolves #37123.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-08 11:00:49 +00:00
JJ Kasper
01ecff3b09
Update to latest version of @swc/helpers (#37531)
* Update to latest version of @swc/helpers

* update lock
2022-06-08 11:52:26 +02:00
Balázs Orbán
e7d3b37d52
chore: remove unused variable (#37538)
I noticed this line was not used in the standalone server:

![image](https://user-images.githubusercontent.com/18369201/172573506-236af421-6e28-40d7-b87f-45a424a24e74.png)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-08 09:15:08 +00:00
Keen Yee Liau
dc36199b22
add method to measure Interaction to Next Paint (INP) (#36490)
This commit lets users measure their Interaction to Next Paint [INP](https://web.dev/inp/) web vital.
Note that the `web-vitals` package is beta to denote that INP is an experimental metric, the code is stable and v3 is backwards compatible.

    `web-vitals` CHANGELOG for v3:
    
    - [BREAKING] Report TTFB after a bfcache restore
    - [BREAKING] Only include last LCP entry in metric entries
    - Add support for the new INP metric
    - Rename getXXX() functions to onXXX()
    - Add a navigationType property to the Metric object
    
    See https://github.com/GoogleChrome/web-vitals/blob/next/CHANGELOG.md

Upgraded `playwright-chromium` from `1.14.1` to `1.17.2` because the Events Timing API used to measure INP is only available in Chromium >= v98.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-06-07 18:28:58 +00:00
Eric Burel
42f838e156
Add check for duplicate locales (#37485)
## Bug

- [X] Related issues linked using `fixes #37483`
- [ ] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`

Duplicate locales will lead to an obscure error message at build time, here I caught them earlier.
Using a Set sounded the terser and fastest approach, but it won't tell which locale is duplicated.

Also I've noticed that the "Array.isArray" check happens twice on i18n.locales? Maybe it's on purpose?

Fixes #37483 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-07 17:58:19 +00:00
JJ Kasper
ff0ccc4817
Enable externalHelpers swc option (#37150)
* Enable externalHelpers swc option

* disable with pnp
2022-06-07 10:59:05 -05:00
Shu Ding
1dad75109c
Avoid unnecessary router state changes (#37431)
* avoid unnecessary router state changes

* refine compare function

* check hasOwnProperty

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-07 14:53:33 +02:00
JJ Kasper
6f2eb24109
v12.1.7-canary.31 2022-06-06 16:49:30 -05:00
JJ Kasper
b3000594b2
Fix invalid middleware regexp in manifest (#37492) 2022-06-06 17:37:47 -04:00
JJ Kasper
28a56d8220
v12.1.7-canary.30 2022-06-06 14:39:08 -05:00
Shu Ding
f56a3de49e
Upgrade node-html-parser (#37449)
* upgrade node-html-parser

* update define bundle patching

* update compiled

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-06 15:36:29 -04:00
JJ Kasper
142bceb694
Ensure ENOENT error is not ignored when loading pages (#37486)
* Ensure ENOENT error is not ignored when loading pages

* Add a separate PageNotFoundError

* update tests
2022-06-06 14:35:26 -04:00
John Pham
be5dedf676
Allowing hiding the ReactDevOverlay (#37417)
* Add hide button

* Update label

* Add data attributes for testing

* Add e2e tests

* update test

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-06 14:21:53 -04:00
Pepijn Senders
6914a25dd2
Set swcMinify as an attribute on terser-webpack-plugin-optimize span (#37416)
It would be nice to have this attribute to compare runs with and without the `swcMinify` options.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-06 15:09:33 +00:00
peter
3e5b0253e4
Fix document head with react 18 (#37443)
Fix custom head on getInitialProps works with React 18

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2022-06-04 10:30:42 +00:00
Steven
4cbc61c740
Fix next/image using layout=raw with priority (#37381)
Fixes a regression from #36985 which switched to native lazy loading but didn't account for the case when the user sets `priority` which changes the default behavior of `loading` prop.

See https://github.com/vercel/next.js/pull/36985#issuecomment-1132267710
2022-06-03 21:54:22 -04:00
Shu Ding
95bd68d25a
Skip loading unused plugins in next dev (#37430)
* dynamically load plugins; switch to type imports; fix page extensions

* fix default export
2022-06-03 14:47:16 -04:00
Gal Schlezinger
401a9a4479
Allow Middleware to set its matcher (#37177)
This PR will allow Middleware to set its matcher through `export const config = { matching: ... }`

## Related

* This PR is rebased off #37121 

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-06-03 16:35:44 +00:00
Jiachi Liu
6acfffa659
Remove unused id rsc cache cleaning and avoid rsc refresh existed in client chunk (#37404)
* refactor: remove useless id removal for rsc cache
* avoid refresh root existed in main client chunk
  - x-ref: #36702 
  - x-ref: #35907
2022-06-02 16:14:48 +00:00
Shu Ding
a3e067e6e5
Use the new moduleMap option in the flight client during SSR (#37406)
Adopt the new `moduleMap` option added in https://github.com/facebook/react/pull/24629, which helps us getting rid of our hacky implementation injected to `globalThis.__next_require__`. The map will be attached to the flight manifest as `__ssr_module_mapping__`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-02 15:43:25 +00:00
Shu Ding
b0783e9932
Fix next dev not working for server components in app (#37403)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-02 14:51:41 +00:00
Tim Neutkens
20f9e949b0 v12.1.7-canary.29 2022-06-02 16:02:47 +02:00
Tobias Koppers
273da9e118
update webpack and watchpack (#37397)
https://github.com/webpack/watchpack/releases/tag/v2.4.0
https://github.com/webpack/webpack/releases/tag/v5.73.0

and let pnpm clean up some stuff
2022-06-02 13:09:21 +00:00
Tim Neutkens
ebc3408f47 v12.1.7-canary.28 2022-06-02 12:03:17 +02:00
Tim Neutkens
a840dbf84e
Add Suspense boundary to demo (#37393) 2022-06-02 12:02:05 +02:00
Steven
ccd3df2f81
Fix bloat in main bundle from amp (#37383)
- Related to #35900 
- Related to #36702 
- Related to #35907
2022-06-02 00:21:09 +00:00
Kiko Beats
129052dc98
Edge Functions: deprecate access to request.page (#37349)
It uses `URLSearchParams` to have the same behavior.

closes https://github.com/vercel/next.js/issues/34521
2022-06-01 20:06:37 +00:00
Tim Neutkens
c31c95b735 v12.1.7-canary.27 2022-06-01 13:54:05 +02:00
Tim Neutkens
647c93e4d0
Handle link with back/forward navigation (#37332) 2022-06-01 13:52:57 +02:00
Gal Schlezinger
210fa39961
Revert Edge API endpoints (#37350)
Reverts vercel/next.js#37344
2022-05-31 20:11:12 +00:00
Gal Schlezinger
db20aa65f5
Revert "Revert "support runtime: edge in api endpoints"" (#37344)
Reverts vercel/next.js#37337
2022-05-31 17:12:02 +00:00