Commit graph

11118 commits

Author SHA1 Message Date
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
Steven
7998b63a38
Fix missing Content-Length header from Image Optimization API (#36581)
Fixes #35514
2022-04-30 01:50:42 +00:00
JJ Kasper
c838b5f50d
v12.1.6-canary.15 2022-04-29 11:54:57 -05:00
Houssein Djirdeh
fd2ba11763
Adds inline script functionality to next/script for worker and beforeInteractive strategies (#36364)
Adds inline script functionality to `next/script` for `worker` and `beforeInteractive` strategies. 

- fixes #36318 
- fixes #26343
- fixes #26591
- fixes #26343
- fixes #26240


Co-authored-by: Janicklas Ralph <6142074+janicklas-ralph@users.noreply.github.com>
2022-04-29 15:20:31 +00:00
JJ Kasper
e30d7237ef
Ensure older lockfile/invalid formats are handled (#36577) 2022-04-29 09:42:48 -05:00
Balázs Orbán
486040eff2
chore: clarify CLI network errors (#36567)
Makes it easier to detect why a network error occurred with the CLI or `next info`, based on https://github.com/vercel/next.js/issues/36344

## 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-04-29 12:39:17 +00:00
Adam Tolley
67a619ea64
Add note about running next without a sub-command (#36560)
This should be made explicitly clear because other code may just call `next` instead of `next dev` (e.g. https://github.com/netlify/framework-info/blob/main/src/frameworks/next.json).

Being in the ninth circle of debug hell right now I could not take it for granted that the two were the same till I saw some kind of confirmation, either from the docs or from the source.  Source is great, but calling it out in the docs would saved me some time.



## 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-04-29 02:57:48 +00:00
Jiachi Liu
ea779c5188
bump styled-jsx to latest (#36554)
x-ref: https://github.com/coryetzkorn/twitter-algorithm/pull/2

* Bump styled-jsx to latest version (5.0.2), so that it could get dedup when user installs the styled-jsx manually
* Remove the legacy `@types/styled-jsx`
2022-04-28 21:12:58 +00:00
Jiachi Liu
cd7419e9c8
Hoist the desired ReactDOM import expression (#36552)
* hoist `react-dom/server` imports to reduce module load time in nodejs
* simplify `reactRoot` detection condition by checking the streaming rendering API we're using. (if it doesn't existed, like react 17, then we won't enable `reactRoot`)
* Merge `__NEXT_CONCURRENT_FEATURES` into `__NEXT_REACT_ROOT` env var since they're identical now
2022-04-28 19:17:23 +00:00
JJ Kasper
244456936b
v12.1.6-canary.14 2022-04-28 13:34:45 -05:00
Balázs Orbán
f000503984
unlock eslint-config-next dependencies (#35781)
Fixes #35753

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-04-28 17:15:58 +00:00
JJ Kasper
60f74230fe
Tweak lockfile patching to be eager (#36549)
This is a follow-up to https://github.com/vercel/next.js/pull/36527 to make sure we eagerly patch the lockfile as the correct swc dependency will be present if the platform matches so the load failure isn't hit which is where we were previously patching the lockfile. This is done in the background so does not block compilation. This also removes some extra logs that aren't necessary. 

<details>

<summary>before lockfile patch</summary>

![before](https://user-images.githubusercontent.com/22380829/165780507-09e5aee6-3253-483f-9e3f-e24bea6df377.png)

</details>


<details>

<summary>after lockfile patch</summary>

![after](https://user-images.githubusercontent.com/22380829/165780545-829665aa-05ec-431d-aa2f-42c4ce3badd7.png)

</details>

This also fixes a case I noticed where we weren't flushing events before exiting when builds fail
2022-04-28 16:40:37 +00:00
Shu Ding
4392b6a9fa
Refactor base server to get rid of the __server_context hack (#36550)
This PR makes the `Options` type of base server configurable as well as assigning to `this.serverOptions`, so the web server can access it during `constructor()`. This gets rid of the dirty `__server_context` hack.

## 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-04-28 16:16:51 +00:00
Lazar Nikolov
cc35859fe7
docs(examples): Updated Chakra UI examples (#36333)
## Overview

This PR updates both Chakra UI examples by updating the Chakra UI packages to the latest versions, and added better examples for Semantic Tokens (new feature in Chakra UI), and pseudo props.

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`


Co-authored-by: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
2022-04-28 12:36:33 +00:00
Donny/강동윤
38aa6d7140
Update swc (#36535)
This PR updates swc to a72f436148


This PR applies

 - https://github.com/swc-project/swc/pull/4452
   - Fixes `yield*` of async generators in async generators.
   - Fixes name mangling of injected helpers.
     - Note: This only applies to tiny files which enables lots of helpers.
 - https://github.com/swc-project/swc/pull/4468
   - Fixes newer version of react.
2022-04-28 10:14:48 +00:00
Tim Neutkens
0b0b5ca75c v12.1.6-canary.13 2022-04-28 11:33:17 +02:00
Tim Neutkens
2451f52bc8
Add support for passing ref to next/link with new behavior enabled (#36537) 2022-04-28 11:32:32 +02:00
Donny/강동윤
3aa8aaae58
next-swc/wasm: Make span start at 0 (#36532) 2022-04-28 11:31:43 +02:00
JJ Kasper
917a736a55
Add event for swc load failure and attempt patching lockfile (#36527) 2022-04-28 11:31:15 +02:00
Jiachi Liu
ea81df0a83
Bump react dev dep to 18.1 (#36491)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-04-28 11:29:30 +02:00
LongYinan
3ee42236d5
Align behavior of SWC transform & transformSync (#36500)
fixes https://github.com/vercel/next.js/issues/35661



## Bug

- [x] 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.
- [x] 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-04-28 02:09:49 +00:00
JJ Kasper
9168b386ce
Normalize font optimization snapshot to reduce flakes (#36531) 2022-04-27 19:28:11 -05:00
Mohamed ElSaadany
e4f66fe911
Adds <link rel="preconnect" ... /> to example optimized font output (#36529)
This makes it clear that the font optimization adds these for you.
This avoids duplicate `<link rel="preconnect" />` in the HTML output if the developer is unaware that it is being added automatically.



## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-04-28 00:04:18 +00:00
Lee Robinson
ea0456dc07
Add docs on self-hosted ISR persisting across pods. (#36520)
ISR works self-hosted, but there's some more guidance needed when hosting with container-based setups (e.g. Kubernetes) and how the files are shared between different pods. This was based on community feedback. Please let me know if you'd like to see any additions here! 🙏
2022-04-27 23:38:08 +00:00
Alex Castle
93d8fac184
Always add height and width prop to image with layout="raw" (#36523)
This PR makes the following changes:
* Always add the `height` and `width` prop to image with `raw` layout (previously only added to images without `sizes`)
* Add a warning if a raw layout image is getting stretched (which can be caused by interaction of height and width prop with styles)
* Remove automatic aspect-ratio style from `raw` images. This is no longer necessary if all `raw` images have height and width props.
* Update tests and docs accordingly
2022-04-27 21:59:05 +00:00
JJ Kasper
af1d7c94f6
v12.1.6-canary.12 2022-04-27 14:23:09 -05:00
JJ Kasper
d66445f800
Ensure optional params are normalized correctly in minimal mode (#36513)
Follow-up for https://github.com/vercel/next.js/pull/36463 this fixes an issue with optional catch-all params not being normalized correctly which was caught by the runtimes tests. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-27 18:46:33 +00:00
Jiachi Liu
e9b423b37c
polish isomorphic path module (#36521)
List all exports for internal path module to avoid import destruction is breaking with typescript.

#### Prev
```js
import pathMod from '../isomorphic/path'

const { join, resolve } = pathMod
```

#### Now
```js
import { join, resolve } from '../isomorphic/path'
```
2022-04-27 18:23:26 +00:00
JJ Kasper
2fc27c1ec7
Update rewrite destination for flakey rewrite tests (#36519)
* Update rewrite destination for flakey rewrite tests

* update other test
2022-04-27 13:04:16 -05:00
Colin McDonnell
842e4ec023
Add with-edgedb example (#35929)
## Documentation / Examples
 
- [X] Make sure the linting passes by running `yarn lint`
2022-04-27 16:49:17 +00:00
JJ Kasper
89a4c1626b
Remove extra yarn PnP example test (#36518) 2022-04-27 11:41:34 -05:00
Tim Neutkens
5e3225da0f v12.1.6-canary.11 2022-04-27 18:40:33 +02:00
Tim Neutkens
c232d3856a
Add string children case for newNextLinkBehavior codemod (#36516) 2022-04-27 18:39:56 +02:00
Tim Neutkens
5907e9d394 v12.1.6-canary.10 2022-04-27 17:34:18 +02: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
JJ Kasper
51bdd97033
Fix failing yarn PnP test from missing dependency (#36515) 2022-04-27 17:32:44 +02:00
Rafo
0cb2037a41
[examples] Update styled-components with Babel - add types (#36125)
This PR is looking forward to improve documentation exemples about usage of Next.js with Typescript and Styled-components. 

I added Typescript types to the original exemple [Example app with styled-components using babel
](https://github.com/vercel/next.js/tree/canary/examples/with-styled-components-babel)

## Feature

- [x] Related issues linked using 
- [x] Documentation added

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`

fixes #36008
2022-04-27 12:43:06 +00:00
Mohamed Achaq
fca1071941
Adding Typescript and Mantine example (#36294)
## 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 `yarn lint`
2022-04-27 12:36:04 +00:00
Donny/강동윤
f2c3ef8318
Update swc (#36477)
* Update

* Update swc

* Update again

* Fix

* log

* Fix

* clippy

* Update

* Fix
2022-04-27 14:28:46 +02:00
Balázs Orbán
04e887b9d1
docs: clarify triaging (#36507) 2022-04-27 13:52:57 +02:00
Javi Velasco
0bf6655f1c
Use edge compiler for middleware (#36486)
* Refactor `path-match`

* Simplify `createPagesMapping`

* Rename `getRawPageExtensions` -> `withoutRSCExtensions`

* Remove unused `functions-manifest-plugin.ts`

* Enable `eval-source-map` for the edge server compiler

* Use Edge Compiler for Middleware & Refactor

* Update some comments

Co-authored-by: JJ Kasper <jj@jjsweb.site>

Update packages/next/shared/lib/router/utils/path-match.ts

Co-authored-by: JJ Kasper <jj@jjsweb.site>

Update packages/next/shared/lib/router/utils/path-match.ts

Co-authored-by: JJ Kasper <jj@jjsweb.site>

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-04-27 11:50:29 +02:00
Jiachi Liu
e7b17133c5
Support swc parse api in WASM (#36482)
* Add `parseSync` in swc WASM binding
* Support no native binding mode for react 18 next apps which are using `NODE_OPTIONS='--no-addons'` flag
* Workaround: adding minus begining position back for wasm loader since the span isn't starting from zero
2022-04-27 00:59:02 +00:00
JJ Kasper
a16fa39291
Update font-optimization test snapshot (#36492)
Fixes failing test case due to upstream font CSS change. 

x-ref: https://github.com/vercel/next.js/pull/36482#issuecomment-1110313267
2022-04-27 00:30:33 +00:00
JJ Kasper
743cf68555
Pass nextRuntime in webpack context (#36488)
Follow-up to https://github.com/vercel/next.js/pull/36383 this also exposes the `nextRuntime` for the custom webpack function in `next.config.js` to allow differentiating between the environments. 

x-ref: https://vercel.slack.com/archives/CGU8HUTUH/p1647866770704939
2022-04-26 21:05:40 +00:00
JJ Kasper
90863c70ea
v12.1.6-canary.9 2022-04-26 15:14:22 -05:00
JJ Kasper
4f5c2deb4c
Add note about lockfile causing swc to fail to load (#36484)
* Add note about lockfile causing swc to fail to load

* Apply suggestions from code review

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
2022-04-26 14:48:52 -05:00
JJ Kasper
e44256978a
Update manual revalidate response cache handling (#36462)
This updates to ensure we only resolve a manual revalidate request when the cache has been fully set instead of eagerly like we do for generating pages in `fallback` mode. This also ensures the response cache keys manual revalidate requests separate from normal requests to ensure one doesn't block the other. This should resolve the below flakey tests.  

x-ref: https://github.com/vercel/next.js/runs/6163218261?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/6157328196?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/6151165153?check_suite_focus=true
2022-04-26 19:32:29 +00:00
JJ Kasper
7e7d7bbca6
Fix incorrect asPath with fallback rewrite in minimal mode (#36463)
This continues off of the change in https://github.com/vercel/next.js/pull/36368 and ensures a fallback rewrite does not influence the `asPath` as these are only matched when a filesystem or dynamic route aren't matched. 

## Bug

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

x-ref: https://github.com/vercel/next.js/pull/36368
2022-04-26 19:12:29 +00:00
Jiachi Liu
d5e767b20d
Add process env NEXT_RUNTIME (#36383)
* To help determine the current running environment is in server nodejs / edge runtime
* Remove usage of `process.browser`
2022-04-26 17:54:28 +00:00
Sukka
487f7ababa
fix(#36435): apply correct fix (#36464)
* fix(#36435): apply correct fix

* fix: only apply interop default flag for re-exported

I really, really love glob.

* test: add test cases for next/dynamic and next/amp
2022-04-26 11:15:49 -05:00