Commit graph

11495 commits

Author SHA1 Message Date
JJ Kasper
87d8c2bb2a
Update concurrency for dev and start E2E tests (#37719)
* Update concurrency for dev and start E2E tests

* update config
2022-06-15 11:06:55 -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
Max Proske
007d186b78
Convert hello-world example to TypeScript (#37706)
TypeScript is being leveraged for new examples going forward, so I'm converting this example over. 😂

## 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-15 11:33:35 +00:00
Hung Viet Nguyen
0f873c7eea
Update Jest config with SWC docs (#37705)
## Motivation/ Context
- When upgrading `next` from `11` to `12`, I followed [Upgrade guide from 11 => 12](https://nextjs.org/docs/upgrading#upgrading-from-11-to-12). I removed `.babelrc` to opt-in `SWC`. I thought that's all, but after removing `.babelrc`, Jest broke immediately. So I follow the guide https://nextjs.org/docs/advanced-features/compiler#jest to configure Jest to work with SWC. I copied the content of `jest.config.js` to my project but it does not work. The reason:
```diff
-const createJestConfig = nextJest({ dir }) // `dir` IS NOT DEFINED
+const createJestConfig = nextJest({ dir: './' }) // Should change to this. Sync with https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler
```
- This PR is to help others to configure Jest with SWC by copying code from the documentation site without encountering the same issue as I did.

## Documentation
- [x] Update the docs so users can just copy and paste when configuring Jest with SWC (Sync with https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler)
- [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)

## Future work
- Since [Upgrade guide from 11 => 12](https://nextjs.org/docs/upgrading#upgrading-from-11-to-12) did not mention anything about Jest. If I remove `.babelrc` to opt-in SWC. The current Jest settings will crash (since it's using babel). We likely want to update the Upgrade guide to mention this cc: @leerob
2022-06-15 11:27:28 +00: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
f17f1d4e56
Update middleware matcher e2e test (#37694) 2022-06-14 15:11:36 -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
Max Proske
78809a3d68
Add with-docker-compose example (#32668)
`with-docker-compose` contains everything needed to get Next.js up and running with Docker Compose.

This example aims to provide an easy-to-use, Next.js app development and production environment, **all without Node.js being installed** on the host machine. This ensures a consistent development environment across Windows, MacOS, and Linux teams.

I was inspired to create this, because the existing [with-docker](https://github.com/vercel/next.js/tree/canary/examples/with-docker) example only uses Docker to build the final production artifacts, not provide a development environment. Docker Compose easily syncs changes with containers for Hot Reloading, parallel builds, and networking, making it a powerful and consistent development tool.

Developers can **easily extend this example** by modifying the YAML files to include Nginx, Postgres, and other Docker images. 

This example takes advantage of Docker multistage builds combined with the Next 12.1 [Output Standalone](https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files-experimental) feature, to create up to **80% smaller apps** (Approximately 110 MB compared to 1 GB with create-next-app). I also included an example without multistage builds, for developers who don't want to get into the weeds.

I have been tweaking this Docker Compose setup over 3 years of real world use, but please let me know if anything can be improved.
2022-06-14 11:13:55 +00:00
Max Proske
3a22c4c554
Convert active-class-name example to TypeScript (#37676)
The Contributing guidelines say TypeScript should be leveraged for new examples, so I thought I'd convert this example over. 

I also:
- Upgraded all dependencies
- Replaced the `prop-types` package with TypeScript types

## 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-14 08:49:09 +00: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
JJ Kasper
3b9f180d25
Allow passing FileRef directly to createNext (#37664)
* Allow passing FileRef directly to createNext

* update type
2022-06-13 15:28:34 -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
Splatterxl
e0631d0ef1
Fix links in google-font-display error (#37661) 2022-06-13 10:17:36 -05:00
Thuy Doan
748cc51c34
Update with-mux-video to use latest upchunk and replace video player with mux-player-react (#37621)
* Update upchunk to latest (2.3.1).

* Add mux-player package to package.json

* WIP: Make VideoPlayer return mux-player

* Remove unused code from prev video player

* Use mux-player-react directly

* Fix import line for mux-player-react

* chore: fix lint issues
2022-06-13 10:06:07 -05:00
JJ Kasper
b33bc2dfb0
Update flakey next-script tests (#37663) 2022-06-13 09:54:59 -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
Adam Sobotka
89b961e191
Request library required by setup (#37658)
In my last PR I removed the request library as it is obsolete and the application does not use it. The database setup utility does though, so I am reverting this change.  


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-06-13 11:00:50 +00:00
Houssein Djirdeh
2eb48e7837
[Script] Updates stale no-script-in-document-page error doc (#37568)
[Recent changes](https://github.com/vercel/next.js/pull/31936) to `next/script` introduced the capability to use `beforeInteractive` scripts in the custom document. This old error message is incorrect.
2022-06-13 03:04:15 +00:00
Adam Sobotka
31c8b97a45
Update with-faunadb dependencies (#37650)
This is just a bump of tech stack used in the example and small rewrite of swr functionality.

## 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`
- [ x ] 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-13 02:57:56 +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
You Nguyen
2daa4117c6
Bump version tailwindcss example to 3.1 (#37633) 2022-06-11 23:53:30 +00:00
Alabhya Jindal
30150e449c
Changed _app.js to a functional component (#37635)
Changed the class component to a functional component of the _app.js file. This is for the Context API example.
2022-06-11 23:47: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
Joseph
085ee96577
Fix with mux video example (#37434)
* fix: On error upchunk dispatches an object

* chore: Typo on contribution guide, `unverfied`

* Update contributing.md

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-10 19:50:28 -05:00
JJ Kasper
1463f0d1bc
v12.1.7-canary.35 2022-06-10 18:24:42 -05:00
JJ Kasper
934e5a4835
Update usage of example.com -> example.vercel.sh (#37630)
* Update usage of example.com -> example.vercel.sh

* another one

* another flakey test
2022-06-10 18:19:37 -05:00
JJ Kasper
9f0e691a32
Fix failing swc builds (#37629)
* update android ndk path

* re-add isRelease checks
2022-06-10 17:21:35 -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
Hannes Bornö
7cc8f92241
i18n regression tests and docs for ignore locale in rewrite (#37581)
* Add regression tests for locale prefixed public files

* Add tests for ignoring source locale in rewrite

* Fix lint

* Add doc example

* Redirect tests

* fix test names

* update tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-06-10 14:04:31 -05: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