Commit graph

1197 commits

Author SHA1 Message Date
Zack Tanner
0312d4a1a9
fix revalidation issue with route handlers (#63213)
### What
When a route handler uses an API that opts it into dynamic rendering
(such as `no-store` on a fetch), and also specifies a `revalidate` time,
the `revalidate` time is ignored and route is treated as fully static.

### Why
`revalidate: 0` and `revalidate: false` have different semantic
meanings: `false` essentially means cache forever, whereas `0` means
it's dynamic. Since `0` is also falsey, the code we have to fallback
with a default `revalidate` value for route handlers is incorrectly not
marking the route as dynamic, and as a result, caching the route without
an expiration time.

### How
This updates the fallback handling for app routes respect a revalidation
value of `0`, so that the page can properly be marked dynamic.

### Test Explanation
This adds 2 new routes handlers: both have a revalidation time specified
& use `no-store` on a fetch, but only one of them specifies `export
const dynamic = 'force-static'`. The one that doesn't specify
`force-static` is correctly omitted from the prerender manifest. The one
that is `force-static` is correctly in the prerender manifest with the
right expiration time. An additional test case was added to verify that
this data refreshes after the specified interval.

Closes NEXT-2764
2024-03-12 15:57:36 -07:00
Shu Ding
977f5ff72e
fix: Loose Server Actions runtime check (#63200)
Addresses some feedback in #62821. This will re-allow implementations
like:

```js
'use server'

export const f = wrapper(async () => {})
```

Where `wrapper` creates a sync function that returns a promise. Although
it will still be silently converted to an async function under the hood.

Closes NEXT-2790
2024-03-12 22:03:29 +00:00
JJ Kasper
aa7ae420c6
Fix generateMetadata race condition (#63169)
This ensures we properly catch/handle `generateMetadata` errors during
eager evaluating of nested `generateMetadata` functions in the tree.
Previously if we eager evaluated a child metadata function that threw an
error e.g. `notFound()` and but the parent metadata function took longer
the thrown error would be an unhandled rejection causing the process to
crash depending on the environment.

Fixes: NEXT-2588


Closes NEXT-2786
2024-03-12 17:23:02 +00:00
Apostolos Tsakpinis
a00458b5e9
fix typo in server/config.ts (#62795)
lager -> larger

---------

Co-authored-by: samcx <sam@vercel.com>
2024-03-11 19:12:00 +00:00
Tobias Koppers
b4b757c25d
ignore fully dynamic requests on server side (#62949)
### What?

make sure that we don't error for dynamic requests on server side.

It will throw at runtime when using a dynamic request.

### Why?

Not all packages are fully bundler compatible, but still work when only
using the parts that work. We don't want to block users from using them
by having an hard compile error.

### How?


Closes PACK-2675
2024-03-11 08:41:33 +00:00
mattddean
6da6388b62
Correctly deserialize undefined unstable_cache data (#59126)
<!-- 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 #

-->

The value `undefined` can be saved to the incremental cache as
`undefined` (`JSON.stringify(undefined)`) with no errors, but when
retrieving it, we attempt to parse it as JSON using
`JSON.parse(undefined)`. This throws an error. We should instead
deserialize `undefined` as `undefined` when retrieving.

relevant discussion: #59087

---------

Co-authored-by: Sam Ko <sam@vercel.com>
2024-03-08 22:07:09 -08:00
Jiachi Liu
664073e86f
Fix metadata url cases should not append with trailing slash (#63050)
### What

Exclude the cases like external urls and relative urls with query from
appending trailing slash when it's needed.

The process is:
- If it's a uncertain string path (relative url, could start with `'./'`
or `/`), convert to relative that starts with `/`;
- then we covert the url (string or URL) to string url
- We do the check if we need to append the trailing slash

### Why

In #62109 we added functionality that can only append trailing slash
when we appended trailing slash to some metadata url like `canonical`
url and open graph url when the config is enabled.
For urls with queries, the trailing slash can also be omitted.
For the external urls (different origin comparing to `metadataBase`) we
don't need to append trailing slash as they're not the same web app.

x-ref: [slack
thread](https://vercel.slack.com/archives/C0676QZBWKS/p1709845946033929)

Closes NEXT-2762
Closes NEXT-2753
2024-03-08 21:16:16 +01:00
OJ Kwon
daec5be052
test(scss): rename test suites (#63060)
### What

To verify manifest issues.


Closes PACK-2697
2024-03-08 10:57:02 -08:00
Wyatt Johnson
ea56c8f7ad
DX: add route context to dynamic errors for app routes (#62844)
Gives the users pathname context on routes that access Dynamic API's so
that if these errors are caught they can modify their code accordingly.
This is a followup to #61332.


Closes NEXT-2695
2024-03-08 11:35:24 -07:00
Zack Tanner
77f88004a8
fix flakey app-action test (#63021)
This test is flaking because the assertion before it triggers a redbox
error, and the HMR event to remove the redbox is occasionally happening
after we've moved onto the next test assertion. It also just checks for
"h1" which is heavily overloaded in this test suite for various UI
elements so I added a more specific selector.


[x-ref](https://github.com/vercel/next.js/actions/runs/8195295576/job/22413257207?pr=63019#step:27:1550)

<!-- 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-2756
2024-03-07 15:15:20 -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
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
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
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
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
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
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
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
栗原和也
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
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
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
Zack Tanner
48bad4e894
fix router crash on revalidate + popstate (#62383)
### What
When the popstate action is fired (as is the case in a browser back
button), if the page you're going back to has missing cache node data,
the router will crash.

### Why
Almost all router actions will suspend at the app-router level with the
exception of `ACTION_RESTORE`. This was to address an issue where
suspending in the router would add enough delay for browser scroll
restoration behavior not to work.

As a result, when going back to the page with missing data, app-router
wouldn't suspend but layout-router would suspend on the missing data
while triggering a lazy fetch. We trigger a server-patch with the
applied lazy data, but when React replays the render, it will replay the
branch without the cache node data applied. This results in the router
getting caught in a loop of suspending, applying the cache node,
replaying the branch without the cache node, and eventually crashing due
to an error thrown by React to prevent re-suspending indefinitely.

### How
This adds a property to the cache node to signal if the lazy data has
been resolved. If it has been, we won't call the server patch action
again.

Fixes #61336
Closes NEXT-2438
2024-02-27 10:15:36 -08:00
Jiachi Liu
c221fc4508
Create react server condition alias for next/navigation api (#62456)
### What

Introduce a `react-server` export condition of `next/navigation`, which
only take effects in RSC layer. And it will only contain `notFound` and
`redirect` related APIs, which can be shared in both server components
and client components environment. This export excludes those APIs
working with React context which are only working in client components.

### Why

We fixed an issue bad alias for react-server condition of react itself
in
https://github.com/vercel/next.js/pull/61522/files#diff-ecb951c8d26893f6d1e4425a873b399d52346ef63eb90fba79d980cef2fabe8cL35
, this was a good fix. But we found that if you're using edge runtime
with `next/navigation` it will error with bundling that you're attempted
to import some client component hooks such as `useContext` from react.

So we introduced a `react-server` version of `next/navigation` that
doesn't interoplate with any client hooks, can we'll bundle that one
instead of original `next/navigation` when you're using it in server
components or app routes.

Closes NEXT-2583
Closes NEXT-2519
Fixes #62187
2024-02-26 13:35:44 +01:00
Jiachi Liu
e5d604f33b
Upgrade vendored react (#62326)
### React upstream changes

- https://github.com/facebook/react/pull/28333
- https://github.com/facebook/react/pull/28334
- https://github.com/facebook/react/pull/28378
- https://github.com/facebook/react/pull/28377
- https://github.com/facebook/react/pull/28376
- https://github.com/facebook/react/pull/28338
- https://github.com/facebook/react/pull/28331
- https://github.com/facebook/react/pull/28336
- https://github.com/facebook/react/pull/28320
- https://github.com/facebook/react/pull/28317
- https://github.com/facebook/react/pull/28375
- https://github.com/facebook/react/pull/28367
- https://github.com/facebook/react/pull/28380
- https://github.com/facebook/react/pull/28368
- https://github.com/facebook/react/pull/28343
- https://github.com/facebook/react/pull/28355
- https://github.com/facebook/react/pull/28374
- https://github.com/facebook/react/pull/28362
- https://github.com/facebook/react/pull/28344
- https://github.com/facebook/react/pull/28339
- https://github.com/facebook/react/pull/28353
- https://github.com/facebook/react/pull/28346
- https://github.com/facebook/react/pull/25790
- https://github.com/facebook/react/pull/28352
- https://github.com/facebook/react/pull/28326
- https://github.com/facebook/react/pull/27688
- https://github.com/facebook/react/pull/28329
- https://github.com/facebook/react/pull/28332
- https://github.com/facebook/react/pull/28340
- https://github.com/facebook/react/pull/28327
- https://github.com/facebook/react/pull/28325
- https://github.com/facebook/react/pull/28324
- https://github.com/facebook/react/pull/28309
- https://github.com/facebook/react/pull/28310
- https://github.com/facebook/react/pull/28307
- https://github.com/facebook/react/pull/28306
- https://github.com/facebook/react/pull/28315
- https://github.com/facebook/react/pull/28318
- https://github.com/facebook/react/pull/28226
- https://github.com/facebook/react/pull/28308
- https://github.com/facebook/react/pull/27563
- https://github.com/facebook/react/pull/28297
- https://github.com/facebook/react/pull/28286
- https://github.com/facebook/react/pull/28284
- https://github.com/facebook/react/pull/28275
- https://github.com/facebook/react/pull/28145
- https://github.com/facebook/react/pull/28301
- https://github.com/facebook/react/pull/28224
- https://github.com/facebook/react/pull/28152
- https://github.com/facebook/react/pull/28296
- https://github.com/facebook/react/pull/28294
- https://github.com/facebook/react/pull/28279
- https://github.com/facebook/react/pull/28273
- https://github.com/facebook/react/pull/28269
- https://github.com/facebook/react/pull/28376
- https://github.com/facebook/react/pull/28338
- https://github.com/facebook/react/pull/28331
- https://github.com/facebook/react/pull/28336
- https://github.com/facebook/react/pull/28320
- https://github.com/facebook/react/pull/28317
- https://github.com/facebook/react/pull/28375
- https://github.com/facebook/react/pull/28367
- https://github.com/facebook/react/pull/28380
- https://github.com/facebook/react/pull/28368
- https://github.com/facebook/react/pull/28343
- https://github.com/facebook/react/pull/28355
- https://github.com/facebook/react/pull/28374
- https://github.com/facebook/react/pull/28362
- https://github.com/facebook/react/pull/28344
- https://github.com/facebook/react/pull/28339
- https://github.com/facebook/react/pull/28353
- https://github.com/facebook/react/pull/28346
- https://github.com/facebook/react/pull/25790
- https://github.com/facebook/react/pull/28352
- https://github.com/facebook/react/pull/28326
- https://github.com/facebook/react/pull/27688
- https://github.com/facebook/react/pull/28329
- https://github.com/facebook/react/pull/28332
- https://github.com/facebook/react/pull/28340
- https://github.com/facebook/react/pull/28327
- https://github.com/facebook/react/pull/28325
- https://github.com/facebook/react/pull/28324
- https://github.com/facebook/react/pull/28309
- https://github.com/facebook/react/pull/28310
- https://github.com/facebook/react/pull/28307
- https://github.com/facebook/react/pull/28306
- https://github.com/facebook/react/pull/28315
- https://github.com/facebook/react/pull/28318
- https://github.com/facebook/react/pull/28226
- https://github.com/facebook/react/pull/28308
- https://github.com/facebook/react/pull/27563
- https://github.com/facebook/react/pull/28297
- https://github.com/facebook/react/pull/28286
- https://github.com/facebook/react/pull/28284
- https://github.com/facebook/react/pull/28275
- https://github.com/facebook/react/pull/28145
- https://github.com/facebook/react/pull/28301
- https://github.com/facebook/react/pull/28224
- https://github.com/facebook/react/pull/28152
- https://github.com/facebook/react/pull/28296
- https://github.com/facebook/react/pull/28294
- https://github.com/facebook/react/pull/28279
- https://github.com/facebook/react/pull/28273
- https://github.com/facebook/react/pull/28269

Closes NEXT-2542


Disable ppr test for strict mode for now, @acdlite will check it and
we'll sync again
2024-02-23 12:46:58 +01:00
Shu Ding
b0c6b00643
Fix module-level Server Action creation with closure-closed values (#62437)
With Server Actions, a module-level encryption can happen when you do:

```js
function wrapAction(value) {
  return async function () {
    'use server'
    console.log(value)
  }
}

const action = wrapAction('some-module-level-encryption-value')
```

...as that action will be created when requiring this module, and it
contains an encrypted argument from its closure (`value`). This
currently throws an error during build:

```
Error: Missing manifest for Server Actions. This is a bug in Next.js
    at d (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/chunks/1772.js:1:15202)
    at f (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/chunks/1772.js:1:16917)
    at 714 (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:2806)
    at t (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/webpack-runtime.js:1:127)
    at 7940 (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:941)
    at t (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/webpack-runtime.js:1:127)
    at r (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:4529)
    at /Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:4572
    at t.X (/Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/webpack-runtime.js:1:1181)
    at /Users/shu/Documents/git/next.js/test/e2e/app-dir/actions/.next/server/app/encryption/page.js:1:4542
```

Because during module require phase, the encryption logic can't run as
it doesn't have Server/Client references available yet (which are set
during the rendering phase).

Since both references are global singletons to the server and are
already loaded early, this fix makes sure that they're registered via
`setReferenceManifestsSingleton` before requiring the module.

Closes NEXT-2579
2024-02-23 12:00:24 +01:00
Zack Tanner
93eb32d96a
Remove default fallback behavior when route group is missing a default (#62370)
This test case was added in #59752, but this doesn't seem like the
correct behavior.

The original PR was intended to be smart about resolving `/default.tsx`
to a route group default (e.g. `/(foo)/default.tsx`) when one wasn't
specified. But since the route group is creating a new hierarchy in the
tree and defines its own layout, if the route group layout doesn't
specify a default, then the not found behavior seems correct.

To fix unexpected not-found behavior in this case, you should specify a
default at the same level as the layout where the missing slot(s) might
be rendered.

Closes NEXT-2565
2024-02-22 16:13:50 +01:00
Zack Tanner
7b5951827f
Fix test flake (#62379)
This onClick isn't actually being used by the test and seems to be
causing a flake unrelated to the test assertions. This removes the
unused code for now so we can still keep the relevant part of the test
in-tact. (Specifically, this test is asserting that we're using the
correct prefetch cache entry for interception routes that originate from
different trees but resolve to the same URL)

<!-- 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-2568
2024-02-22 00:19:49 -08:00
JJ Kasper
40bc285d21
Update data cache max size error (#62348)
Makes the error message more specific to Next.js and provides specific
size that exceeded the limit.

x-ref: [slack
thread](https://vercel.slack.com/archives/C05U6TZ2DCP/p1708543103375799)

Closes NEXT-2559
2024-02-21 22:03:20 +00:00
Zack Tanner
d371f648d2
Renew prefetch cache entry after update from server (#61573)
### What
When a prefetch cache entry becomes "stale", it'll remain stale until
eventually it gets evicted. However during that stale window, the cache
is never revalidated, and so instant navigations stop working and data
is fetched from origin every navigation.

### Why
The `lastUsedTime` entry on the prefetch cache is currently only updated
after the first read. Once it becomes stale, `applyFlightData`'s
recursive functions will see that there is no longer a reusable prefetch
cache entry, and will trigger a lazy fetch of the new data on every
subsequent navigation.

### How
This updates prefetch cache handling to always ensure we’re using a
fresh or reusable prefetch cache entry. This means that stale prefetch
entries will be refreshed on a navigation event. As a result of this,
I’ve had to disable one of our tests that relies on this stale cache
behavior. It’s not ideal that we’re blocked on the loading boundary when
fetching child segment data—ideally we can refactor this to cache the
loading component in the CacheNode and copy it over on navigations,
similar to how ‘head’ is handled. I’ll work on this in a separate PR.

Note: The new client cache test for this is disabled in PPR for the same
reason as the other tests: auto prefetching with PPR navigations is
currently loading fresh data rather than reusing the prefetch cache.


Fixes #58969
Fixes #58723
Closes NEXT-1904
2024-02-20 09:07:18 -08:00
Jiachi Liu
d7d636adf5
Tree shake the unused exports in direct relative imported client component module (#62238)
### What & Why

This PR helps fixes a long time tree-shaking issue that if you're import
some identifiers from client components, the whole client component is
being included in the client chunk. Because we're using import eager
mode in webpack to include all the client component modules that make
sure they're present in SSR entry and browser entry when they're
transformed to client reference on RSC layer.

But the way we collect client components is a bit "aggressive" where
contains some spaces to optimize.

### How

We change the collected client components from simpliy collecting it
resolved module request, into collecting both the imported identifiers
(by server components) and the module request. And when we inserted the
used client components imports into the SSR and Client entry, leverage
webpack magic comments `"webpackExports"` to only contain the used
exports in the bundle. Thank you webpack for this nice feature : )

Along the way we also fixed an issue that when you only used default
export, the `default` export itself should also be proxied when the
bundle is in ESM.

#### Notice

There's a limitation yet that it can't work with barrel file, if you
have a shared component `index.js` to re-export the changes several
client components there and you only partially import few from
`index.js` it won't work. For the cases that the node_modules package
contain a barrel file importing multiple client components, please use
[optimizePackageImports](https://nextjs.org/docs/app/api-reference/next-config-js/optimizePackageImports)
config for now. We'll have follow up optimizations

### Testing Result

If we compare the `react-aria-components` the reproduction from #60246,
you'll see the result being optimized a lot:

#### After vs Before

134KB being tree-shaked out 🤯 
```
Route (app)                              Size     First Load JS
┌ ○ /                                    324 B           127 kB
├ ○ /_not-found                          872 B          86.5 kB
└ ○ /other-page                          174 B           127 kB
```

```
Route (app)                              Size     First Load JS
┌ ○ /                                    325 B           261 kB
├ ○ /_not-found                          870 B          86.5 kB
└ ○ /other-page                          176 B           261 kB
```

Fixes #60246
Related report: https://github.com/adobe/react-spectrum/issues/5639
Closes NEXT-2527
phase 1 of NEXT-1799

---------

Co-authored-by: Shu Ding <g@shud.in>
2024-02-20 17:07:25 +01:00
Tobias Koppers
8250a8419a
add turbo.resolveExtensions to allow to customize extensions (#62004)
### What?

* add `turbo.resolveExtensions` to allow to customize extensions in
Turbopack

fixes PACK-2335
Fixes https://github.com/vercel/turbo/issues/4934
2024-02-19 09:07:09 +00:00
Donny/강동윤
d8865d040a
test: Make css bundle assertion work also for turbopack (#62127)
### What?

Fix one assertion about CSS files emitted by turbopack.

### Why?

Turbopack generates `/_next/static/chunks/2225ce._.css`, which does not
match the regex.
Note that it has `._.css`. The previous assertions match on
`[^.]+\.css`, which does not support two dots in the file name.

I tried `/<link rel="stylesheet" href=".+\.css(\?v=\d+)?"/g`, but it
captured 3 `link` tags at once. So I used `/<link rel="stylesheet"
href="[^<]+\.css(\?v=\d+)?"/g`.


### How?

Closes PACK-2413
2024-02-19 03:35:13 +00:00
Leah
ca1b6184c8
chore: update test template to use nextTestSetup (#62154)
### Why?

Less indentation and allows for IDE integration.



Closes PACK-2523
2024-02-16 17:30:54 +01:00
Jiachi Liu
cbdd1d2654
Fix handling subpath for server components externals (#62150)
Follow up of #61986 where we didn't handle the subpath externals very
well, found by @sokra

Closes NEXT-2517
2024-02-16 17:24:12 +01:00
Tim Neutkens
212553958c
Fix issue with ComponentMod being read in Turbopack (#62141)
## What?

Fixes an issue where trying to build an edge runtime page with
generateStaticParams fails to read `ComponentMod`. Discussed with @sokra
and found that changing it to `import()` resolves the problem.

<!-- 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-2514
2024-02-16 16:06:38 +01:00
Donny/강동윤
12639c4847
test: Make css deduplication assertion work for turbopack (#62128)
### What?

Fix one assertion about CSS files emitted by turbopack.

### Why?

Webpack generates 3 links with `?v=` query, and 2 extra links without
`?v=` query. Turbopack does not have query string, so we match 5 links.

### How?

Closes PACK-2414
2024-02-16 17:37:55 +09:00
Jiachi Liu
3c4ec650b3
Should not warn metadataBase missing if only absolute urls are present (#61898)
### What

* Narrow down the metadata base warnings only when there's any relative
urls need to be resolved, if there's only absolute urls present, no need
to resolve and we don't warn.
* Polish the error message, updated from "metadata.metadataBase is not
set ..." to "metadataBase property in metadata export is not set ..."

### Why

It will be confusing if we're still show metadataBase warning when
there's no need to set one, since the social image cards only have
absolute urls

Closes NEXT-2426
2024-02-16 00:29:55 +01:00
Jiachi Liu
dc71a5721b
Fix trailing slash for canonical url (#62109)
### What

We should respect the `trailingSlash` config for metadata canonical url,
this PR is adding the handling for strip or keep the trailing slash for
canonical url. Passing down trailingSlash config to metadata resolving
to decide how we handle it.

### Why

The tricky one was `/` pathname, when visiting the origin directly, that
it will always have at least `/` in the URL instance. But for the
default `origin`, it shouldn't show the `/` if the `trailingSlash`
config is `false`. Also it should show trailing slash for all pathnames
if that config is enabled.

BTW there's a `__NEXT_TRAILING_SLASH` env but since we're using the
fixed nextjs runtime module, so this can't be dynamically replaced in
the metadata resolving modules. So we didn't use it

Fixes #54070 
Closes NEXT-2424
2024-02-15 18:57:15 +01:00
Zack Tanner
5309c30c7d
make router restore action resilient to a missing tree (#62098)
### What
Following an anchor link to a hash param, and then attempting to use
`history.pushState` or `history.replaceState`, would result in an MPA
navigation to the targeted URL.

### Why
In #61822, a guard was added to prevent calling `ACTION_RESTORE` with a
missing tree, to match other call-sites where we do the same. This was
to prevent the app from crashing in the case where app router internals
weren't available in the history state. The original assumption was that
this is a rare / unlikely edge case. However the above scenario is a
very probable case where this can happen, and triggering an MPA
navigation isn't ideal.

### How
This updates `ACTION_RESTORE` to be resilient to an undefined router
state tree. When this happens, we'll still trigger the restore action to
sync params, but use the existing flight router state.

Closes NEXT-2502
2024-02-15 14:10:29 +00:00
Tim Neutkens
bf5ddd4c25
More hot-reloader-turbopack refactors (#62055)
## What?

Follow-up to #61993

More code moved to be used for builds in the future.

<!-- 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-2492
2024-02-15 08:53:36 +01:00
Jiachi Liu
8d28d5954e
test: rename node_modules_bak to node_modules (#62066)
We switched to `pnpm` for testing instead of `yarn` for e2e tests
containing customized node_modules packages, it works with
`node_modules` folder before. Rename the existing `node_modules_bak`
hack to make it easy to test with.

Previously we use `yarn` but it will clean `node_modules` folder so we
have to use another script to copy packages, it's not a required thing
now so we can test package from node_modules directly without renaming
folders locally

Closes NEXT-2496
2024-02-15 00:42:35 +01:00
Jiachi Liu
cfedc529c7
Fix extra swc optimizer applied to node_modules in browser layer (#62051)
### What

Disable swc transform optimizer for node_modules in browser layer of app
router bundles

Fixes #61858
Fixes #60644 
Fixes #60920
Fixes #61740
Closes NEXT-2418

### Why

In browser there could be not only one runtime, it could have both js
worker and browser. In js worker the `typeof window` is not as same as
in browser, so disabling the swc optimizer which will replace the code.
Leave the condition as it as.
2024-02-14 21:58:39 +01:00
Leah
60f0837b67
refactor(tests): make chain more "correct" (#51728)
### Why?

I really dislike the way `.chain` works right now, it shouldn't mutate
the `BrowserInterface`, this PR changes it so it's just a pure chain
without weird side effects.

One example with the current version (before this PR):
```
const el = browser.elementByCss('#version-2')
await el.text()
// throws
await el.text()
```

### Additional Changes

- removes selenium (which is completely unused)
- updates playwright
- makes the playwright tracing not error all the time
2024-02-14 20:14:24 +01:00
Zack Tanner
fffa4c3d9b
fix navigation applying stale data when triggered from global not found (#62033)
### What
When a global not found page is rendered, and when the not-found page or
containing layout has a link with `prefetch: auto` back to the root
page, the router would update the URL but not correctly swap out the
not-found component with the page component.

### Why
With auto prefetching (which is the default when `prefetch` is left
unspecified on a link), the router will perform a partial prefetch on
dynamic pages. This means it'll fetch the flight data _without_ React
nodes and store it in the prefetch cache. On navigation, this is used to
determine where we already have cached React nodes and where we need to
trigger a lazy fetch to get new data. However, global not found pages
are peculiar in that they will always contain a data path like: `['', {
children: ['__PAGE__', {}] }]` since they are inserted at the root. This
means that if there's also a page component that corresponds with the
same path, the router will incorrectly think it already has cache node
data for it.

### How
During SSR when the `asNotFound` flag signals to the renderer that the
component we're rendering is matching the global not-found page, we
modify the segment key to be something unique so the data path won't
collide with a top-level page.

In
[fc01c8e](fc01c8e7f7)
I added handling only on the server to modify the segment key. This
still fixes the issue, but at the cost of triggering an MPA navigation
on the client because it's treated as a root layout change

In
[69d5687](69d5687765)
I added client handling to not treat this special segment key as a root
layout change, and to signal to the router it needs to refetch the data.
This ensures we don't do an MPA navigation.

Fixes #61956
Closes NEXT-2481

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-02-14 10:46:31 -08:00