Commit graph

11741 commits

Author SHA1 Message Date
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
Max Proske
0f4333a5a3
chore(examples): Convert blog example to TypeScript (#38095)
Converted Blog example over to TypeScript to match the Contribution guidelines.

I also simplified the example by removing `_document.js` and prettier from `package.json`.

## 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-07-06 19:33:16 +00:00
Zane Chua
3b3d249c48
Update edge-runtime.md (#38271)
* Update edge-runtime.md

* Update docs/api-reference/edge-runtime.md

* fix linting

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-07-06 14:13:17 -05:00
Dustin Goodman
7f6b8ac7ee
fix: update with-msw example to function properly for all use cases (#38050) 2022-07-06 14:07:08 -05:00
Marius Jørgensen
3ae343fa90
Fix/update docs for swc styled components (#38280)
According to https://github.com/vercel/next.js/issues/30802 SWC transforms for `styled-components` were updated with support for `cssProp`, `fileName` and `namespace`. The docs only mention support for `ssr` and `displayName`.

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
2022-07-06 19:00:17 +00:00
Rishabh Poddar
b83107c38c
Updates with-supertokens example (#38369)
* add-supertokens-to-authentication.md

* bump supertokens deps

* update SuperTokens Auth doc

* Update docs/authentication.md

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

* Update docs/authentication.md

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

* updates supertokens dependency and optimises for serverless execution

* runs prettier-fix

* adds supertokens to 'Bring Your Own Database' section as well

* does not show home page if not logged in

* extracts config into its own file and calls it in all serverless functions

* removes need for backend init in app.jsx

* simplifies use of dynamic

* refreshes page after getServerSideProps

* removes unnecessary check in API

* update to docs pertaining SuperTokens

* adds placeholder secrets so that the UI loads on first run

* changes to readme

* updates version of supertokens frontend and backend SDK, and a few other fixes

* Update docs/authentication.md

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

* updates to readme for supertokens example

* updates version of dependency

* updates dependency version

* updates to dependencies

* removes unnecessary config on frontend

* changes how redirection is done post signout

* update to dependency

* updates examples

* updates code to use for new package

* updates dependencies

* updates auth-react package

* with-supertokens example updated to use supertokens-node v7

* updates dependency

* updates supertokens-node version

* Update examples/with-supertokens/package.json

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

* updates based on check-examples.sh script

* linter fix

* updates supertokens-auth-react dependency version

* adds development OAuth key to example

* removes section from README

* removes unnecessary file

* updates dependency versions

* with-supertokens: reduced bundle size by removing node lib from bundle

Linting fix

* Removed accidentally added config file

* adds sign in with apple

* extracted oauth keys to .env file

* fixes node init issue race condition

* removes unnecessary file

* updates supertokens-auth-react dependency

* updates superttokens-node dependency

* adds a cap to react dependency

* updates eslint-config-next version

* removes unnecessary dev dependency

* updates to latest version of supertokens-auth-react SDK

* Updated nextjs in supertokens example

* Update examples/with-supertokens/package.json

* Update examples/with-supertokens/package.json

* Update package.json

* Update examples/with-supertokens/package.json

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* Update examples/with-supertokens/package.json

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* updates to supertokens-auth-react version

* feat: update&improve ssr in with-supertokens

* refactor: implement review feedback

* refactor: moved everything into ProtectedPage to make Auth component usage clearer

* refactor: implement review feedback

* updates dependency version and uses nextjs router for navigation

* removes prettier dendency in with-supertokens example app
2022-07-06 13:47:21 -05: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
Shu Ding
f396988824
Add more CSS imports test cases (#38343)
## 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-06 17:57:35 +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
JJ Kasper
9573174196
Replace pre-commit with husky (#38350)
* Replace pre-commit with husky

* update lock

* actually update lock
2022-07-06 11:14:16 -05: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
Steven
fb8686055a
Revert "chore: remove workspace from package.json since we have `pnpm-works…" (#38376)
Revert "chore: remove workspace from `package.json` since we have `pnpm-works… (#38166)"

This reverts commit a37abc62ee.
2022-07-06 17:08:00 +02:00
Yohann MARTZOLFF
27bfdec1ea
Add example: with-apivideo-upload (#36050)
* feat(app): Landing

* feat(index): Add button to video view

* Remove React stric mode

* feat(index): Handle navigate with query params

* feat(app): Create common style

* feat(app): Video view

* feat(video view): Add footer

* feat(app): Add .env

* feat(index): Hide upload button on progress

* Update pages type

* Change MyApp props type

* feat(index): Add prod domain for fetching

* update(app): CSS

* update(index): Domain name

* feat(index): Remove getSSProps

* Update README

* Update README

* update(status): CSS

* feat(index): Add link to GitHub repo

* Remove static API key from .env

* Lint

* update(packages): next version

* Lint + Prettier

* Remove name & version from package.json

* update: Rename .env.development -> .env.local.example

* update: Remove esLint + updagrade React & ReactDOM version

* Remove yarn.lock changes

Co-authored-by: José Barcelon-Godfrey <jose.barcelon@gmail.com>
2022-07-06 16:35:49 +02:00
Anjorin Damilare
a37abc62ee
chore: remove workspace from package.json since we have `pnpm-works… (#38166)
chore: remove workspace from `package.json` since we have `pnpm-workspace`
2022-07-06 16:26:20 +02: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
Winme
58070c654a
Remove CharkraProvicer RestCSS prop (#38199)
See the charkra-ui offical docs [ChakraProvider component](https://chakra-ui.com/getting-started/cra-guide#chakraprovider-props), `resetCSS` default value now is `true`, So there is no need to add this prop again
2022-07-06 13:46:22 +00:00
Armand Abric
fa1261cbfb
Fix typo in SWC plugin destructuring example (#38367)
## 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: Balázs Orbán <18369201+balazsorban44@users.noreply.github.com>
2022-07-06 13:39:36 +00:00
Max Proske
88038ca21f
chore(examples): Convert api-routes-middleware example to TypeScript (#38358)
Convert `api-routes-middleware` example to TypeScript to match Contribution docs.

- Updated cookie util to match the [extending `res`  with TypeScript Next.js docs](https://nextjs.org/docs/api-routes/api-middlewares#connectexpress-middleware-support)

## 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-07-06 13:33:55 +00:00
Max Proske
5145c2d5e2
chore(examples): Convert api-routes-cors example to TypeScript (#38356)
Convert `api-routes-cores` example to TypeScript to match Contribution docs.

- Update CORS configuration to match the [middleware Next.js docs](https://nextjs.org/docs/api-routes/api-middlewares#connectexpress-middleware-support)
- Allow POST requests as per instructions in `index.tsx`: "make a **POST** / GET / OPTIONS request to /api/cors"

## 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-07-06 13:12:40 +00:00
Jeff Mendez
616e0d7ee8
chore(examples): fix experiments loading npm wasm (#38348)
* enables default config that handles npm wasm bundles



## 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 13:05:14 +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
Ryan "Haticus" Huellen
20c1079e96
Clarification for Testing Environment Variables (#38359)
## 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)

## The Issue
When it came to testing environment variables with jest in the current release of NextJS, I ran into an issue where my variables were seemingly undefined for no reason. With some research and the help from a friend in discussion post #38353 it was determined further configuration steps were needed in relation to the environment variables for jest. At the time being, no direct link is made between [Setting up Jest](https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler) and [Test Environment Variables](https://nextjs.org/docs/basic-features/environment-variables#test-environment-variables).

## The Change
This fix provides further clarification on the issue by creating a new link within the note on the [Setting up Jest](https://nextjs.org/docs/basic-features/environment-variables#test-environment-variables) page. Moreover, further explanations were added to ensure developers understand the `test` environment is completely separate from both `development` and `production` meaning files like `.env.development` and `env.prodution` won't be recognized when testing.

## Supporting Documentation
This is an issue time and time again for developers. Not only have I experienced this, but others have asked on both [GitHub Discussions](https://github.com/vercel/next.js/discussions/16270) and [StackOverflow](https://stackoverflow.com/questions/63934104/environment-variables-undefined-in-nextjs-when-running-jest/67997819#67997819). Moreover, many of the solutions from 2020 no longer work properly.

I hope this is sufficient enough for a contribution to the documentation. Minor improvements like these create the ideal developer experience Next.js is known for. :)


Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2022-07-06 02:39:11 +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
Cupid Valentine
9f162cc812
Update analysis scripts (#38201) 2022-07-05 15:04:54 -05:00
Cupid Valentine
09fdf9ada1
Update get-static-props.md (#38287)
## 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-05 19:50:49 +00:00
JJ Kasper
bcf4802b1f
Update some flaking tests for edge compiler and rsc (#38344) 2022-07-05 14:37:42 -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
Lee Robinson
a5e11612c7
Update next/future/image docs to specify supported browser versions. (#38307)
This adds more specificity to what browsers are supported for the underlying web-native features.
2022-07-05 13:49:04 +00:00
Riccardo Giorato
49129e7860
fix(examples): fix link on middleware example (#38323)
## 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-07-05 13:16:34 +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
Balázs Orbán
e6bad25b5e chore: fix issue validator paths 2022-07-04 13:54:20 +02:00
Balázs Orbán
ef1ebb4a82
chore: point to /dist for local action 2022-07-04 13:49:10 +02:00
Eduardo Sigrist Ciciliato
7664a40064
feat(examples): adds middleware example (#38240)
## 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)


Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2022-07-04 03:45:56 +00:00
Carsten Lebek
beaa4df9fc
Typo in NextResponse docs (#38259)
## 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-03 22:18:41 +00:00
Emerson Laurentino
6b8e499c7b
fix: middleware-upgrade-guide.md (#38246)
* Update middleware-upgrade-guide.md

* Update middleware-upgrade-guide.md
2022-07-01 22:24:34 -05: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