Commit graph

5284 commits

Author SHA1 Message Date
Vercel Release Bot
6dc28b3148
Update Turbopack test manifest (#62981)
This auto-generated PR updates the integration test manifest used when
testing Turbopack.
2024-03-07 14:31:55 +01:00
Jiachi Liu
27ed7820a8
[error overlay] move missing tags error inside error overlay (#62993)
### What

* Move missing html tags error into error overlay, from outside we don't
have to manually determine when to render a dummy component with runtime
missing tag error or error overlay.
* Add brackets `<>` to the html tags in the error



![image](https://github.com/vercel/next.js/assets/4800338/cd3467b7-74c2-477e-8516-c31761adb064)


### Why

In #62815, we're having throwing an missing required error, this will
trigger another runtime error. Then when error overlay caught it through
error event listener, it will render it as an unhandled runtime error:

You will see the below message in the overlay.
```
Unhandled Runtime Error
Error: The following tas are missing...

[Error stack]
```

This error message will bring a message that the error is happened on
client during runtime, but actually we already know that is a user side
mistake which doesn't have a error trace. This couldn't hmr as you fix
the error as well.

This PR moves the rendering into error overlay that we're aware of the
errors and can render the correct html on client, with the `html` tag
attached with error id and `body` wrapping the error overlay. We tell
overlay that there're missing tags through props, let it handle
everything inside.

It can also hmr once you fix the error. One drawback is that when you
re-introduce the error, it might trigger react DOM updates exception
(`Failed to execute 'removeChild' on 'Node': The node to be removed is
not a child of this node.`) instead of the "missing tags" message again.
Besides that the HMR works properly.

Closes NEXT-2741
2024-03-07 14:24:00 +01:00
Arian
5f3b13584c
chore: update pnpm version from 8.15.1 to 8.15.4 (#62979)
Update pnpm version from 8.15.1 to 8.15.4
pnpm 8.15.4 release note
https://github.com/pnpm/pnpm/releases/tag/v8.15.4

Previous comment form reviewer  
https://github.com/vercel/next.js/pull/62963#issuecomment-1982010314
2024-03-07 09:22:45 +00:00
Sam Ko
ee273c42bc
chore(next-font): update @capsize/metrics package to the latest (#62896)
## Why?

We need to be up-to-date with this package so our `next/font` is working
optimally. → https://github.com/seek-oss/capsize/releases.

Unlikely related to the latest
[comment](https://github.com/vercel/next.js/issues/47115#issuecomment-1979248754),
but a good reminder I need to check this regularly (or we should
automate it, or have a better solution).

Closes NEXT-2715
2024-03-06 12:04:20 -08:00
JJ Kasper
67eca23ae5
Upgrade to latest @edge-runtime packages (#62955)
This upgrades to the latest edge-runtime packages as it includes
exposing `performance`. This was reverted previously as our publishes
were failing with a specific change that has since been removed
upstream.

Closes NEXT-2730
2024-03-06 11:43:48 -08:00
Sukka
c206d89ec2
feat(eslint): enhance no-unwanted-polyfill w/ new endpoints (#62719)
The PR adds the new `polyfill.io` instance endpoint (from Fastly and
Cloudflare) to the `eslint-plugin-next`'s `no-unwanted-polyfillio`
rules, so these new endpoints can be detected by the rule.

---

`polyfill.io` was acquired by **a China-based CDN company** "Funnull",
see [the announcement from the `polyfill.io` domain owner's
Twitter](https://x.com/JakeDChampion/status/1761315227008643367) and
https://github.com/polyfillpolyfill/polyfill-service/issues/2834.
Despite Funnull's claims of operating in the United States, the
predominance of Simplified Chinese on its website suggests otherwise,
and it turns out that **"Funnull" is notorious for providing service for
the betting and pornography industries**.

[The original creator of the `polyfill.io` has voiced his concern on
Twitter](https://twitter.com/triblondon/status/1761852117579427975). And
since the acquisition, numerous issues have emerged
(https://github.com/polyfillpolyfill/polyfill-service/issues/2835,
https://github.com/polyfillpolyfill/polyfill-service/issues/2838,
https://github.com/alist-org/alist/issues/6100), rendering the
`polyfill.io` service **extremely unstable**. Since then, Fastly
([Announcement](https://community.fastly.com/t/new-options-for-polyfill-io-users/2540))
and Cloudflare
([Announcement](https://blog.cloudflare.com/polyfill-io-now-available-on-cdnjs-reduce-your-supply-chain-risk))
has hosted their own instances of `polyfill.io` service.

---------

Co-authored-by: Steven <steven@ceriously.com>
2024-03-06 16:42:53 +00:00
Donny/강동윤
3ed96f92cb
feat: Introduce lightningcss-loader for webpack users (#61327)
### What?

I'm recreating a PR because CI of
https://github.com/vercel/next.js/pull/58712 uses `lightningcss@1.14.0`
for an unknown reason.

Add an opt-in feature to use `lightningcss` instead of webpack
css-loader.

### Why?

In the name of performance.

### How?


This PR is largely based on https://github.com/fz6m/lightningcss-loader
by @fz6m.
(Thank you for nice work)

Closes PACK-1998
Closes PACK-2124

---------

Co-authored-by: OJ Kwon <1210596+kwonoj@users.noreply.github.com>
2024-03-06 17:07:53 +01:00
Balázs Orbán
0a73e89880
feat(error-overlay): version staleness in Pages Router (#62942) 2024-03-06 16:00:16 +00:00
Balázs Orbán
8f5107de16
feat(error-overlay): notify about missing html/body in root layout (#62815) 2024-03-06 10:59:53 +00:00
OJ Kwon
415cd74b9a
fix(next-api): correct font manifest generation (#62916)
### What

I noticed the font manifest generated by Turbopack was always empty.
Debugging showed that the path to the client_root was always incorrect
when calculating `get_font_paths_from_root`. And also fixed an issue
where for certain paths, the (`/index`) manifest key should contain the
original path.

Closes PACK-2666
2024-03-06 11:21:39 +01:00
Vercel Release Bot
57abed52dd
Update Turbopack test manifest (#62925)
This auto-generated PR updates the integration test manifest used when
testing Turbopack.
2024-03-06 11:19:55 +01:00
Will Binns-Smith
f9aec9005a
Turbopack: Trace edge runtime app render errors through source maps (#62901)
Similar to #62611, this implements error stack translation for edge
runtime app render errors.

Test Plan: `TURBOPACK=1 pnpm test-dev
test/development/app-render-error-log/app-render-error-log.test.ts`

Closes PACK-2665
2024-03-05 20:40:26 -08:00
Sam Ko
0d3481b6b2
test(integration-cli): fix test name (#62915)
- https://github.com/vercel/next.js/pull/62840#discussion_r1513648576

Closes NEXT-2720
2024-03-05 17:12:44 -08:00
Jiachi Liu
ced7339aa6
Fix: missing crossorigin property on manifest link (#62873)
We didn't set the property of manifest before, this PR fixes the missing
prop

> If the manifest requires credentials to fetch, the crossorigin
attribute must be set to use-credentials, even if the manifest file is
in the same origin as the current page.
x-ref: https://developer.mozilla.org/en-US/docs/Web/Manifest


Fixes NEXT-2706
2024-03-06 02:04:28 +01:00
Sam Ko
bdfe247b5e
chore(cli): fix allowRetry when using port 3000 (#62840) 2024-03-05 16:19:21 -08:00
OJ Kwon
d953de6203
test(fixture): update snapshot (#62894)
Closes PACK-2664
2024-03-05 21:25:15 +01:00
Jiwon Choi
9798ae52c5
refactor(next): fix spacing on auto-generated root layout (#62769)
![Screenshot 2024-03-03 at 5 28
23 AM](https://github.com/vercel/next.js/assets/120007119/282d65aa-71f0-410d-bd25-1352a244d2fb)

Added a space.

---------

Co-authored-by: Sam Ko <sam@vercel.com>
2024-03-05 19:47:57 +00:00
Jiachi Liu
02c4ce1acf
refactor: rename isAppDirEnabled to hasAppDir (#62837)
app dir is always "enabled", but not always exists. Rename to the proper
word to describe. Found this confusion while developing other fetaures

Closes NEXT-2691
2024-03-05 18:58:53 +01:00
Tobias Koppers
1d8b70411f
apply some transforms on foreign code too (#62827)
### What?

some transforms need to be applied on node_modules code too to work
correctly

### Why?

### How?


Closes PACK-2651
2024-03-05 16:03:35 +01:00
OJ Kwon
655227f4e1
Revert "refactor(analysis): rust based page-static-info, deprecate js parse interface in next-swc" (#62838)
Reverts vercel/next.js#61832

Closes PACK-2654
2024-03-04 21:43:56 +00:00
Shu Ding
7b2b982343
fix: Add stricter check for "use server" exports (#62821)
As mentioned in the new-added error messages, and the [linked
resources](https://react.dev/reference/react/use-server#:~:text=Because%20the%20underlying%20network%20calls%20are%20always%20asynchronous%2C%20%27use%20server%27%20can%20only%20be%20used%20on%20async%20functions.):

> Because the underlying network calls are always asynchronous, 'use
server' can only be used on async functions.
> https://react.dev/reference/react/use-server

It's a requirement that only async functions are allowed to be exported
and annotated with `'use server'`. Currently, we already have compiler
check so this will already error:

```js
'use server'

export function foo () {} // missing async
```

However, since exported values can be very dynamic the compiler can't
catch all mistakes like that. We also have a runtime check for all
exports in a `'use server'` function, but it only covers `typeof value
=== 'function'`.

This PR adds a stricter check for "use server" annotated values to also
make sure they're async functions (`value.constructor.name ===
'AsyncFunction'`).

That said, there are still cases like synchronously returning a promise
to make a function "async", but it's still very different by definition.
For example:

```js
const f = async () => { throw 1; return 1 }
const g = () => { throw 1; return Promise.resolve(1) }
```

Where `g()` can be synchronously caught (`try { g() } catch {}`) but
`f()` can't even if they have the same types. If we allow `g` to be a
Server Action, this behavior is no longer always true but depending on
where it's called (server or client).

Closes #62727.
2024-03-04 18:50:19 +01:00
OJ Kwon
372c74b620
refactor(analysis): rust based page-static-info, deprecate js parse interface in next-swc (#61832)
Reenabling https://github.com/vercel/next.js/pull/59300 with fixes for
the unsupported inputs.

Closes [PACK-2088](https://linear.app/vercel/issue/PACK-2088)

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2024-03-04 08:07:36 -08:00
Tobias Koppers
92eecbfdff
Turbopack: sass support (#62717)
### What?

* upgrades turbopack for `getResolve` in webpack loaders
* add missing resolve-url-loader to turbopack for full sass support

Closes PACK-2634
2024-03-04 11:56:55 +00:00
Tim Neutkens
bd28752495
Fix conflicting-app-page-error test for Turbopack (#62747)
## What?

Fixes the check for Turbopack. Follow-up to #62531 which fixes the
underlying issue but it wasn't checking the right value.

<!-- 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

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating 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 #

-->


Closes NEXT-2665
2024-03-02 11:00:05 +00:00
Will Binns-Smith
be87132327
Turbopack: Trace server app render errors through source maps (#62611)
Previously, errors shown in the error overlay, these stir were left
untraced through source maps.

Test Plan: `TURBOPACK=1 pnpm test-dev
test/development/app-render-error-log/app-render-error-log.test.ts`

Closes PACK-2608
2024-03-01 16:31:02 -08:00
Sam Ko
47f73cd8ec
refactor(cli): refactor cli to commander (#61877)
## Description
Refactor the [Next.js
CLI](https://nextjs.org/docs/app/api-reference/next-cli) to use
[commander](https://github.com/tj/commander.js) instead of
[arg](https://github.com/vercel/arg).

## Why?
- Auto-generated, properly formatted help command + output. With `arg`,
much of the help commands were manually added via a single
`console.log`, causing deviations over time.
- Ergonomic, ease of adding new subcommands and rules

## Breaking Changes
- Update the experimental `next experimental-compile` and `next
experimental-generate` build commands in favor of `next build
--experimental-build-mode=compile/generate`

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-03-01 23:12:47 +00:00
Tim Neutkens
8a2460ccb1
Revert "Migrate Sass tests to test/e2e" (#62735)
Reverts vercel/next.js#62321

This needs to land with @sokra's work on Sass but that couldn't land
yet.

Closes NEXT-2661
2024-03-01 20:02:22 +01:00
Jiachi Liu
4d4b45ec2c
fix dev overlay pseudo html collapsing (#62728)
Dev overlay should show the full stack trace after clicking the
uncollase button to display the full component stack

Closes NEXT-2658
2024-03-01 19:13:57 +01:00
Tim Neutkens
8034042215
Add compiler error for conflicting App Router and Pages Router in Turbopack (#62531)
## What?

Working on fixing `test/e2e/conflicting-app-page-error`, this adds a
compiler error for the case where App Router routes conflict with Pages
Router routes. It's not 1:1 the same error as in webpack because in the
webpack version we hijacked the App Router resolving logic to assume
there's a certain set of paths, where Turbopack has the full route to
route tree resolving implementation which doesn't assume there's a
single page that can be resolved.

The tests are updated to reflect this change.


<!-- 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

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating 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 #

-->


Closes NEXT-2592
2024-03-01 17:39:39 +01:00
Vercel Release Bot
2dab0b6ec8
Update Turbopack test manifest (#62715)
This auto-generated PR updates the integration test manifest used when
testing Turbopack.
2024-03-01 09:56:27 +00:00
Tim Neutkens
c0b1383c39
Migrate Sass tests to test/e2e (#62321)
## What?

Migrates the Sass support tests from `test/integration` (legacy test
suite) to `test/e2e`, this way all these tests run against both
development and production, whereas previously most of them would only
run against production.

This is helpful as it ensures the tests are running against Turbopack
too, which is highlighting some missing features in Sass support for
Turbopack.

I've had to rewrite most of the tests to check against the actual
rendered output in the browser instead of CSS output in the `.next`
folder, the majority of these now run regardless of implementation
details.

<details>
<summary>Tests that failed with Turbopack</summary>

```
 FAIL  e2e/app-dir/scss/url-global-partial/url-global-partial.test.ts (84.9 s)
  ● SCSS Support loader handling › CSS URL via file-loader sass partial › should render the page

    thrown: "Exceeded timeout of 60000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      13 |     })
      14 |
    > 15 |     it('should render the page', async () => {
         |     ^
      16 |       const browser = await next.browser('/')
      17 |       expect(
      18 |         await browser.elementByCss('.red-text').getComputedCss('color')

      at it (e2e/app-dir/scss/url-global-partial/url-global-partial.test.ts:15:5)
      at describe (e2e/app-dir/scss/url-global-partial/url-global-partial.test.ts:7:3)
      at Object.describe (e2e/app-dir/scss/url-global-partial/url-global-partial.test.ts:6:1)

 FAIL  e2e/app-dir/scss/composes-external/composes-external.test.ts (84.765 s)
  ● CSS Module Composes Usage (External) › should render the module

    thrown: "Exceeded timeout of 60000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      12 |   })
      13 |
    > 14 |   it('should render the module', async () => {
         |   ^
      15 |     const browser = await next.browser('/')
      16 |     expect(
      17 |       await browser.elementByCss('#verify-yellow').getComputedCss('color')

      at it (e2e/app-dir/scss/composes-external/composes-external.test.ts:14:3)
      at Object.describe (e2e/app-dir/scss/composes-external/composes-external.test.ts:6:1)

 FAIL  e2e/app-dir/scss/composes-basic/composes-basic.test.ts (35.629 s)
  ● CSS Module Composes Usage (Basic) › should render the module

    expect(received).toBe(expected) // Object.is equality

    Expected: "rgb(255, 255, 0)"
    Received: "rgb(0, 0, 0)"

      16 |     expect(
      17 |       await browser.elementByCss('#verify-yellow').getComputedCss('color')
    > 18 |     ).toBe(colorToRgb('yellow'))
         |       ^
      19 |     expect(
      20 |       await browser
      21 |         .elementByCss('#verify-yellow')

      at Object.toBe (e2e/app-dir/scss/composes-basic/composes-basic.test.ts:18:7)

 FAIL  e2e/app-dir/scss/npm-import-nested/npm-import-nested.test.ts (90.889 s)
  ● Good Nested CSS Import from node_modules › should render the page

    thrown: "Exceeded timeout of 60000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      12 |   })
      13 |
    > 14 |   it('should render the page', async () => {
         |   ^
      15 |     const browser = await next.browser('/')
      16 |     expect(
      17 |       await browser.elementByCss('.red-text').getComputedCss('color')

      at it (e2e/app-dir/scss/npm-import-nested/npm-import-nested.test.ts:14:3)
      at Object.describe (e2e/app-dir/scss/npm-import-nested/npm-import-nested.test.ts:6:1)

 FAIL  e2e/app-dir/scss/nm-module-nested/nm-module-nested.test.ts (81.941 s)
  ● Valid Nested CSS Module Usage from within node_modules › should render the page

    thrown: "Exceeded timeout of 60000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      12 |   })
      13 |
    > 14 |   it('should render the page', async () => {
         |   ^
      15 |     const browser = await next.browser('/')
      16 |     expect(await browser.elementByCss('#other2').getComputedCss('color')).toBe(
      17 |       colorToRgb('red')

      at it (e2e/app-dir/scss/nm-module-nested/nm-module-nested.test.ts:14:3)
      at Object.describe (e2e/app-dir/scss/nm-module-nested/nm-module-nested.test.ts:6:1)

```

</details>

<!-- 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

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating 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 #

-->


Closes NEXT-2550

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2024-03-01 09:43:21 +00:00
Vercel Release Bot
ec1cd79138
Update Turbopack test manifest (#62674)
This auto-generated PR updates the integration test manifest used when
testing Turbopack.
2024-03-01 07:58:23 +01:00
JJ Kasper
dc41d9c644
Add param to debug PPR skeleton in dev (#62703)
This adds an experimental query `__nextppronly` to allow debugging PPR
skeletons in development to avoid having to do numerous builds to be
able to debug this experience.

x-ref: [slack
thread](https://vercel.slack.com/archives/C05KYT5S9FF/p1709151588583179?thread_ts=1708474869.960689&cid=C05KYT5S9FF)
2024-02-29 16:30:56 -08:00
Jiachi Liu
ce422240e3
feat: display text diff for text mismatch hydration errors (#62684)
### What

Keep improving the hydration erros. Currently we divide the hydration
mismatch types into two categories, html tag mismatch and text mismatch.
We're displaying the mismatched text content between server and client
here since we have it in the component stack and warnings.

We've already made some improvements in #62590 , here we carry on
improving the highlited text into red and bold that is much easier for
you to spot on.

This updated a few long snapshots that we could collapse and show only
the text content difference instead of all the component stack.

### Screenshots

(Dark and light modes)

#### Mismatch html tags
<img width="360"
src="https://github.com/vercel/next.js/assets/4800338/f721b374-69cc-4600-a09d-bef87e885fab"><img
width="360"
src="https://github.com/vercel/next.js/assets/4800338/1abf2572-2be8-4359-a652-8ba39aaccfd3">


#### Mismatch text content
<img width="360"
src="https://github.com/vercel/next.js/assets/4800338/7f0d2215-8bc0-4fba-9c92-6c44efa29531"><img
width="360"
src="https://github.com/vercel/next.js/assets/4800338/656d1e1a-3157-4bcf-a239-74bb81fcb4c4">


#### Large content mismatch

### Why

I was intended to bring a html diff between server and client html
content but turns out the diff result could be giant and not ideal due
to few reasons. So we switched to the path of leveraging component stack
and mismatch contents.
React reordering the tags after hydration. For instance the `script` or
`link` tags could be hoist by React Float, so the lines of html is are
to preserved. so the diff is hard to be super accurate unless your
mismatch is small. If you're mismatch a component with rich html
content, it could be a pretty large diff.

Another case is if you have a bad nesting html like `<p> ...<span>...
<p>my text</p> ...</span>... <p>` where there're many span in between,
the final different could also be hudge as browser will close the first
`<p>` tag and the rest content will go into the diff. Hence we're going
with the component and text content diff.


Closes NEXT-2645
2024-02-29 23:36:38 +01:00
Leah
9f72146dd7
fix(turbopack): don't emit issues for deleted pages (#62012)
### What?

We now keep track of all client assets emitted for each route in
`ClientAssetMapper` and remove all issues associated with them when a
route get deleted.

Fixes #61384  
Closes PACK-2487
2024-02-29 16:55:49 +00:00
JJ Kasper
01b9603edc
Revert "Ensure dynamic routes dont match _next/static unexpectedly" (#62691)
Reverting temporarily to allow investigation into separate issue
eliminating this as also an issue.

Reverts vercel/next.js#62559
2024-02-29 08:34:11 -08:00
Tim Neutkens
c262e6118f
Consistently use /_not-found for not found page in App Router (#62679)
## What?

#62528 caused test/e2e/app-dir/not-found/conflict-route to fail
compilation in Turbopack, this compiler error was previously already
reported by Turbopack but Next.js didn't show it, which #62528 resolved.

This PR changes the handling for the not-found handling to be consistent
between development and build, which ensures that the "special" page no
longer conflicts with app/not-found/page.js.

Closes NEXT-2617


Note: this is a reworked iteration of
https://github.com/vercel/next.js/pull/62585 which wasn't sufficient.

<!-- 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

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating 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 #

-->
2024-02-29 14:47:31 +00:00
Balázs Orbán
9ae437f4b1
fix(navigation): allow useSelectedLayoutSegment(s) in Pages Router (#62584)
### What?

Do not fail when `useSelectedLayoutSegment` or
`useSelectedLayoutSegments` APIs are called in the Pages Router.

### Why?

This makes migration easier and creates consistency with our other App
Router-specific APIs that inherit the same behavior.

### How?

Similar to #47490, we return `null` if there is no Layout context
(indicating being in Pages Router)

Types are also overridden in the navigation compact module declaration
which kicks in during start to correct the types if we detect a `pages/`
directory.

Note to reviewer: #47490 didn't add a test, so I added one top-level,
let me know if you have a better suggestion for placing.

Closes NEXT-2506
Fixes #61464
2024-02-29 13:14:52 +00:00
栗原和也
2baf4f74e4
fix: Enable SearchParams to be displayed after redirect in Server Action (#62582)
### What?
Fixes https://github.com/vercel/next.js/issues/62525
Closes NEXT-2620

Since codes below do not consider searchParams, `redirect` in server
action removes all searchParams passed from client side.

93e4bb823c (diff-c809d50461027cdba7c092e564818b1172133d337abc5c513f829c94c8483dc6R186)

So I just add conditional branch for searchParams.

---

lint, prettier was applied.
Also I have done tests by commands below. and it was all passed.

```
pnpm testonly --testPathPattern "integration" -t "redirect"
```

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2024-02-28 14:37:39 -08:00
Jiachi Liu
7525633427
DX: display highlited pesudo html when bad nesting html error occurred (#62590)
### What

When you have bad nesting html in your React code, React wil raise
hydration error since the browser html parser might parse it to sth else
different comparing to server html on client. Previously we're display
only the warning in the error description in dev overlay.

Now we introduced another format of displaying pesudo html that
representing your code, with highlighting the html tag that causes the
error. Since React might gives you the whole component stack of React
tree, so we also introduced a way that can collapse the error.

#### Example


https://github.com/vercel/next.js/assets/4800338/622122d6-4d2e-4c8e-95e8-4864343e478b

### Why
The reason we added this is that even we show the html diff, it could
super large due to React ordering the html on client, so the mismatch
might be a lot. The idea here is similar to what you saw when you passed
down a bad event handler into server component, we displayed a pesudo
html as it could hit your mind faster than just seeing the warning. The
best way is to display the source code, but before we can show the
source, getting component stack display as pseudo html instead of here
could be more helpful.



### After vs Before

<img width="400"
src="https://github.com/vercel/next.js/assets/4800338/714119ad-ff23-46a9-bc5a-5601eb390e71">
<img width="400"
src="https://github.com/vercel/next.js/assets/4800338/575f95fa-889e-4cee-ad19-9c2fea06519a">



Closes NEXT-2621
2024-02-28 16:14:48 +01:00
Remo Vetere
3790099997
Fix Router Error Events in Shallow Routing by Skipping cancelHandler Creation (#61771)
### Problem

We've identified a bug within Next.js's pages router when utilizing the
shallow routing API, specifically when invoking `router.push` with the
`{ shallow: true }` option, like so:
 
```javascript
router.push('/?counter=10', undefined, { shallow: true });
```

Shallow routing is designed to update the URL without running data
fetching methods such as getServerSideProps, getStaticProps, or
getInitialProps. However, a side effect of this process is that it skips
the clean-up of the cancelHandler. This leads to router error events
being fired erroneously, causing confusion and potential stability
issues, as the system behaves as if an error occurred when, in fact,
none did.
 
### Solution

This PR addresses the issue by modifying the shallow routing logic to
also skip the creation of the cancelHandler. Given that shallow routing
operations are synchronous and do not involve data fetching or other
asynchronous tasks that might need to be canceled, the cancelHandler is
unnecessary in this context.

fixes #61772

---------

Co-authored-by: Shu Ding <g@shud.in>
2024-02-28 05:39:31 -08:00
Abhinay Pandey
f38dc18861
Fix: generateSitemaps in production giving 404 (#62212)
### What?
generateSitemaps function returns a 404 for /sitemap/[id].xml in
production

### Why?
While finding the correct sitemap partition from the array, we check the
param against the id. Which works in dev because id and param are both
without trailing .xml. But it fails in production as param has a
trailing .xml (/sitemap/[id] works in production because it falls back
to dynamic loading and param and id are both without .xml)

### How?
If we are in production environment, check the id with a trailing .xml
because that's whats returned from generateStaticParams, an array of
__metadata_id__ with trailing .xml

Fixes #61969

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-02-28 12:43:07 +01:00
JJ Kasper
eaa7606de1
Fix instrumentation with only pages (#62622)
This ensures we properly transpile `instrumentation.ts` when only
`pages` is being used as previously we were relying on the `app`
specific loaders which aren't configured when an `app` directory isn't
present. We regressed on this in
https://github.com/vercel/next.js/pull/60984 as it was working as
expected prior to this commit

x-ref: [slack
thread](https://vercel.slack.com/archives/C011GK1JUBA/p1709075846401649?thread_ts=1706643408.233909&cid=C011GK1JUBA)

Closes NEXT-2632
2024-02-28 11:38:39 +01:00
Donny/강동윤
bc943405a7
Update swc_core to v0.90.12 (#62518)
### What?

Update swc crates.

### Why?

To apply https://github.com/swc-project/swc/pull/8657

### How?

Closes PACK-2579
2024-02-28 04:22:47 +00:00
JJ Kasper
26de5ca269
Migrate locale redirect handling to router-server (#62606)
This moves the locale redirect handling out of `base-server` as it
shouldn't be handled here and should be at the routing level. This
avoids the duplicate handling with middleware that causes the incorrect
detection/infinite looping. Test case from separate PR was carried over
to prevent regression.

Fixes: https://github.com/vercel/next.js/issues/55648
Closes: https://github.com/vercel/next.js/pull/62435
Closes: NEXT-2627
Closes: NEXT-2628

---------

Co-authored-by: Nourman Hajar <nourmanhajar@gmail.com>
Co-authored-by: samcx <sam@vercel.com>
2024-02-27 16:37:11 -08:00
Jiachi Liu
69d1edf6d0
Fix metadata json manifest convention (#62615)
### What

Change from processing the file with `next-metatdata-route-loader`
directly into passing the file as loader query, and leave an empty
resource file for it. This will resolve the error that users were seeing
with `manifest.json` convention.

```
Import trace for requested module:
../../../../packages/next/dist/build/webpack/loaders/next-metadata-route-loader.js?page=%2Fmanifest.jso
n%2Froute&isDynamic=0!./app/manifest.json?__next_metadata_route__
getStaticAssetRouteCode page /manifest.json/route this.resourcePath /Users/huozhi/workspace/next.js/tes
t/e2e/app-dir/metadata-json-manifest/app/manifest.json
```

### Why

I looked at the loader process that the final resource processed by
webpack is `json!next-metadata-route-loader...`, which means the builtin
json loader processing json file after the metadata route loader. I
didn't get chance to solve the ordering issue, so I changed the
resourcePath to empty "", and pass the file path as query into the
loader to avoid json-loader processing it after transpilation.


Fixes #59923

Closes NEXT-2630
Closes NEXT-2439
2024-02-28 00:55:27 +01:00
JJ Kasper
e1e6a073fa
Ensure dynamic routes dont match _next/static unexpectedly (#62559)
This ensures our dynamic routes that have the same specificity as
`_next/static/:path*` don't get matched unexpectedly when the
`_next/static` asset doesn't exist. We were holding off on making this
change explicit due to compatibility concerns but these are no longer a
concern and the unexpected matching is more of a concern.

Closes: CSM-11
Fixes: https://github.com/vercel/next.js/issues/19270

Closes NEXT-2613
2024-02-27 15:01:16 -08:00
Jiachi Liu
29876c6f4f
Fix redirect under suspense boundary with basePath (#62597)
### What

Fixes `redirect()` call under suspense boundary, redirect url should
include the `basePath` in the url.

### Why

`redirect()` under suspense boundaries will go through server html
insertion, which is being used every time by suspense boundary resolved,
new errors will triggered from SSR streaming. It was missing before.

Fixes NEXT-2615
Fixes #62407
2024-02-27 23:45:24 +01:00
Zack Tanner
4caaccbdf6
fix flakey navigation test (#62598)
This test pretty consistently fails locally and in CI with the following
error in the request handler:

> Target page, context or browser has been closed


[x-ref](https://github.com/vercel/next.js/actions/runs/8069442877/job/22047444250#step:27:798)
<!-- 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

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating 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 #

-->


Closes NEXT-2626
2024-02-27 20:52:51 +00:00
Balázs Orbán
c441245932
fix(build-output): show stack during CSR bailout warning (#62594)
### What?

We should treat the warning for CSR bailout the same as the hard-error,
and show the stack trace for either case.

### Why?

It might be useful to track down the source of this warning.

### How?

We have the stack info already, but we only showed it during the error
logging. We should show it for warnings too.

This is similar to #61200

Closes NEXT-2624
2024-02-27 21:13:55 +01:00