Commit graph

11136 commits

Author SHA1 Message Date
vercel-release-bot
0114c2cb24 v14.1.1-canary.44 2024-02-08 12:22:09 +00:00
Jimmy Lai
feb27ad621
Revert "feat(next/image)!: remove squoosh in favor of sharp as optional dep" (#61810)
Reverts vercel/next.js#61696

Closes NEXT-2401
2024-02-08 11:00:34 +00:00
Tim Neutkens
b3878423c4
Increase Rust stack size (#61809)
## What?

Follow-up to #61781. That change doesn't apply so the packages we tested
still crashed the process. This ensures the environment variable is set
if it's not already set.

<!-- 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-2400
2024-02-08 10:59:50 +01:00
Will Binns-Smith
50ef635c0c
Fall back loading chunks for sourcemap tracing (#61790)
This implements falling back to try multiple locations loading chunks
for sourcemap tracing.

Unfortunately, when RSC replays server errors on the client, it does not
carry over the [0] symbol used to annotate server frames. Instead,
errors are recreated by React and only include the message and stack.

This allows more tests to pass, as we are able to correctly trace stack
frames by loading the appropriate server chunk.

Closes PACK-2442
2024-02-08 09:05:08 +01:00
OJ Kwon
775e898603
feat(next-core): build time client|server-only assertion (#61732)
### What

This PR injects a build-time error for the turbopack if
`client|server-only` is imported in incorrect context. The basic idea is
using resolve plugin, so in resolve time if matching context (which
alises erroneous import), raise a build time error.

Unfortunately this won't fix all of the tests in `invalid-imports`, due
to

1. resolveplugin does not have way to trace import from transformed, so
not able to detect `styled-jsx` from using `<styled..` tags
2. webpack (in our implementation) and turbopack's resolveplugin have
different order of transform / module trace chain, so enabling resolve
plugin in some context raises build error instead of runtime error in
rsc-build-error.

Closes PACK-2397
2024-02-08 09:04:43 +01:00
Donny/강동윤
c662d57342
fix(next-swc): Detect exports.foo from cjs_finder (#61795)
### What?

Patch cjs finder to detect `exports.foo` (instead of module.exports)

### Why?

This causes an issue for `react.production.min.js`.

x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1707343215879979

### How?

Closes PACK-2443
2024-02-08 11:28:33 +09:00
Tyler Sebastian
70b78c2945
Skip client-side data-fetching after ssr error (#51377)
Fixes: #47978

When an error occurs in getInitialProps, the error page's
getInitialProps is run server-side and returned in `__NEXT_DATA__`.
Following, there's no need to re-run `getInitialProps` client-side on
the hydrate pass.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-07 17:24:26 -08:00
Zack Tanner
7c38a667aa
consolidate prefetch utils & separate build util (#61789)
In preparation for the refactor of cache utils in subsequent PRs, this PR moves the one-off prefetch cache utils into a shared `prefetch-cache-utils` file, and also relocates the `buildCustomRoute` util into an isolated lib so that it can be imported into base-server (in a future PR).

This PR does not make any changes to these functions.

Closes NEXT-2394
2024-02-07 16:22:35 -08:00
Jiachi Liu
ed3ee38108
Fix attempted import error for react (#61791)
### What

Exclude precompiled react packages from browser layer loaders coverage.

### Why

Since we're transpiling all the browser layer code now after #59569,
then SWC will also compile react. But when it compiles
`react.production.min.js` it gives me with the code and ESM helper
inserted

```js
import { _ as _type_of } from "@swc/helpers/_/_type_of"; // This is not correct
var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Sym
bol.for("react.strict_mode"), r = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.f
```

This makes bundler think it's a ESM package but actually it's CJS, which
converts the module into `{ default: .., __esModule }` instead of the
original react module.

When you're using `React.useEffect` or other API through namespace
import (`import * as React from 'react'`), this will break the module
exports check in bundling as the property doesn't directly attached to
the module now. This PR disabled the transform for precompiled react
packages now and will see the deeper issue in next-swc side later.

Fixes #60890
Fixes #61185

Closes NEXT-2362
2024-02-08 00:57:43 +01:00
Balázs Orbán
53fd5ac0e5
fix(ts): match MiddlewareConfig with documentation (#61718)
### What?

Fix the user-facing `MiddlewareConfig` interface.

~While in the codebase, I also made the incoming config object type a
bit more strict by converting from `any` to `unknown`.~ Reverted, as we
do a config assertion already in a [different
place](https://github.com/vercel/next.js/blob/canary/packages/next-swc/crates/next-custom-transforms/src/transforms/page_config.rs/#L171-L180).

### Why?

The interface we previously exposed was the one we used internally,
_after_ we did some parsing on the config object, which is different
from what the user is expected to pass.

### How?

I separated the internal type to its own `MiddlewareConfigParsed`
interface.

Closes NEXT-2375
Fixes #61705

Ref: #61576
2024-02-07 23:32:03 +00:00
vercel-release-bot
d04cfb68a4 v14.1.1-canary.43 2024-02-07 23:21:21 +00:00
OJ Kwon
13af19a562
build(cargo): add deps for the wasi (#61784)
<!-- 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



### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

minor config update to the deps to include tokio for the wasi target.


Closes PACK-2435
2024-02-07 10:44:30 -08:00
Tobias Koppers
9d67a9f2d8
partially fix css duplication in app dir (#61198)
### What?

depends on https://github.com/facebook/react/pull/28108

* fixes CSS Ordering issues due to CSS duplication in production mode
* The issues still happen in dev mode
* Highlights broken CSS Ordering for more dev cases, e. g. CSS in client
components


Closes PACK-2300
2024-02-07 17:08:48 +01:00
vercel-release-bot
fa4d1a501c v14.1.1-canary.42 2024-02-07 08:48:27 +00:00
JJ Kasper
56cf916714
Add experimental touchstart flag for testing (#61747)
Adds an experimental flag to allow us to validate `touchstart` handling

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1707269419316909?thread_ts=1707256828.309319&cid=C03S8ED1DKM)

Closes NEXT-2384
2024-02-07 09:45:20 +01:00
Tobias Koppers
86c46edce7
source map fixes (#61723)
### What?

* show guessed original file for generate code
* avoid internal cast
* add get_source_map method
* hide turbopack runtime stack lines
* hide unmapped stack lines


Closes PACK-2400

Before:


![image](https://github.com/vercel/next.js/assets/1365881/29f24f59-7c77-4496-92de-efcc72d28ad5)

After:


![image](https://github.com/vercel/next.js/assets/1365881/ca07e9f9-71ea-440d-97a2-c2c731ab3899)

and expanded:


![image](https://github.com/vercel/next.js/assets/1365881/1f73e632-890d-4681-8f21-ef502c676aae)

### Other Turbopack changes


* https://github.com/vercel/turbo/pull/4235 <!-- Leah -
chore(turborepo-lib): use compile error for feature validation -->
* https://github.com/vercel/turbo/pull/7285 <!-- Tobias Koppers -
resolve source maps that are attached in source code -->
* https://github.com/vercel/turbo/pull/7301 <!-- Donny/강동윤 -
fix(turbopack): Reverse order of css chunks to fix css module issues -->
* https://github.com/vercel/turbo/pull/7286 <!-- Tobias Koppers - guess
original source for generated code -->
2024-02-07 08:58:08 +01:00
vercel-release-bot
b77373e283 v14.1.1-canary.41 2024-02-07 06:48:49 +00:00
OJ Kwon
f437ebb2c1
feat(next-core): expand matching js extensions for the rules (#61745)
### What?

fixes unexpected use client build warning in some applications.

We've consolidated all the ecmaplugins into custom rules. It behaves
different for the ecma inputs, while plugin runs any ecmascript inputs
rules only runs with matching target. The culprit module in question was
published as `.mjs`, so the necessary transform didn't ran.

Closes PACK-2419
2024-02-06 17:05:32 -08:00
Ahmed Abdelbaset
36a70667b2
fix jsDoc of notFound (#61692)
In #61649 the paragraph `"This function allows you to redirect the user
to another URL. It can be used in..."` describing `notFound` was copied
as is from the `redirect` jsDoc

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-06 15:56:21 -08:00
vercel-release-bot
b61a709068 v14.1.1-canary.40 2024-02-06 23:21:25 +00:00
vercel-release-bot
f07c2bd559 v14.1.1-canary.39 2024-02-06 23:19:27 +00:00
itz-Me-Pj
98232c8c73
Fix: Error Fetching _devpagesmanifest.json #17274 (#60349)
Closes NEXT-
Fixes #17274 Error Fetching _devpagesmanfest.json

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-06 15:15:39 -08:00
Will Binns-Smith
0060de1c49
Reapply "Turbopack: convert between locations correctly (#61477)" (#61733) (#61735)
This reverts commit a32d654c73.


Closes PACK-2421
2024-02-06 14:24:30 -08:00
Eddie Jaoude
ad15817f03
docs: fix example code missing comma (#59012)
<!-- 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?

Code example in docs was invalid

### Why?

Missing comma, causing command `npm run dev` to break.

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Sam Ko <sam@vercel.com>
2024-02-06 21:59:44 +00:00
Ahmed Abdelbaset
0a796d66f3
Fix duplicate line in README (#61691)
#48717 duplicated the /learn course link in README.md
2024-02-06 20:45:14 +00:00
Will Binns-Smith
a32d654c73
Revert "Turbopack: convert between locations correctly (#61477)" (#61733)
This reverts commit b19585f7fa.


Closes PACK-2420
2024-02-06 20:33:49 +01:00
Wyatt Johnson
252d9cf453
Navigation Signals in PPR (#60450)
### What

This adds support for navigation signals like `notFound()` and
`redirect(url)` when Partial Prerendering has been enabled.

### Why

Navigation API's like `notFound()` and `redirect(url)` throw errors in
order to interrupt the rendering of components. When a page both invokes
API's that cause the render to be marked as dynamic (like
`unstable_noStore()`) and also a navigation API, these errors may race
to the end. In the case where the navigation error does not beat out the
error emitted by dynamic API's will still trigger the detection warning
that's present to warn you about situations where you may have
accidentally caught the error.

### How

This resolves this issue by explicitly checking for navigation signals
(errors) thrown during the render, and not displaying the "caught
dynamic API" error and console warning.

Closes NEXT-2037
2024-02-06 12:25:50 -07:00
vercel-release-bot
300cf76c83 v14.1.1-canary.38 2024-02-06 19:24:56 +00:00
Steven
07c4ec052e
feat(next/image)!: remove squoosh in favor of sharp as optional dep (#61696)
## History

Previously, we added support for `squoosh` because it was a wasm
implementation that "just worked" on all platforms when running `next
dev` for the first time. However, it was slow so we always recommended
manually installing `sharp` for production use cases running `next
build` and `next start`.

Now that [`sharp` supports
webassembly](https://sharp.pixelplumbing.com/install#webassembly), we no
longer need to maintain `squoosh`, so it can be removed. We also don't
need to make the user install sharp manually because it can be installed
under `optionalDependencies`. I left it optional in case there was some
platform that still needed to manually install the wasm variant with
`npm install --cpu=wasm32 sharp` such as codesandbox/stackblitz (I don't
believe sharp has any fallback built in yet).

Since we can guarantee `sharp`, we can also remove `get-orientation` dep
and upgrade `image-size` dep.

I also moved an [existing `sharp`
test](https://github.com/vercel/next.js/pull/56674) into its own fixture
since it was unrelated to image optimization.

## Related Issues
- Fixes https://github.com/vercel/next.js/issues/41417
- Closes https://github.com/vercel/next.js/pull/54670
- Related https://github.com/vercel/next.js/issues/54708
- Related https://github.com/vercel/next.js/issues/44804
- Related https://github.com/vercel/next.js/issues/48820
2024-02-06 14:17:07 -05:00
Will Binns-Smith
b19585f7fa
Turbopack: convert between locations correctly (#61477)
- parsed stack traces (and error stack locations in js) have 1-based
lines and 1-based columns
- source map tokens have 0-based lines and 0-based columns
- babel code frames use 1-based lines and 0-based columns

This was not always respected. This preserves the 1-based lines and
columns in anything called a stack frame, 0-based lines and columns for
source map apis, and converts to babel’s format as needed.


Closes PACK-2341

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2024-02-06 11:09:48 -08:00
OJ Kwon
9cadae5eef
feat(next-swc): support wasm32-* build target (#61586)
<!-- 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

### How?

Closes NEXT-
Fixes #

-->

### What?

This PR introduces a ground work to generate wasm bindings package from
our napi bindings. This doesn't actually replace anything yet, however
aim to establish our napi bindings package can be built against wasm32
target.

### Why?

We currently have two bindings package to generate native / wasm target
support, one for napi and one other for wasm. Recently napi-rs started
to support to generate bindings for the wasm directly - which means we
can get rid of the wasm-pack based bindings code entirely and maintain a
single bindings code only.

This'll makes our `next-swc` simpler as well, since the invocation to
the bindings now becomes identical we don't have to additional wasm
specific logics to invoke functions (i.e transform, transformsync..).
Also napi generates wasi-supported wasm bindings, provides few more
features to the current wasm bindings.

#### Good
- Async napi binding fn works transparently (`transform`, `minify`...)
- (Experimental) thread supports depends on node.js runtime
- Wasi support: i.e it can even read filesystem directly!

#### Things to consider
- node.js's wasi support is experimental yet
- napi-rs's wasm support is in beta yet, specifically `packaging`
generated wasm output.

Due to `things to consider` reasons, this PR does not replace existing
wasm target yet. We should be able to plan out things later.

**What happens to the turbopack api in napi bindings?**

Simply put, this **does not support turbopack in wasm**. Build works by
disabling turbopack (more notably, underlying dependency doesn't support
wasm) features. It is something to explore separately.


Closes PACK-2367


There is a branch at https://github.com/vercel/next.js/pull/61586 shows
quick demo for importing, running sync / async / read external files.
2024-02-06 10:15:13 -08:00
Julius Marminge
6d07c00dee
fix: allow some recursion for middleware subrequests (#60615)
This alters the behavior of the subrequest check to allow for 5
recursive calls to match Vercel production, ref [Slack
thread](https://pinglabsworkspace.slack.com/archives/C052S77L05C/p1694729495655489).

> [!NOTE]
> Currently limited by fetches having to forward the subrequest header
for each request which isn't ideal. Need some assistant on how to access
the request in the module context fetch override.
> No forwarding: 
![CleanShot 2024-02-05 at 22 52
10@2x](https://github.com/vercel/next.js/assets/51714798/8ae79f00-f987-4919-946c-d8363d540cef)
> With forwarding: 
![CleanShot 2024-02-05 at 22 51
31@2x](https://github.com/vercel/next.js/assets/51714798/32bd4072-9373-4cb0-ab05-f862a818e0d7)

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-06 18:00:29 +00:00
OJ Kwon
e652a6f652
feat(transforms): enable rsc transforms for the remaining contexts (#61231)
### What?

This PR wraps up supporting rsc transforms (mostly for the assertion) in
Turbopack. PR contains a few changes to support it, including:

- adjust / expand transform rules for the corresponding contexts
- fix file name / node_modules check
- extract visitors for the assertion / transforms

This change enables most of the rsc-build* tests and some more other
tests. The only failing tests in the rsc-build-errors is due to
Turbopack not triggering hmr with empty file.

Closes PACK-2303
2024-02-06 09:15:07 -08:00
vercel-release-bot
59bf406d0a v14.1.1-canary.37 2024-02-06 17:07:44 +00:00
Jiachi Liu
4aa5e9cad2
Fix next/server api alias for ESM pkg (#61721)
### What & Why

We have a modularize imports config for `next/server` before, which will
transform the `next/server` imports to directly import from the actual
file, for instance: `import { NextRequest } from 'next/server'` will
become `import { NextRequest } from
'next/dist/server/web/exports/next-request'`, where the NextRequest is
exported as default export. This is fine in most case until you're using
a ESM pkg, then it will be resolved as `{ default: NextRequest }`
according to the spec. Since it's a ESM import to a CJS module in
`next/dist`.

Since we already have the ESM alias introduced in #59852 , this can
handle the case more properly.

### How

Remove the modularize imports config for `next/server`, use the ESM api
alias instead.

Migrate the cjs optimizer tests from middleware to a separate endpoint
`/cjs/server`. As now ESM imports for next/server are not going to get
tree-shaken in dev, but since we don't have image response there it's
still fine.

Closes NEXT-2376
Closes NEXT-2374
2024-02-06 16:59:24 +00:00
Zack Tanner
a19b3bc6fb
fix navigation issue when dynamic param casing changes (#61726)
### What
When navigating to a page with dynamic params using a certain casing,
and then following a link to another page using _different_ casing for
the same param, the router would get stuck in an infinite suspense
cycle.

### Why
On the client we normalize cache keys by lowercasing the values for
dynamic segments. However the RSC data for each segment wouldn't have
this same casing logic applied. This is causing the router to not
recognize that there is already RSC data available for that segment,
resulting in an infinite suspense cycle.

### How
The `toLowerCase()` logic shouldn't be needed here. Technically we could
leave this in place and update `matchSegment` to also apply the
lowercase logic, but currently there are too many utility functions that
parse segments to comfortably make that change. I confirmed that the bug
related to why we lowercased these router cache keys is no longer
present after making this change.

Fixes #61722
Closes NEXT-2377
2024-02-06 08:59:18 -08:00
Balázs Orbán
df74a02fe3
fix(ts): ReadonlyURLSearchParams should extend URLSearchParams (#61419)
### What?

Let the developer check the instance of `ReadonlyURLSearchParams` to
match against `URLSearchParams`

### Why?

`useSearchParams()`'s return type is `ReadonlyURLSearchParams` which
implements all the methods of `URLSearchParams`, therefore its type
should be extended from `URLSearchParams` as well. Deprecated methods
are also implemented to throw an error, so no runtime behavior is being
changed

### How?

Mark the unavailable methods as `@deprecated` which will visually mark
them in IDEs:


![image](https://github.com/vercel/next.js/assets/18369201/f3de2858-14ac-4021-981d-b0267610faa7)

This is similar how `ReadonlyHeaders` extends `Headers`, added in:
#49075

[Slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1706628877916779)

Closes NEXT-2305
2024-02-06 16:15:38 +01:00
Zack Tanner
da842e167a
fix loading issue when navigating to page with async metadata (#61687)
### What
Client-side transitioning to a page that triggered a loading boundary
with async metadata would cause the transition to stall, potentially
getting stuck in a refetch loop.

### Why
In layout-router, we trigger a "lazy fetch" when we encounter a segment
that we don't have cache nodes for. This calls out to the server and
suspends until the data fetch is resolved, and applied to the router
tree. However after suspending but before updating the client router, we
set `childNode.lazyData` to null. When we unsuspend from the server
patch action, `childNode.rsc` might still be missing and clearing
`lazyData` means we've blown away the reference to the fetch we already
had pending, triggering a refetch loop.

### How
This removes the logic that mutates the cache node in render, as this is
not concurrent safe, and doesn't appear to be needed for anything.

Fixes #61117
Closes NEXT-2361

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-02-06 07:10:53 -08:00
Leah
f910e2bdcd
chore: update turbopack (#61682)
### Turbopack Updates

* https://github.com/vercel/turbo/pull/7240 <!-- OJ Kwon -
refactor(turbopack): remove deprecated options -->
* https://github.com/vercel/turbo/pull/7241 <!-- Will Binns-Smith -
Turbopack: Fix Next.js in cross-bundler benchmarks -->
* https://github.com/vercel/turbo/pull/7274 <!-- Leah - fix(turbopack):
support reloading typescript tailwind config -->

Fixes #61607
2024-02-06 14:40:15 +01:00
Jiachi Liu
92e4a4b78c
Associate server error digest with browser logged one (#61592)
### What

#### Core
This PR respect the error's digest when recieves new error occurred from
server side, and it will be logged into client on production with the
same `digest` property.
If we discover the original RSC error in SSR error handler, retrieve the
original error

#### Tests

* Move the errors related tests from `test/e2e/app-dir/app` to a
separate test suite `test/e2e/app-dir/errors`
* Add a new test case for logging the original RSC error
* Add a new test case for logging the original Server Action error


### Why

This will help associate the `digest` property of the errors logged from
client with the actual generated server errors. Previously they're
different as we might re-compute the digest proper in handler that react
server renderer thinks it's a new error, which causes we have 2
different errors logged on server side, and 1 logged on client side. The
one on client side can associate to the server errors but it's from
react renderer which is not the original error.

Closes NEXT-2094
Fixes #60684
2024-02-06 13:39:12 +01:00
Tobias Koppers
89fcf68c6a
decode magic identifiers (#61658)
### What?

* decode magic identifiers when printing compile errors to the console
* Error Overlay
  * decode magic identifiers in the error message
  * decode magic identifiers in source frame
  * decode magic identifiers in call stack


![image](https://github.com/vercel/next.js/assets/1365881/836ba497-84dd-4958-8341-4207fc6d860f)

![image](https://github.com/vercel/next.js/assets/1365881/f03d5c9e-0b2f-4699-b7c3-56c38b0eba51)

![image](https://github.com/vercel/next.js/assets/1365881/49a65991-92d8-47b4-863c-961536d98d13)


### Why?

### How?

PACK-2008


Closes PACK-2387
2024-02-06 10:19:07 +00:00
Leah
933c98651c
fix(turbopack): read preload option for google fonts (#61679)
### What?

I forgot to check the `preload` option when implementing it and just
looked at the `subsets`.

This also fixes duplicate preload tags by adding them to a set in the
default `_document.tsx`



Closes PACK-2392
2024-02-06 08:30:12 +01:00
Josh Story
23955574ae
Update React from 60a927d04 to 2bc7d336a (#61522)
Updates React from 60a927d04 to 2bc7d336a

Also updates aliases for `react.shared-subset` to `react.react-server`

### React upstream changes

- https://github.com/facebook/react/pull/28250
- https://github.com/facebook/react/pull/28225
- https://github.com/facebook/react/pull/28123
- https://github.com/facebook/react/pull/28240
- https://github.com/facebook/react/pull/28239
- https://github.com/facebook/react/pull/28245
- https://github.com/facebook/react/pull/28244
- https://github.com/facebook/react/pull/28238
- https://github.com/facebook/react/pull/28235
- https://github.com/facebook/react/pull/28221
- https://github.com/facebook/react/pull/28215
- https://github.com/facebook/react/pull/28214
- https://github.com/facebook/react/pull/28213
- https://github.com/facebook/react/pull/28212
- https://github.com/facebook/react/pull/28211
- https://github.com/facebook/react/pull/28247
- https://github.com/facebook/react/pull/28210
- https://github.com/facebook/react/pull/28186
- https://github.com/facebook/react/pull/28232
- https://github.com/facebook/react/pull/28169
- https://github.com/facebook/react/pull/28177
- https://github.com/facebook/react/pull/28170
- https://github.com/facebook/react/pull/28168
- https://github.com/facebook/react/pull/28122
- https://github.com/facebook/react/pull/27982
- https://github.com/facebook/react/pull/28217
- https://github.com/facebook/react/pull/28223
- https://github.com/facebook/react/pull/28208
- https://github.com/facebook/react/pull/28209
- https://github.com/facebook/react/pull/28200
- https://github.com/facebook/react/pull/28199
- https://github.com/facebook/react/pull/28198
- https://github.com/facebook/react/pull/28197
- https://github.com/facebook/react/pull/28196
- https://github.com/facebook/react/pull/28194
- https://github.com/facebook/react/pull/28192
- https://github.com/facebook/react/pull/28191
- https://github.com/facebook/react/pull/28182
- https://github.com/facebook/react/pull/28181
- https://github.com/facebook/react/pull/28180
- https://github.com/facebook/react/pull/28178
- https://github.com/facebook/react/pull/28201
- https://github.com/facebook/react/pull/28176
- https://github.com/facebook/react/pull/28162
- https://github.com/facebook/react/pull/28131
- https://github.com/facebook/react/pull/28190
- https://github.com/facebook/react/pull/28172
- https://github.com/facebook/react/pull/28171
- https://github.com/facebook/react/pull/28173
- https://github.com/facebook/react/pull/28174
- https://github.com/facebook/react/pull/28175
- https://github.com/facebook/react/pull/28136
- https://github.com/facebook/react/pull/28135
- https://github.com/facebook/react/pull/28134
- https://github.com/facebook/react/pull/28133
- https://github.com/facebook/react/pull/28132
- https://github.com/facebook/react/pull/28130
- https://github.com/facebook/react/pull/28202
- https://github.com/facebook/react/pull/28102
- https://github.com/facebook/react/pull/28161
- https://github.com/facebook/react/pull/28193
- https://github.com/facebook/react/pull/28195
- https://github.com/facebook/react/pull/28189
- https://github.com/facebook/react/pull/28160
- https://github.com/facebook/react/pull/28096
- https://github.com/facebook/react/pull/28183
- https://github.com/facebook/react/pull/28125
- https://github.com/facebook/react/pull/28157
- https://github.com/facebook/react/pull/28115
- https://github.com/facebook/react/pull/28124
- https://github.com/facebook/react/pull/28163
- https://github.com/facebook/react/pull/28164
- https://github.com/facebook/react/pull/28150
- https://github.com/facebook/react/pull/28159
- https://github.com/facebook/react/pull/28069
- https://github.com/facebook/react/pull/28110
- https://github.com/facebook/react/pull/28148
- https://github.com/facebook/react/pull/28116
- https://github.com/facebook/react/pull/28099
- https://github.com/facebook/react/pull/28100
- https://github.com/facebook/react/pull/28147
- https://github.com/facebook/react/pull/28128
- https://github.com/facebook/react/pull/28126
- https://github.com/facebook/react/pull/28139
- https://github.com/facebook/react/pull/28140
- https://github.com/facebook/react/pull/28141
- https://github.com/facebook/react/pull/28142
- https://github.com/facebook/react/pull/28113
- https://github.com/facebook/react/pull/28129
- https://github.com/facebook/react/pull/28114
- https://github.com/facebook/react/pull/28053
- https://github.com/facebook/react/pull/28091
- https://github.com/facebook/react/pull/28087
- https://github.com/facebook/react/pull/28112
- https://github.com/facebook/react/pull/28086
- https://github.com/facebook/react/pull/28101
- https://github.com/facebook/react/pull/28106
- https://github.com/facebook/react/pull/28117
- https://github.com/facebook/react/pull/28118
- https://github.com/facebook/react/pull/28105
- https://github.com/facebook/react/pull/27883
- https://github.com/facebook/react/pull/28111
- https://github.com/facebook/react/pull/28095
- https://github.com/facebook/react/pull/28108
- https://github.com/facebook/react/pull/28090
- https://github.com/facebook/react/pull/28089
- https://github.com/facebook/react/pull/28076
- https://github.com/facebook/react/pull/28074
- https://github.com/facebook/react/pull/28103
- https://github.com/facebook/react/pull/28098
- https://github.com/facebook/react/pull/28097
- https://github.com/facebook/react/pull/28068
- https://github.com/facebook/react/pull/28093
- https://github.com/facebook/react/pull/28094
- https://github.com/facebook/react/pull/28073
- https://github.com/facebook/react/pull/28084
- https://github.com/facebook/react/pull/28063
- https://github.com/facebook/react/pull/28085
- https://github.com/facebook/react/pull/28083
- https://github.com/facebook/react/pull/28065
- https://github.com/facebook/react/pull/28061
- https://github.com/facebook/react/pull/28077
- https://github.com/facebook/react/pull/28075
- https://github.com/facebook/react/pull/28078
- https://github.com/facebook/react/pull/28050
- https://github.com/facebook/react/pull/28011
- https://github.com/facebook/react/pull/28055
- https://github.com/facebook/react/pull/28066
- https://github.com/facebook/react/pull/28067
- https://github.com/facebook/react/pull/28010
- https://github.com/facebook/react/pull/27993
- https://github.com/facebook/react/pull/28052
- https://github.com/facebook/react/pull/28060
- https://github.com/facebook/react/pull/28059
- https://github.com/facebook/react/pull/28034
- https://github.com/facebook/react/pull/28033
- https://github.com/facebook/react/pull/28004
- https://github.com/facebook/react/pull/28051
- https://github.com/facebook/react/pull/28012
- https://github.com/facebook/react/pull/28001
- https://github.com/facebook/react/pull/28002
- https://github.com/facebook/react/pull/27995
- https://github.com/facebook/react/pull/28006
- https://github.com/facebook/react/pull/28005
- https://github.com/facebook/react/pull/28007
- https://github.com/facebook/react/pull/28008
- https://github.com/facebook/react/pull/28009
- https://github.com/facebook/react/pull/28000
- https://github.com/facebook/react/pull/28003
- https://github.com/facebook/react/pull/27997
- https://github.com/facebook/react/pull/27240
- https://github.com/facebook/react/pull/27977
- https://github.com/facebook/react/pull/27940
- https://github.com/facebook/react/pull/27939
- https://github.com/facebook/react/pull/28090
- https://github.com/facebook/react/pull/28089
- https://github.com/facebook/react/pull/28076
- https://github.com/facebook/react/pull/28074
- https://github.com/facebook/react/pull/28103
- https://github.com/facebook/react/pull/28098
- https://github.com/facebook/react/pull/28097
- https://github.com/facebook/react/pull/28068
- https://github.com/facebook/react/pull/28093
- https://github.com/facebook/react/pull/28094
- https://github.com/facebook/react/pull/28073
- https://github.com/facebook/react/pull/28084
- https://github.com/facebook/react/pull/28063
- https://github.com/facebook/react/pull/28085
- https://github.com/facebook/react/pull/28083
- https://github.com/facebook/react/pull/28065
- https://github.com/facebook/react/pull/28061
- https://github.com/facebook/react/pull/28077
- https://github.com/facebook/react/pull/28075
- https://github.com/facebook/react/pull/28078
- https://github.com/facebook/react/pull/28050
- https://github.com/facebook/react/pull/28011
- https://github.com/facebook/react/pull/28055
- https://github.com/facebook/react/pull/28066
- https://github.com/facebook/react/pull/28067
- https://github.com/facebook/react/pull/28010
- https://github.com/facebook/react/pull/27993
- https://github.com/facebook/react/pull/28052
- https://github.com/facebook/react/pull/28060
- https://github.com/facebook/react/pull/28059
- https://github.com/facebook/react/pull/28034
- https://github.com/facebook/react/pull/28033
- https://github.com/facebook/react/pull/28004
- https://github.com/facebook/react/pull/28051
- https://github.com/facebook/react/pull/28012
- https://github.com/facebook/react/pull/28001
- https://github.com/facebook/react/pull/28002
- https://github.com/facebook/react/pull/27995
- https://github.com/facebook/react/pull/28006
- https://github.com/facebook/react/pull/28005
- https://github.com/facebook/react/pull/28007
- https://github.com/facebook/react/pull/28008
- https://github.com/facebook/react/pull/28009
- https://github.com/facebook/react/pull/28000
- https://github.com/facebook/react/pull/28003
- https://github.com/facebook/react/pull/27997
- https://github.com/facebook/react/pull/27240
- https://github.com/facebook/react/pull/27977
- https://github.com/facebook/react/pull/27940
- https://github.com/facebook/react/pull/27939

Closes NEXT-2331
2024-02-05 18:22:27 -08:00
Jiwon Choi
4c5384351c
fix(next-eslint): .eslintrc.json not being created by next lint on App Router (#55104)
This PR fixes `.eslintrc.json` not being created after the user runs
`next lint` and selects an option of `Strict` or `Base`.
The reason is that the lint check was looking for `pages` and
`src/pages` only. Added `app` and `src/app` to be checked also.

Fixes: #55094
Fixes: #55102

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-05 15:47:18 -08:00
Allan Guigal
4ba1f06380
fix: status code to avoid navigation with empty props (#60968)
### What?
Currently, when a middleware is active and the path results in a 404,
the server responds with a 200 status code to data requests. We propose
a change to ensure that a 404 status code is returned in these
situations, as expected, solving production issues for the navigation
router.

### Why?
The client data requests (identified with `_next/data` path &
`x-nextjs-data` header) get answered the status code 200. The code below
is executed when there is a version skew for the data requests (e.g
prefetch in production).


4125069840/packages/next/src/server/lib/router-server.ts (L217-L227)

The version skew consists in the client side version identified with the
buildId in `__NEXT_DATA__ ` tag to be obsolete compared to the server
version (`BUILD_ID` file).

In the case of prefetching, this leads to the code above being executed,
therefore the `prefetch-reducer.ts` handles the response as valid and
sets it in its cache. Which ultimately triggers a navigation with empty
prop, resulting in erroneous behaviours reported in issues and in our
production websites:

4125069840/packages/next/src/client/components/router-reducer/reducers/prefetch-reducer.ts (L54-L74)

By switching the response to a 404, we trigger this code in the fetch
(`fetchServerResponse`). This change prompts a hard navigation
(mpaNavigation), effectively refreshing the client version and
resynching it with the server version.

4125069840/packages/next/src/client/components/router-reducer/fetch-server-response.ts (L125-L134)

### How?
We simply update the status code to 404 here:

4125069840/packages/next/src/server/lib/router-server.ts (L223)

Closes: https://github.com/vercel/next.js/pull/60785
Closes: https://github.com/vercel/next.js/issues/59295
Fixes: https://github.com/vercel/next.js/issues/47516

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-05 15:34:23 -08:00
vercel-release-bot
bdd0dd2d50 v14.1.1-canary.36 2024-02-05 23:22:30 +00:00
Aly Ahmed
19c2e197ea
fix setAssetPrefix when running on NextCustomServer (#61676)
### What?

Fixes `setAssetPrefix` when running on a custom server using next()
function

### Why?

Looks like when we run next custom server, there are 2 instances created
to handle this case

* main server in `/server/next.ts`
* and Render server `./server/lib/render-server.ts`

The issue mainly happens when calling `setAssetPrefix` it will update
only the main server and not render server

``` javascript
  const next = require('next')
  const app = next({ });
    app.setAssetPrefix('my-fancy-cdn/static');
    app.render(); // render server is used instead of the main server
```

### How?

when calling `setAssetPrefix` on the main server also update the render
server with the same information.

Fixes: #59940
Fixes: #51223 
Fixes: #61383

### Related Resources

#53523  #49805


c9c6ff6d77/docs/03-pages/01-building-your-application/06-configuring/10-custom-server.mdx

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-05 14:09:29 -08:00
OJ Kwon
a4d33d4acd
fix(next-core): adjust server alias for the context (#61690)
### What

This PR attempts to adjust import map to `server-only` / `client-only`
close to the existing webpack configs, makes to pass more tests.

Closes PACK-2396
2024-02-05 14:05:37 -08:00
Balázs Orbán
bb7577aa44
feat(ts): add JSDoc comments for public APIs (#61649)
### What?

This PR adds JSDoc comments to the most common public APIs to improve
the DX in IDEs like VSCode.

### Why?

Currently, we provide no information on some of the most used APIs in
IDEs, which makes it harder than it needs to be to look up the extra
information.

<details>
<summary><b>Before:</b></summary>
<img
src="https://github.com/vercel/next.js/assets/18369201/8b6092e8-8f9b-49da-a3df-b07a59982069"
width="640"/>
</details>

<details>
<summary><b>After:</b></summary>
<img
src="https://github.com/vercel/next.js/assets/18369201/30216f76-414a-43b0-9aa6-2fdd742ab3fe"
width="640"/>
</details>

### How?

Using JSDoc comments, I added a basic description to most public APIs
that link back to the current docs for more details. The description is
kept minimal to avoid out-of-sync documentation.

Note: In the future, the flow could be reversed here, and our API
Reference docs could actually be generated from a single source of
truth, the source code itself. However, this will require more work by
re-organizing our public API submodules in a single directory, (related
#61525), so the API docs are easy to maintain even without a deeper
knowledge of the codebase.

Note: These comments should also be extended to
methods/properties/arguments in these public APIs in the future.

Closes NEXT-2357

[Slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1706735292633029)
2024-02-05 20:31:59 +00:00
vercel-release-bot
b1f6b8246e v14.1.1-canary.35 2024-02-05 19:38:59 +00:00