Commit graph

241 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Gal Schlezinger
ff55e4a7f3
add a test that verifies that NextResponse can be cloned (#37883)
This resolves #35573

I can't seem to reproduce the issue so I only created a unit test that verifies that it has the correct behavior.
@tavvy can you also check this PR out to see if it makes sense or not?

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-21 16:39:40 +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
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
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
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
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
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
JJ Kasper
1d1ffc88b7
Update to leverage turbo for build/prepublish (#37280)
* Update to leverage turbo for build/prepublish

* update path

* remove extra turbo config
2022-05-30 19:05:27 -05:00
Javi Velasco
daab64c27e
Extract router utils to common functions (#37313)
* Extract `detect-domain-locale` to a util file

* Remove `pathNoQueryHash` in favor of `parsePath`

* Remove `hasPathPrefix` in favor of `pathHasPrefix`

* Remove `addPathPrefix` in favor of an existing util

* Bugfix parsing pathname

* Refactor `addLocale`

* Extract `removeLocale`

* Extract `basePath` utils

* Dynamic imports for `getDomainLocale`
2022-05-30 20:19:37 +02:00
Kiko Beats
fafbea8b74
Use Edge Runtime for running Edge Functions locally (#37024)
This PR introduces [Edge Runtime](https://edge-runtime.vercel.app/) for emulating [Edge Functions](https://vercel.com/features/edge-functions) locally.

Every time you run a [middleware](https://nextjs.org/docs/advanced-features/middleware) locally via `next dev`, an isolated edge runtime context will be created.

These contexts have the same constraints as production servers, plus they don't pollute the global scope; Instead, all the code run in a vm on top of a Node.js process.

Additionally, `@edge-runtime/jest-environment` has been added to make easier testing Edge Functions in a programmatic way.

It dropped the following polyfills from Next.js codebase, since they are now part of Edge Runtime:

- abort-controller
- formdata
- uuid
- web-crypto
- web-streams

Co-authored-by: Gal Schlezinger <2054772+Schniz@users.noreply.github.com>
2022-05-30 12:01:36 +00:00
Javi Velasco
523704b83f
Execute middleware on Next.js internal requests (#37121)
* Do not exclude internal _next request in middleware

* Allow for `NextURL` to parse prefetch requests

* Add test for middleware data prefetch

* Refactor `hasBasePath` and `replaceBasePath`

* Refactor `removeTrailingSlash`

* Refactor parsed next url to use `getNextPathnameInfo`

* Allow to configure `NextURL`

* Ensure middleware rewrites with always with a locale

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-27 13:29:04 -05:00
Steven
0d95886815
Fix experimental remotePatterns wildcard (#37137)
- Follow up to #36245 
- Closes #37026
2022-05-25 20:25:06 +00:00
d-suke
13747476b8
should render the correct sizes passed when a noscript is rendered (#37161)
## Bug

- [x] Fixes #36807
- [x] Unit tests added

Please review this PR.

As shown in [this Issue](https://github.com/vercel/next.js/issues/36807), the noscript element does not render sizes correctly during SSR.
This change adds `noscriptSizes` to the props passed to `ImageElement` to generate the same `sizes` and `srcset` as the normal img tag that is actually rendered in the browser.
2022-05-24 19:25:05 +00:00
Sharath Challa
11ad65e445
Add eslint rule for not allowing styled-jsx in _document.js (#32678)
## Bug

- [ ] Related issues linked
fixes #32656



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-05-23 02:32:13 +00:00
Gáspár Körtesi
863db9b0e2
keep method when cloning Request, fixes #36522 (#36539)
keep method when cloning Request

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-22 12:58:17 -05:00
Sukka
87826ee186
fix(#33081): handle relative path correctly (#36823)
## Bug

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

Fixes #36823 
Closes #33084

The issue is caused by the `isLocalURL` function only checks if a URL starts with `/`, `#` or `?`. So a URL that starts with `.` will not be considered a "local URL". The PR fixes that by introducing a new util function `isAbsoluteUrl` that is fully compliant with [RFC3986](https://tools.ietf.org/html/rfc3986#section-4.3).
2022-05-22 16:43:48 +00:00
Javi Velasco
036ffa7057
Extract and refactor getPageStaticInfo (#37062)
Extract config parsing
2022-05-20 14:24:00 +02:00
Damien Simonin Feugas
bf089562c7
feat(middleware)!: forbids middleware response body (#36835)
_Hello Next.js team! First PR here, I hope I've followed the right practices._

### What's in there?

It has been decided to only support the following uses cases in Next.js' middleware:
- rewrite the URL (`x-middleware-rewrite` response header)
- redirect to another URL (`Location` response header)
- pass on to the next piece in the request pipeline (`x-middleware-next` response header)

1. during development, a warning on console tells developers when they are returning a response (either with `Response` or `NextResponse`).
2. at build time, this warning becomes an error.
3. at run time, returning a response body will trigger a 500 HTTP error with a JSON payload containing the detailed error.

All returned/thrown errors contain a link to the documentation.

This is a breaking feature compared to the _beta_ middleware implementation, and also removes `NextResponse.json()` which makes no sense any more.

### How to try it?
- runtime behavior: `HEADLESS=true yarn jest test/integration/middleware/core`
- build behavior : `yarn jest test/integration/middleware/build-errors`
- development behavior: `HEADLESS=true yarn jest test/development/middleware-warnings`

### Notes to reviewers

The limitation happens in next's web adapter. ~The initial implementation was to check `response.body` existence, but it turns out [`Response.redirect()`](https://github.com/vercel/next.js/blob/canary/packages/next/server/web/spec-compliant/response.ts#L42-L53) may set the response body (https://github.com/vercel/next.js/pull/31886). Hence why the proposed implementation specifically looks at response headers.~
`Response.redirect()` and `NextResponse.redirect()` do not need to include the final location in their body: it is handled by next server https://github.com/vercel/next.js/blob/canary/packages/next/server/next-server.ts#L1142

Because this is a breaking change, I had to adjust several tests cases, previously returning JSON/stream/text bodies. When relevant, these middlewares are returning data using response headers.

About DevEx: relying on AST analysis to detect forbidden use cases is not as good as running the code.
Such cases are easy to detect:
```js
new Response('a text value')
new Response(JSON.stringify({ /* whatever */ })
```
But these are false-positive cases:
```js
function returnNull() { return null }
new Response(returnNull())

function doesNothing() {}
new Response(doesNothing())
```
However, I see no good reasons to let users ship middleware such as the one above, hence why the build will fail, even if _technically speaking_, they are not setting the response body. 



## 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`
- [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

- [x] Make sure the linting passes by running `yarn lint`
2022-05-19 22:02:20 +00:00
Javi Velasco
f354f46b3f
Deprecate nested Middleware in favor of root middleware (#36772)
This PR deprecates declaring a middleware under `pages` in favour of the project root naming it after `middleware` instead of `_middleware`. This is in the context of having a simpler execution model for middleware and also ships some refactor work. There is a ton of a code to be simplified after this deprecation but I think it is best to do it progressively.

With this PR, when in development, we will **fail** whenever we find a nested middleware but we do **not** include it in the compiler so if the project is using it, it will no longer work. For production we will **fail** too so it will not be possible to build and deploy a deprecated middleware. The error points to a page that should also be reviewed as part of **documentation**.

Aside from the deprecation, this migrates all middleware tests to work with a single middleware. It also splits tests into multiple folders to make them easier to isolate and work with. Finally it ships some small code refactor and simplifications.
2022-05-19 15:46:21 +00:00
Kiko Beats
cc8ab99a92
Edge Cookies: Add .getWithOptions method (#36943)
Hello,

This is an iteration after first work at https://github.com/vercel/next.js/pull/36478.

What that PR missed is a way to just get a cookie value. Well, this PR adds two new things:

`cookies.get` returns the cookie value that could be `string | undefined`:

```js
const response = new NextResponse()
response.cookies.set('foo', 'bar', { path: '/test' })

const value = response.cookies.get('foo')
console.log(value) // => 'bar'
```

Additionally, if you want to know all the cookie details, you can use `cookies.getWithOptions`:

```js
const response = new NextResponse()

response.cookies.set('foo', 'bar', { path: '/test' })
const { value, options } response.cookies.getWithOptions('foo')

console.log(value) // => 'bar'
console.log(options) // => { Path: '/test' }
```
2022-05-19 13:04:58 +00:00
Hannes Bornö
4fd883f238
Remove optional chaining from eslint rule to support older node versions (#36978)
fixes #36693

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-05-17 17:09:31 +00:00
Shu Ding
b122178ead
Decouple entries for server components and client components (#36860)
* (wip)

* dev mode

* build mode

* update comment

* fix tests

* fix _N_SSP and _N_SSG exports

* fix missing variables

* fix api route bug

* fix compiler stats

* fix lint errors

* add extra cache group for edge server

* fix test

* fix test

* fix views route meta and entries

* fix linter error

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-13 19:48:53 +02:00
LongYinan
9e568dae24
Make esm default interpolation work with jest mock (#36877)
fixes https://github.com/vercel/next.js/issues/36794
2022-05-13 16:39:38 +00:00
Kiko Beats
b78c28f7a0
feat: better cookies API for Edge Functions (#36478)
This PR introduces a more predictable API to manipulate cookies in an Edge Function context.

```js
const response = new NextResponse()

// set a cookie
response.cookies.set('foo, 'bar') // => set-cookie: 'foo=bar; Path=/'`

// set another cookie
response.cookies.set('fooz, 'barz') // => set-cookie: 'foo=bar; Path=/, fooz=barz; Path=/'`

// delete a cookie means mark it as expired
response.cookies.delete('foo') // => set-cookie: 'foo=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT, fooz=barz; Path=/'`

// clear all cookies means mark all of them as expired
response.cookies.clear() // => set-cookie: 'fooz=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT, foo=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT'`
``` 

This new cookies API uses [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) interface, and it's available for `NextRequest` and `NextResponse`.

Additionally, you can pass a specific cookies option as a third argument in `set` method:

```js
response.cookies.set('foo', 'bar', {
  path: '/',
  maxAge: 60 * 60 * 24 * 7,
  httpOnly: true,
  sameSite: 'strict',
  domain: 'example.com'
}
```

**Note**: `maxAge` it's in seconds rather than milliseconds.

Any cookie manipulation will be reflected over the `set-cookie` header, transparently.

closes #31719
2022-05-09 09:50:32 +00:00
Steven
da8d1984d2
Add experimental wildcard remotePatterns config for upstream images (#36245)
## Description 
This PR implements a new configuration object in `next.config.js` called `experimental.images.remotePatterns`.

This will eventually deprecate `images.domains` because it covers the same use cases and more by allowing wildcard pattern matching on `hostname` and `pathname` and also allows restricting `protocol` and `port`.

## Feature

- [x] Implements an existing feature request.
- [x] Related issues linked
- [x] Unit tests added
- [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`

## Related 

- Fixes #27925 
- Closes #18429 
- Closes #18632
- Closes #18730
- Closes #27345
2022-05-05 02:19:16 +00:00
Javi Velasco
0de109baab
Refactor Page Paths utils and Middleware Plugin (#36576)
This PR brings some significant refactoring in preparation for upcoming middleware changes. Each commit can be reviewed independently, here is a summary of what each one does and the reasoning behind it:
- [Move pagesDir to next-dev-server](f2fe154c00) simply moves the `pagesDir` property to the dev server which is the only place where it is needed. Having it for every server is misleading.
- [Move (de)normalize page path utils to a file page-path-utils.ts](27cedf0871) Moves the functions to normalize and denormalize page paths to a single file that is intended to hold every utility function that transforms page paths. Since those are complementary it makes sense to have them together. I also added explanatory comments on why they are not idempotent and examples for input -> output that I find very useful.
- [Extract removePagePathTail](6b121332aa) This extracts a function to remove the tail on a page path (absolute or relative). I'm sure there will be other contexts where we can use it.
- [Extract getPagePaths and refactor findPageFile](cf2c7b842e) This extracts a function `getPagePaths` that is used to generate an array of paths to inspect when looking for a page file from `findPageFile`. Then it refactors such function to use it parallelizing lookups. This will allow us to print every path we look at when looking for a file which can be useful for debugging. It also adds a `flatten` helper. 
- [Refactor onDemandEntryHandler](4be685c37e) I've found this one quite difficult to understand so it is refactored to use some of the previously mentioned functions and make it easier to read.
- [Extract absolutePagePath util](3bc0783474) Extracts yet another util from the `next-dev-server` that transforms an absolute path into a page name. Of course it adds comments, parameters and examples.
- [Refactor MiddlewarePlugin](c595a2cc62) This is the most significant change. The logic here was very hard to understand so it is totally redistributed with comments. This also removes a global variable `ssrEntries` that was deprecated in favour of module metadata added to Webpack from loaders keeping less dependencies. It also adds types and makes a clear distinction between phases where we statically analyze the code, find metadata and generate the manifest file cc @shuding @huozhi 

EDIT: 
- [Split page path utils](158fb002d0) After seeing one of the utils was being used by the client while it was defined originally in the server, with this PR we are splitting the util into multiple files and moving it to `shared/lib` in order to make explicit that those can be also imported from client.
2022-04-30 11:19:27 +00:00
Tim Neutkens
f550da7031
Remove passhref Eslint rule as it's no longer needed with new link behavior (#36511) 2022-04-27 17:33:13 +02:00
Janicklas Ralph
0441f816a6
Changes to the beforeInteractive strategy to make it work for streaming (#31936)
Changes to the beforeInteractive strategy to make it work for streaming

Splitting `beforeInteractive` into two strategies `beforeInteractive` at the _document level and `beforePageRender` for page level <Scripts>
2022-04-21 21:15:53 +00:00
Kiko Beats
8f8e497e1b
fix(NextResponse.json): pass options (#35367) 2022-04-15 22:23:42 -05:00
Sukka
3ae571d97b
refactor(build): no force transpile optional chaining / nullish (#35976) 2022-04-15 21:48:43 -05:00
Michael Ward
1be5f36123
Adds linting rule to avoid assignment to 'module' variable. Fixes #34859 (#35279) 2022-04-15 14:45:53 +02:00
Naoyuki Kanezawa
1d8165bd79
fix: do not add locale prefix to api route on NextURL (#36118)
Fixes https://github.com/vercel/next.js/issues/35694

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-13 15:30:03 +00:00
Naoyuki Kanezawa
9805399faa
Revert "fix the dynamic routing of middleware" (#35932)
Reverts vercel/next.js#32601
2022-04-06 14:35:52 +00:00
JJ Kasper
4a7ab34baf
Update repo to use react 18 by default (#35888)
This updates our `yarn next` command to leverage react v18 by default and removes the need for the test require hook/config modifying when testing react 18. There are some fixtures we need to investigate react 18 support in follow-ups:

- `test/integration/client-navigation-a11y`
- `test/integration/critical-css`
- `test/integration/custom-error-page-exception`
- `test/integration/font-optimization`
- AMP specific tests
2022-04-05 21:51:47 +00:00
Donny/강동윤
fdfa3c7bae
feat(next-swc): Update swc crates (#35395)
* Update crates

* fixup

* fix type

* Update test refs

* Update css crates

* Update test refs

* Update test refs

* Update test refs

* SourceMap

* Fix?

* Update crates

* Fix

* Update test refs

* Update test refs

* Update error reporter

* Update snapshots

* Update snapshots

* Bug?

* Fix

* Fix lint

* Update swc again

* fixup

* Update test refs

* Fix

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
2022-03-30 15:13:40 -07:00
Jiachi Liu
d95d2d35c7
Only resolve page runtime for react 18 and error on read failure (#35705)
* Read the proper page file from either pages directory or from node_modules (inernal pages like _app, _document)
* Only reading page runtime when `reactRoot` is enabled, reduce time for react 17 apps
2022-03-30 20:21:41 +00:00
hiro
a00268e70f
Fix typos (#35683)
* fix(typo): wolrd -> world

* fix(typo): _lineNumer -> _lineNumber

* fix(typo): Dyanmic -> Dynamic

* fix(typo): mutliple -> multiple

* fix(typo): dyanmic -> dynamic

* fix(typo): speical -> special

* fix(typo): acceptible -> acceptable

* fix(typo): dyanmic -> dynamic

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): nonexistant -> nonexistent

* fix(typo): accesible -> accessible

* fix(typo): explicitely -> explicitly
2022-03-28 22:53:51 -05:00
Naoyuki Kanezawa
53d1b00c7f
fix the dynamic routing of middleware (#32601)
* fix the dynamic routing of middleware

* add middleware to dynamicRoutes of routes-manifest

* remove unused import

* fix middleware routing with static paths

* update manifest version test

* prevent to match with api route using regex

* use iterator instead of generator

* do not use Iterator

* fix type

* fix type

* remove unused import

* apply the fix for support colons

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-03-28 16:16:43 -05:00
Jiachi Liu
99aea513bf
enhance: cover re-exported gsp cases for runtime fallback (#35326)
Cover re-exported gsp cases from #35011
2022-03-15 13:14:18 +00:00
JJ Kasper
acbd54322f
Ensure mjs files are transformed with jest (#34698)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-03-09 13:49:58 +01:00