Commit graph

350 commits

Author SHA1 Message Date
Jiwon Choi
022cb25640
fix(eslint): next/script beforeInteractive gives warning on appDir (#51148)
## Issue

The `context.getFilename()` gets the absolute path of the files, and the if statement to filter `/src` and `/app` was not working since #46609.

## Expected

Do not show a lint warning if use `beforeInteractive` inside `appDir`.

Fixes #46609 #50261
2023-11-12 09:30:10 +00:00
Wyatt Johnson
3fa9f31ce1
fix: updates for resuming postponed in minimal mode (#57375)
Co-authored-by: Jimmy Lai <11064311+feedthejim@users.noreply.github.com>
2023-11-03 21:17:45 +00:00
Wyatt Johnson
13f0303085
Reduce FS access for incremental cache (#57902)
This passes down the route kind information to the incrememntal cache so it no longer needs to test some files existing in order to validate if the file exists or not for a route.
2023-11-01 21:17:16 +00:00
Balázs Orbán
4c46ddd92a
chore: drop undici (#56899)
### What?

Note: This is not a breaking change, just removing some unused code.

### Why?

Since #56896 we don't need this, as Node.js 18+ has `fetch` exposed by default.

### How?

Depends on #56896, #56909

We already didn't load `fetch` if `globalThis` had it (ie. Node.js 18+ environments), and since we are dropping support for Node.js 16, these code paths should have no effect on runtime behavior.
2023-10-19 18:35:12 +00:00
Balázs Orbán
33db463fe4
chore: upgrade jest (#56909)
### What?

Upgrade jest to its latest version

### Why?

#56899 fails because historically Jest stripped the globals in Node.js, but 28+ isn't doing that anymore. If we upgrade, we don't have to keep track of Node.js globals and when they are added. This will be useful in removing even more polyfills for things that are natively shipped in Node.js now.

### How?

Jest 29 introduced a change to the snapshot format: https://jestjs.io/blog/2022/08/25/jest-29

First, I tried setting the old compat option to not require updating snapshots, but some tests were still failing: https://dev.azure.com/nextjs/next.js/_build/results?buildId=70633&view=logs&j=8af7cf9c-43a1-584d-6f5c-57bad8880974&t=7ae70e63-3625-50f4-6764-5b3e72b4bd7a&l=273 So going through the pain now instead.
2023-10-19 17:38:24 +00:00
Tim Neutkens
59bda2d818
More Turbopack fixes (#56299)
Skips additional production-only tests.

Follow-up to #56089.

In this PR I went through all of `test/integration` looking for `nextBuild(` and added the skipping logic.
2023-10-02 13:55:23 +00:00
Jiachi Liu
b3e95edab4
Warn experimental.appDir option can be removed (#55346)
We have dropped `experimental.appDir` option, to share the insights that can be removed, add a warning `"App router is enabled by default now, <experimental.appDir> option can be safely removed.'" `
2023-09-13 23:38:17 +00:00
Jiachi Liu
14e94e69c5
fix duplicated error logging when start server (#55328)
There're few places calling `loadConfig` to access nextjs config for different purpose, and every of them will do validation of next config scheme and could log the warnings potentially to cause duplicated warnings. To address that issue this PR limit the places when should the warnings be logged in certain places, mainly the `next` command entry. Refactor the API here to make it more explicit

Previous logging redeisgn also might trigger duplicated compilation, for instance you compiled page A but then editing another component it might still displaying page A is recompiled. Now we always display `"Compiled .."` message when there's a recompilation but avoid the unnecessary ones such as initial edge compilor ready but there's no modules inside. Then when it recompiles or recovers from error nextjs server will tell "Compiled .." instead of the specific page which might be not related.

Also refactors a minor issue: When `silent` option is set to `true`, auto recorrect next config option from `loadConfig` API like `traillingSlash` is not working

Closes NEXT-1610

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-13 22:25:41 +00:00
Jiachi Liu
e117c000e4
Redesign nextjs logging (#54713)
The current logging styles has been existed for a while, this PR gives a fresh impression for the logging output from Next.js.
We want to achieve few new goals that makes the output clean, modernized, sweet 🍫 .

Few goals are addressed with this redesign:

## Refresh Impression & Simplification

The new design of logging is much more information centralized and streamlined.

* Given a `ready` message at the begining when compilers are bootstrapped.
* Only show `compiled` event with green check mark indicating succesful compilation, this will merge the unclear `compiling` event which shows `(client and server)` before, now tell you the route compilation info in one line.

hello world app

### `next dev`

#### After vs Before


<img src="https://github.com/vercel/next.js/assets/4800338/9649b340-8241-4756-a2b3-a989f0b74003" height="120"> 
<img src="https://github.com/vercel/next.js/assets/4800338/ee181263-3dd4-40d0-9ffc-819a56b45900" height="120">  

 


 

### `next build`

#### After vs Before


<img src="https://github.com/vercel/next.js/assets/4800338/5db9829a-9ffc-49f0-b030-93ee92f5c248" width="360"> 
<img src="https://github.com/vercel/next.js/assets/4800338/b9527b83-27c8-4426-9c0d-c0d4072b7d58" width="360">





### error status

#### After vs Before

<img src="https://github.com/vercel/next.js/assets/4800338/00455226-ace7-468b-8d90-0d36bf038489" height="120"> 
<img src="https://github.com/vercel/next.js/assets/4800338/1be8c451-d3f0-465c-9ef7-6b0dde7cff85" height="120"> 



## Streamlization

If you have customized envs and experiments Next.js will give the brief in the early summary about your network information, env vars, and enabled experimental features

<img src="https://github.com/vercel/next.js/assets/4800338/ca1a7409-1532-46cb-850f-687e61e587b2" width="400">


## Polish

### fetching logging structure 

#### After vs Before
<img src="https://github.com/vercel/next.js/assets/4800338/97526397-dffe-4736-88ed-e5cbe5e945bd" width="400">
<img src="https://github.com/vercel/next.js/assets/4800338/ab77c907-5ab5-48bb-8347-6146d2e60932" width="400">


### Dedupe Duplicates

The logging is moved from `@next/env` to `next` itself, `@next/env` will only notify the invoker that the env is reloaded. Then the duplicated logs for the env reloading cases can be avoid.

#### After vs Before
<img src="https://github.com/vercel/next.js/assets/4800338/04799295-e739-4035-87aa-61cec962fc39" width="400">
<img src="https://github.com/vercel/next.js/assets/4800338/e29020c9-0031-4bf3-a21b-8b64633f43a2" width="400"> 


### Different indicators

Use unicode text icons for different situation: 
* passed -> check mark
* warning -> warning
* error -> red cross
* loading -> circle

<img src="https://github.com/vercel/next.js/assets/4800338/715c34bd-298f-4990-a5d7-e12e455ead44" width="400">



Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-09-05 11:40:00 +00:00
JJ Kasper
2eef775472
Update tag handling for app cache (#53321)
Optimizes how we handle cache tags for soft tags (auto-added by Next.js)
and normal tags (added manually) and adds differentiating between
`revalidatePath('/blog/first')` and page/layout.

Soft tags are not stored across cache entry and instead auto sent along
when checking cache entries. This allows us to prevent storing
exponential amounts of tags across cache entries while still having the
relationship between them so that single path revalidation can work
properly.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1690586837903309)
2023-08-31 15:17:40 -07:00
Max Leiter
4c3b7f9b7a
Export RedirectType from next/navigation (#54729)
A continuation of #51864 with RedirectType used in an e2e test and some
ts-ignores removed from the codebase. Happy to split it into two PRs but
I left comments in the two consequential files

---------
2023-08-29 11:05:44 -07:00
Wyatt Johnson
0f822373ee
File Reader Improvements (#54645)
This replaces the existing recursive directory reading beheviour with a more efficient implementation. Rather than previously doing actual recursion with the function calls to go deeper into each directory, this has been rewritten to instead use a while loop and a stack. This should improve memory usage for projects with very deep directory structures. 

The updated design that performs directory scanning on all directories found at each layer, allowing more filesystem calls to be sent to the OS instead of waiting like the previous implementation did.

**Currently the new implementation is about 3x faster.**
2023-08-28 18:09:56 +00:00
Jiachi Liu
1e3920c3dd
Upgrade precompiled ua-parser-js (#54404)
Upgrade `ua-parser-js` which is used by `userAgentFromString` to latest version

Closes NEXT-1552
2023-08-22 23:56:05 +00:00
Balázs Orbán
af97755e3c
fix(edge): override init when cloning with NextRequest (#54108)
### What?

When cloning a `Request` with `NextRequest` the second argument needs to take precedence over the `Headers` set on the original request.

### Why?

Follow-up of #53157

I checked the `Request` spec https://fetch.spec.whatwg.org/#request-class and following the order of execution, `init.headers` should indeed override the headers if the first param was `Request`.

I verified this in the browser too:

```js
const req1 = new Request("http://n", {headers: {"x-header": "foo"}})
const req2 = new Request(req1, {headers: {"x-header-2": "bar"}})
Object.fromEntries(req2.headers) // {x-header-2: "bar"}
```

So we should match `NextRequest` with this behavior.

### How?

Pass the `init` to `super` when cloning the request.

Closes NEXT-1521
Fixes #54094
2023-08-16 18:54:35 +00:00
Matt Cowley
c1fa78bf6c
fix(next/image): empty blur image when animated (#54028)
Partial fix for #54012: do not generate a blur image in the image loader when the image is detected to be animated, rather than returning the *entire* animated image as the blur image.
2023-08-15 02:17:40 +00:00
Ngô Đức Anh
a4b430e6f1
Better IPv6 support for next-server (#53131)
### What?
This PR makes it easier to use Next.js with IPv6 hostnames such as `::1` and `::`.

### How?
It does so by removing rewrites from `localhost` to `127.0.0.1` introduced in #52492. It also fixes the issue where Next.js tries to fetch something like `http://::1:3000` when `--hostname` is `::1` as it is not a valid URL (browsers' `URL` class throws an error when constructed with such hosts). It also fixes `NextURL` so that it doesn't accept `http://::1:3000` but refuse `http://[::1]:3000`. It also changes `next/src/server/lib/setup-server-worker.ts` so that it uses the server's `address` method to retrieve the host instead of our provided `opts.hostname`, ensuring that no matter what `opts.hostname` is we will always get the correct one.

### Note
I've verified that `next dev`, `next start` and `node .next/standalone/server.js` work with IPv6 hostnames (such as `::` and `::1`), IPv4 hostnames (such as `127.0.0.1`, `0.0.0.0`) and `localhost` - and with any of these hostnames fetching to `localhost` also works. Server Actions and middleware have no problems as well.

This also removes `.next/standalone/server.js`'s logging as we now use `start-server`'s logging to avoid duplicates. `start-server`'s logging has also been updated to report the actual hostname.
![image](https://github.com/vercel/next.js/assets/75556609/cefa5f23-ff09-4cef-a055-13eea7c11d89)
![image](https://github.com/vercel/next.js/assets/75556609/619e82ce-45d9-47b7-8644-f4ad083429db)
The above pictures also demonstrate using Server Actions with Next.js after this PR.
![image](https://github.com/vercel/next.js/assets/75556609/3d4166e9-f950-4390-bde9-af2547658148)

Fixes #53171
Fixes #49578
Closes NEXT-1510

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-08-14 07:23:24 +00:00
JJ Kasper
6b492974b7
Move next-rs API tests from unit to e2e (#53771)
These tests aren't unit per-se as they rely on e2e-utils so this moves
them to the `development` test folder.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1691520079363229)
2023-08-08 21:50:04 -07:00
Tobias Koppers
9d1b3f43a1
Turbopack: add hmr test case and fix bugs (#53719)
### What?

test case for HMR

### Turbopack Changes

* https://github.com/vercel/turbo/pull/5686 <!-- Tobias Koppers - remove
error in update -->
2023-08-08 17:07:24 +02:00
Tobias Koppers
654bd8c803
add unit test case for next.rs api (#53679)
### What?

unit test for next.rs api

### Why?

ensure that it's working

### How?
2023-08-07 19:26:44 +02:00
JJ Kasper
975fb1f466
Fix windows unit tests (#53412)
Fixes differences in tests to handle windows now that we've fixed them
not being run.

x-ref:
https://github.com/vercel/next.js/pull/53408/checks?check_run_id=15501915673
2023-07-31 18:06:18 -07:00
Balázs Orbán
e1133cf097
fix(edge): allow Request cloning via NextRequest (#53157)
### What?

Allow the following:

```ts
new NextRequest(new Request(...))
```

### Why?

Cloning a request by passing it to the constructor of another `Request` is allowed by the spec: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#parameters

### How?

If the passed argument is an instance of `Request`, we pass it as-is to `super()`

Fixes #52967
Closes NEXT-1468
2023-07-25 11:36:39 +00:00
Steven
c3ca17cf02
fix: add missing <preload> for next/image in App Router (#52425)
- Depends on https://github.com/facebook/react/pull/27096
- Fixes #43134 
- Closes NEXT-811
- Closes NEXT-846
2023-07-14 15:36:35 +00:00
Jiachi Liu
dfe08aed33
Fix NextRequest constructor parameters (#52001)
FIx the type change introduced in #51727
2023-06-29 22:50:53 +00:00
Jiachi Liu
f4b947fb56
Fix eslint async client component (#51952)
Fixes #51917 

It's throwing error in arrow function, should also be covered in the
lint rule
fix NEXT-1326
2023-06-28 20:03:32 -07:00
Steven
946c9c5c46
Add unstable_getImgProps export from next/image (#51205)
### Description 

This PR refactors the Image component so that the core logic can be consolidated into a single function.

This allows usage outside of `<Image>`, such as:

1. Working with [`background-image`](https://developer.mozilla.org/en-US/docs/Web/CSS/background-image) or [`image-set`](https://developer.mozilla.org/en-US/docs/Web/CSS/image/image-set)
2. Working with canvas [`context.drawImage()`](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Using_images) or simply `new Image()`
3. Working with [`<picture>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) media queries to implement Art Direction or Light/Dark Mode images

### Example

```tsx
import { unstable_getImgProps as getImgProps } from 'next/image'

export default function Page() {
  const common = { alt: 'Hero', width: 800, height: 400 }
  const { props: { srcSet: dark } } = getImgProps({ ...common, src: '/dark.png' })
  const { props: { srcSet: light, ...rest } } = getImgProps({ ...common, src: '/light.png' })

  return (<picture>
  <source media="(prefers-color-scheme: dark)" srcSet={dark} />
  <source media="(prefers-color-scheme: light)" srcSet={light} />
  <img {...rest} />
</picture>)
}
```

### Related

fix NEXT-257

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-06-29 01:35:08 +00:00
Ty Hopp
65f94baa83
feat: Introduce eslint rule for async client components (#51547)
The [React Server Component RFC on promise support](https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md) indicates that [client components cannot be async functions](https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md#why-cant-client-components-be-async-functions).

This PR introduces an eslint rule to enforce this.

Fixes #50898
2023-06-26 21:10:24 +00:00
Shu Ding
cb7be1912f
Remove unncessary source matching from loader (#51775)
The same logic is handled by SWC already, and extracted here:

dd937bde09/packages/next/src/build/analysis/get-page-static-info.ts (L68)
2023-06-25 21:58:11 +00:00
최지원
2aa68ae287
fix: eslint not ignoring "/app" (#50261)
## Why?
```
src/app/layout.tsx
```
![code](https://github.com/vercel/next.js/assets/120007119/3cc991f8-a96d-4ffb-9f84-4dfdbcac5318)

**eslint[@next/next/no-before-interactive-script-outside-document](https://nextjs.org/docs/messages/no-before-interactive-script-outside-document)**
> `next/script`'s `beforeInteractive` strategy should not be used outside of `pages/_document.js`. 

## How?
- Possibility of pathname starts with "/" on OS X and Linux, so added condition to check file path starting with "/"
- e.g. "/src/app" or "/app"
- Added test code



Passed 
- `pnpm build && pnpm lint`
- `pnpm jest test/unit/eslint-plugin-next/no-before-interactive-script-outside-document.test.ts`

Extends #46609
Fixes #50096
Fixes NEXT-1230
2023-05-26 16:27:42 +00:00
Jiachi Liu
702eb17638
Fix client references extraction of CJS exports analysis (#50059)
client refs are not correctly extracted as we're using regex to get the exports names from cjs file. The regex was extracting some bad names from the code source, this PR fixes the regex to make sure they extract the correct content

Fixes NEXT-1213
2023-05-19 19:42:46 +00:00
Jiachi Liu
ef2b8f8696
Fix canonical url for dynamic routes (#49512)
The `pathname` in app-render was actually "page" (e.g. `/blog/[slug]`),
with special url conventions. Instead we should use actual request url
as pathname. Rename previous `pathname` arg to `pagePath` for better
readability

Also improved the url validation
2023-05-09 16:31:06 -07:00
JJ Kasper
0bf6c2790b
Update tags handling during server action redirect (#49227)
Updates the tag handling during a server action direct to pass through
the revalidated tags for immediate revalidation as discussed.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1683218335368759)
2023-05-04 15:33:36 -07:00
Jiachi Liu
a4d63092e8
Support generate dynamic sitemaps for dynamic routes (#48867)
### What

For dynamic routes you might have different sitemap for different params

* Unloack using `sitemap.[ext]` in your app everywhere
* Support `generateSitemaps()` to create multiple sitemaps at the same time

### How

* Change the metadata regex to allow use sitemap in every routes
* Similar approach to `generateImageMetadata`, we make `sitemap.js` under dynamic routes to a catch all routes, and it can have multiple routes

Closes NEXT-1054
2023-04-26 20:41:37 +00:00
Jiachi Liu
cc684d02bc
Add export runtime test for pages and fully remove experimental.runtime (#48630)
### What 

`export const runtime = 'experimental-edge'` also work for pages. This
PR add tests for that.

Closes NEXT-426

Follow up for #46631 that to fully remove all related code of the
`experimental.runtime`
2023-04-20 22:37:38 +00:00
Maia Teegarden
43d09ce2fd
Update swc_core to v0.75.23 (#48098)
Depends on https://github.com/vercel/turbo/pull/4470

---

 - Closes https://github.com/vercel/next.js/issues/46989
 - Fixes WEB-879
 - Fixes WEB-813

---------

Co-authored-by: OJ Kwon <1210596+kwonoj@users.noreply.github.com>
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
Co-authored-by: Shu Ding <g@shud.in>
2023-04-18 08:59:52 +02:00
Yamagishi Kazutoshi
da8a82d6bf
Change CacheFs methods to return Buffer (#48237)
### What?

In environments where `FileSystemCache` is used, the cache for static
resources such as image files will be broken.

### Why?

Because `fs.readFile(path, 'utf8')` tries to read a file as a `string`.

### How?

Change to use `fs.readFile(path)` to always read files as binary
(`Buffer`).
2023-04-17 15:22:29 +00:00
Sean Massa
3003bff6fa
ensure original matcher source is free of mutations (#47980)
In a previous PR (https://github.com/vercel/next.js/pull/46753), the
`originalSource` was saved to be passed along through the build process.
This was done a bit too late in the flow, which made `originalSource`
include some transformations.

Because `originalSource` is used for display purposes, we need it
unmodified. This PR preserves `originalSource`.
2023-04-12 16:55:45 +02:00
Shu Ding
c11bce5989
Opt-into worker mode when appDir is enabled (#47857)
This unblocks further optimization opportunities as well as fixes for
systematic problems such as NEXT-227. After this PR, only production
mode of non-app projects will be running on the legacy main process
mode.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-11 22:26:49 +02:00
vinay
2601f55982
(Fix)(Tests)Fix typo in unit testing (#47644)
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
Fix Typo In Unit Testing
2023-04-01 22:23:15 -07:00
Tim Neutkens
baae7b1f44
Clean up leftover loaders (#46801)
More cleanup flowing out of the removal of the `target` option.

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/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`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

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

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-03-25 10:21:27 +01:00
Mark Ladyshau
054f786c8c
Skip warning if there is app directory for no-html-link-for-pages rule (#42516)
Skips pages directory warning if there is app directory in the root for `no-html-link-for-pages` lint rule.

Fixes #42448.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a 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 a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-22 02:15:52 +00:00
Jiachi Liu
93152db9b1
Fix bad route path for custom metadata routes (#47286)
We introduced static route `robots.txt` and dynamic route `robots.js` for metadata, it should still allow users to create their own customized version. This issue is caused by a route conflicts. Only append `/route` to page path when there's not ending with `/route`


Fixes #47198
Closes NEXT-850
2023-03-21 15:55:32 +00:00
Jiachi Liu
694e7f9e80
Generate metadata images generation with app routes (#47225)
Generated metadata icons through api routes instead of using webpack
emitting file. Each metadata image file will go through
`next-metadata-image-loader` to get the image basic info, and then it
will go through `next-metadata-route-loader` to be converted as a
routes.

Related to NEXT-264
Closes NEXT-810
2023-03-17 13:41:56 +01:00
Maksym Anisimov
74891fde18
Add auto-detection of image/x-icon content type (#47013)
Added auto-detection of image/x-icon content type by analyzing response buffer

fixes https://github.com/vercel/next.js/discussions/45998

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-03-10 20:36:33 +00:00
Noemi
71dbcacf17
Do not re-assign process.env (#46914)
## Checklist

- [ ] Related issues linked using `fixes #number` 
  - no related issue exists, happy to open one if desired
- [x] Tests added
- not sure if specific tests are needed? there is an integration test
for environment variables, and Next.js relies a lot on passing
information through environment variables; i'd expect everything to
break if this change broke environment variable handling
- [x] Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md
  - no new errors, does not apply

### What?

Re-assigning `process.env` substitutes the "magic object" that sets
environment variables at the process level with an ordinary JavaScript
object. This causes environment variables that are set after
`process.env` is re-assigned to not be visible to native add-ons.

See [this Node.js issue][issue] and [this reproduction case][repro] for
details.

[issue]: https://github.com/nodejs/node/issues/46996
[repro]: https://github.com/unflxw/nodejs-process-env-addons-repro

### Why?

In general, paraphrasing the maintainer in the Node.js issue,
re-assigning `process.env` is not a thing you should do. More
specifically, I'm trying to use Next.js' experimental OpenTelemetry
support with AppSignal's Node.js integration, which also uses
OpenTelemetry.

The AppSignal Node.js package sets environment variables in order to
configure a long-running process, which is then launched through a
native add-on. Because of the re-assignment of `process.env` that occurs
early in Next.js' lifecycle process, by the time the AppSignal Node.js
package sets environment variables, it's setting them in an ordinary
JavaScript object that Next.js left in the global `process` object, not
in the magic one created by the Node.js runtime.

This means that these environment variables are not _actually_ being set
for the process at the OS level, and therefore they're also not set for
the native add-on, or for the long-running process it spawns.

### How?

A `replaceProcessEnv` function is implemented that takes an environment
object as an argument, and applies the difference between that
environment object and the current environment to the existing
`process.env` object. This function is used instead of re-assigning
`process.env`.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-09 14:41:50 -08:00
Jiachi Liu
36ca1598d5
Support static file robots.txt and sitemap.xml as metadata route (#46963)
Support top level static `robots.txt` and `sitemap.xml` as metadata
route in app directory. When those files are placed in top root
directory

Refactored a bit the page files matching logic, to reuse it between dev
server and build

Closes NEXT-267
2023-03-09 11:10:18 -08:00
Jan Kaifer
8b50b80cde
eslint rule for script strategy should work properly in app/ (#46609)
fixes https://github.com/vercel/next.js/issues/46549

The docs are wrong for now, this limitation is just in `pages/`, you can
use it anywhere in `app/`.

Since `app/` is still not stable we will emit that warning in all files
outside of `app/`.
2023-03-08 11:28:52 +01:00
Sukka
26768571ad
test(unit): add cases for cssnano simple (#46862)
Continues from #46380. The PR migrates the unit test cases from the original repo into the Next.js repo.
2023-03-07 06:28:53 +00:00
Hannes Bornö
533748d383
next/font refactoring and additional unit tests (#46731)
Currently all helper functions are exported from huge utils files. This
moves the helper functions to their own files, this approach aligns
better with the rest of the codebase.

The unit tests are split up and colocated with the function it tests.
Also added some missing tests.

Plus some overall cleanup, added comments and fixed types.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/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`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-03-06 17:16:25 -08:00
Jiachi Liu
bca80141d1
Fix require cache conflict between app and pages (#46736)
Related NEXT-472

When you have `app/page.js` and `pages/page.js`, the `pagePath` are the
same, which is `/page`. This will result require cache conflicts. When
you visit the `app/` page first, then the `pages/` page, the 2nd request
will still get the app dir page module, which result in server error.

Solution: use different cache key of pagePathCache for pages/ and app/ 

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-03-03 12:24:09 -08:00
Michael Novotny
5e112c062e
Updates next/image eslint message to denote that costs may be incurred. (#46640)
Changes ESLint warning message to still encourage usage of `next/image`
for the best experience, but also denoting that optimization could come
with incurred costs.

## Feature

- [x] Documentation added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

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

---------

Co-authored-by: Steven Tey <stevensteel97@gmail.com>
Co-authored-by: Steven <steven@ceriously.com>
2023-03-01 14:28:09 -08:00