Commit graph

743 commits

Author SHA1 Message Date
Jiachi Liu
65ecd9c3e2
Fix missing metadataBase for static tw,og image resolving (#46243)
Replacement for #46156
Closes NEXT-587

* `metadataBase` will always need to be provided for twitter image and
opengraph image
* Fixing the metadataBase isn't picked up by static og/twitter images

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-22 14:21:52 +01:00
Luba Kravchenko
9d2824e995
Update app dir cache handling (#46081)
Updates handling for app dir caching for edge runtime and adds additional tests. 

x-ref: NEXT-511

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-02-22 07:10:25 +00:00
JJ Kasper
aa7cc31b6c
Fix app-dir vary test in deploy mode (#46224
x-ref:
https://github.com/vercel/next.js/actions/runs/4238645116/jobs/7366078010
2023-02-21 18:51:57 -08:00
Tim Neutkens
5160aa72a9
Fix route.js trailingSlash handling (#46185)
<!--
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:
-->

Fixes NEXT-598

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-21 17:19:56 -08:00
Jiachi Liu
ccdc836713
Fix flaky script test (#46211)
x-ref:
https://github.com/vercel/next.js/actions/runs/4198362898/jobs/7282523186
2023-02-21 15:52:40 -08:00
JJ Kasper
1253a3035f
Add ISR handling for app routes (#46133)
Follow-up to https://github.com/vercel/next.js/pull/45716 this updates
the ISR handling for app routes. This also ensures the E2E deploy tests
are running for the `app-routes` test suite.

fixes NEXT-509

Relies on https://github.com/vercel/vercel/pull/9489

---------
2023-02-21 15:25:42 -08:00
Shu Ding
7af4308b11
Fix handle extracted CSS modules without layer info (#46200)
Closes #46091. As explained in the comments, in certain cases CSS
extracted via mini-css-extract-plugin doesn't have layer info attached
and we can't simply skip them. Since this is more of an optimization,
it's fine to add a special case for CSS.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-22 00:02:48 +01:00
Shu Ding
0ab8dcb09d
Fix client boundary defined in a module (#46171)
This PR fixes the bug where a client boundary (`"use client"`) is defined in a module (`"type": "module"`). Currently Next.js throws this error:

```
error - Error: Cannot find module 'private-next-rsc-mod-ref-proxy'
```

...that will be resolved with this PR.

The only limitation after this fix is, you can't have `export *` under a client boundary in a module. Added a error message for that.

NEXT-595

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-21 15:20:45 +00:00
Jiachi Liu
888384c5e8
Add icon descriptor property media and fetchPriority (#46149)
* Add `fetchPriority` and `media` property to icon descriptor
* Add more jsdoc

Closes NEXT-544
Fixes https://github.com/vercel/next.js/issues/45859

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-02-20 22:27:55 +00:00
Jimmy Lai
bee51b6c87
feat: add instrumentation hook (#46002)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-02-20 19:04:09 +01:00
Jiachi Liu
2f967ccd48
Detect invalid metadata exports errors in next-swc (#46077)
* Use next-swc to detect invalid metadata exports
* In client components page under app dir, metadata exports are not
available
* In server components page under app dir, metadata and gM exports can
be exported together

Move sync metadata / async metadata typing resolving test to UT

Closes NEXT-368

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-19 08:36:50 +01:00
Tim Neutkens
28eb15f6c6
Fix manifest error when using route.js (#46102)
This ensures there is no client component entry created for route.js.
@shuding is going to investigate further why this would break the
manifest generation in development.


Fixes #45956
Fixes NEXT-588

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-18 20:31:49 +01:00
Shu Ding
0fe793f51c
Add vary header to responses from pages and Edge SSR (#46073)
This PR ensures that the `vary` header is set for pages responses and
Edge SSR responses too, to avoid potential caching problems when
navigating between them.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-02-17 22:54:48 -08:00
Tim Neutkens
ae3442c37a
Fix RSC navigation when overriding headers in middleware (#46049)
Fixes NEXT-583

Ran into this when looking into adding an integration test for the RSC
normalizing PR.

Middleware has the ability to override `headers` which causes
client-side navigation to break as it'll remove the `rsc` header which
causes Next.js to respond with the HTML response instead of the RSC
payload.

This PR ensures the RSC headers are always copied over as middleware
does not get access to them.

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-17 16:34:35 +01:00
Jiachi Liu
15aa25f27a
Refactor freezing metadata while resolving and fix title merging (#45965)
Addressing @gnoff 's comments from #45923

* Only freezing for the parentMetadata `argument`
* Group dev specific code in one place for less branches and better DEC
* Concurrently run the metadata resolving promises

Fix title merging: should use the parent layout instead of adjacent
layout
2023-02-16 17:02:39 -08:00
Jiachi Liu
ee0cbeceb7
Fix metadata manifest field rendering (#46004)
x-ref:
https://github.com/vercel/next.js/pull/45945#issuecomment-1433278890

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

---------
2023-02-16 15:29:28 -08:00
Gal Schlezinger
282c1a0637
[edge] support edge-light exports when bundling edge functions (#45188)
This PR implements `edge-light` as a main field for bundling edge
functions as defined in https://runtime-keys.proposal.wintercg.org

Resolves EC-614

## Feature

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

---------
2023-02-16 13:30:34 -08:00
Tim Neutkens
5599c47ed6
Add edge support for route handlers (#45990)
- Add test for edge route
- Add edge route loader
- Ensure edge route does not trigger static generation
- Remove unused import
- Use new loader during compilation
- Add names for routeKind to help debugging
- Ensure route is considered a appDir page
- Return response from edge runtime
- Handle edge route in dev and prod

Fixes NEXT-510

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-16 16:32:37 +01:00
Tim Neutkens
ffee09b6ff
Move initial head (#45695)Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Move initial into the cache, so the top level boundaries will wrap the
head contents. Then we can use navigation API like `notFound` in the
`generateMetadata`, the notFound errors could be still captured in that
case

Closes NEXT-292

Added tests for not found in metadata

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-02-16 16:26:48 +01:00
Hannes Bornö
435eca3fc5
Add next/font import (#45891)
Enables using `next/font` by adding `@next/font` as a dependency and
reexporting its loaders.

Always generates the `font-loader-manifest` as we can't know beforehand
if the user intends to use `next/font` or not.

Also adds telemetry for `next/font` usage.

The tests are updated to use `next/font`. But `@next/font` is tested in
`test/e2e/next-font/index.test.ts` and `test/e2e/app-dir/next-font` as
well to ensure it doesn't break.

Fixes NEXT-351

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-16 15:33:39 +01:00
Hannes Bornö
0484dc4097
Use metadata API in automatically created root layout (#45938)
Use the Metadata API instead of creating a `head.js` when automatically
creating a root layout. The generated layout is the same as the one in
https://github.com/vercel/next.js/pull/45819, but with a different title
and description.

Automatic root layout:
```tsx
export const metadata = {
  title: 'Next.js',
  description: 'Generated by Next.js',
}

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}
```

Fixes NEXT-545

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-16 15:17:58 +01:00
JJ Kasper
3e919b6add
Fix flakey app cli output checks (#45960)
x-ref:
https://github.com/vercel/next.js/actions/runs/4186567737/jobs/7255320047
2023-02-15 11:33:17 -08:00
Jiachi Liu
9101440020
Metadata fields improvements (#45945)
Resolves the comments from beta docs

* fix typing of `metadata.authors` rendering
* add `metadata.manifest` field

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-15 17:35:50 +00:00
Hannes Bornö
087aa6e83e
Log dev error in Server Router (#45951)
Fixes NEXT-561

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-15 17:09:48 +00:00
Jiachi Liu
2b2c7462cd
Freeze resolved metadata object in dev mode (#45923)
In dev mode, instead of `resolve(resolvedMetadata)` for the parent metadata argument we pass down `resolve(freeze(deepClone(resolvedMetadata)))` as parent metdadata, this approach will avoid users mutating resolved metadata manually but still allowing next manage to merge it during resolving

Closes NEXT-559

- [x] linked task
- [x] e2e tests
2023-02-15 13:49:34 +00:00
JJ Kasper
778a2a7442
Fix app routes on deploy (#45931)
Follow-up to https://github.com/vercel/next.js/pull/45716 this ensures
we correctly construct the initial URL value as it must be a fully
qualified URL. Existing tests caught this failure when running in deploy
mode.
2023-02-15 09:54:39 +01:00
JJ Kasper
7d8f85bd8d
Update E2E deploy tests (#45929)
Updates test cases that aren't expected to work for deploy mode at the
moment.

x-ref:
https://github.com/vercel/next.js/actions/runs/4180235531/jobs/7241206278
2023-02-14 20:00:58 -08:00
Shu Ding
e50d22b992
Include tsconfig.json in tests (#45879)
As per
https://github.com/vercel/next.js/pull/45670#issuecomment-1428729000,
it's very necessary to include `tsconfig.json` in our tests as we need
to test specific TS configurations sometimes.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-14 18:37:09 -08:00
Shu Ding
c8fe390041
Rename manifest file names (#45877)
Here we rename names of manifest files to align better with React.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-15 01:03:17 +00:00
Jiachi Liu
4ef0bcc779
test: update flaky app dir test (#45921) 2023-02-14 16:18:21 -08:00
Wyatt Johnson
74ca99c866
Server Router Improvements (#45716)
This adds updated matching handle for the server to separate out the matching and executing of different route types e.g. page routes, API routes, and app routes. 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-02-15 00:16:45 +00:00
Tim Neutkens
f3daa1c364
Add missing isRootLayout when creating optimistic tree (#45899)
Fixes #45750
Closes #45822 
Fixes NEXT-514

Ensures rootlayout marker is copied into the optimistic tree.

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-14 14:06:58 +01:00
JJ Kasper
e573b20756
Update middleware prefetch handling (#45772)
When doing external rewrites with middleware we shouldn't bail for the
prefetch case as this is valid and the bailing can occur on the
destination application.

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-13 09:02:59 -08:00
Tim Neutkens
db2e9b2870
Add tests for parallel routes / interception and handle router state patch merging client-side (#45615)
Added tests:
- Add tests for interception+parallel and interception
- Add test for  parallel route tab bar
- Add test for back/forward navigation on parallel routes

Core changes:
- Updated handling of parallel route matcher `@` to produce the correct
router tree
- Fixed global-error resolving, it was resolving from the `page.js` on
each level. It should only live next to the root layout only, so now it
resolves when it finds the root layout.
- `applyRouterStatePatchToTree` now merges the levels of the original
tree and the patch. This ensures parallel routes that are not affected
by the response from the server are not removed from the tree.
- Ensure cache nodes are not removed when they're not affected by tree
patch, this ensures parallel route cache nodes will not be removed when
navigating.

Other changes:
- Added launch app-dir build to launch.json for vscode debugger


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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-13 16:12:44 +01:00
Jiachi Liu
a5fe64cd06
Static og and twitter image files as metadata (#45797)
## Feature

Closes NEXT-265
Fixes NEXT-516


- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-13 13:57:55 +00:00
Hannes Bornö
8fb2f59169
Add status code to app-render redirect response (#45846) 2023-02-13 14:12:16 +01:00
Tim Neutkens
f49cc8da17
Use text/x-component for RSC response (#45808) 2023-02-11 18:44:53 +01:00
Shu Ding
59a63eda0a
Add experimental route type checking (#45761)
Implements alpha version of type checking for `Link`'s `href`. To opt-into this feature, `experimental.appDir` and `experimental.typedRoutes` need to be enabled, and the project needs to be using TypeScript.

Once enabled, Next.js will generate a link definition in `.next/types` that contains information of existing routes, and it will be included by TS. In the definition we simply declare types for the `Link` module.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-11 15:06:39 +00:00
Tim Neutkens
1faa599568
Add additional tests for @next/mdx (#45585)Co-authored-by: Shu Ding <g@shud.in>
Adds additional integration tests for `@next/mdx`.

- Test mdx-rs
- Test `mdx-components.tsx`
- Tests development and production. Previously it only checked
development.

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

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-02-11 13:37:00 +01:00
Tim Neutkens
d4df2bf2da
Use text/plain content-type for RSC responses (#45783)Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
First step for making RSC responses use gzip/brotli.
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-11 13:26:43 +01:00
Shu Ding
98d6e47234
Fix type checking for generateStaticParams (#45788
Address the problem reported in
https://github.com/vercel/next.js/discussions/41745#discussioncomment-4936492.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-10 11:16:38 -08:00
Shu Ding
1c5983fe95
Prefix basePath in navigate and prefix methods in app router (#45771)
Closes #41824.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-10 13:01:00 +00:00
Jiachi Liu
484f4724f4
Separate navigation and hooks tests into new test suites (#45766)
Moving tests to reduce app-dir/app/index.test.ts running duration
2023-02-10 00:38:39 +00:00
Shu Ding
d841f8ea83
Move CSS tests out of the main test suite (#45765)
No changes in this PR, just move out all CSS related tests out of
app-dir/app/index.tests.ts into a separate suite.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-09 23:22:53 +01:00
Jiachi Liu
e8e85effd6
Support favicon.ico for metadata (#45759
## Feature

* Picking up root favicon (`/app/favicon.ico`) into icons, and add
missing `type` prop for `<link>`
* Fixes the `/favicon.ico` 500 in dev server (`fileExists` checking
part)

Closes NEXT-475

- [x] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [x] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-09 13:14:09 -08:00
Shu Ding
bb9bb64864
Fix global CSS loader behavior when appDir is enabled (#45739)
The current behavior is, when `appDir` is enabled, global CSS should be
allowed to be imported from anywhere (because components can be re-used
by both pages and app). Changes in #45619 made it not behaving correctly
and this PR fixes it.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-09 14:33:45 +01:00
JJ Kasper
77bab39097
Ensure bundle 404 can be rewritten in dev (#45728)
This fixes a mismatch in behavior between dev/start where bundle 404s
could be rewritten in production but not dev. Also ensures we have a
regression test for this behavior.

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

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

---------

Co-authored-by: Shu Uesugi <shu.chibicode@gmail.com>
2023-02-08 22:02:39 -08:00
Jiachi Liu
628bc4c07b
Allow setting metadataBase for metadata (#45719)
## Feature

For property that needs to be resolved as URL, compose with
`metadataBase` if it's provided

Closes NEXT-398

### Detail updates

* fix issue that path having extra `/` in the middle for pages path
under app dir
* don't render Meta if value is empty string, e.g. `og:title` can be
`''` from value of `title.absolute`
* did some refactor to separate resolvers into different files
* add some unit tests for resolve urls

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

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-02-09 01:35:19 +01:00
Vu Van Dung
7654d7bc2d
Allow generateMetadata to be synchronous (#45696)
The very-newly-released `generateMetadata` function currently does not
allow itself to be synchronous. It leads to situations like this

```ts
export async function generateMetadata() {
  return { title: "Hello, world!" };
}
```

where there's evidently no reason to use `async`, but it's forced by
Next.js.

This PR aims to remove this restriction: `generateMetadata` can be
synchronous now.

## Bug

- [x] Related issues linked using `fixes #45685`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

Signed-off-by: Vu Van Dung <me@joulev.dev>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-02-08 21:02:03 +01:00
Shu Ding
a25c32a9a0
Fix CSS loaders in pages when app dir is enabled (#45619)
This PR changes the loader logic from something like `ctx.hasAppDir ?
useAppLoaderForCSS : usePagesLoaderForCSS`, to a mental modal of
`[ctx.hasAppDir ? useAppLoaderForCSSInAppLayer : null,
usePagesLoaderForCSSInPagesLayer]`. This change makes sure that both
pages and app can exist and work well together, instead of a binary
switch.

Also renamed the loader with `-dev` removed, because it is used for
production build too.

NEXT-461

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-08 20:55:01 +01:00
JJ Kasper
434a8cb7d0
Fix missing hasHeader mock during revalidate (#45681)
Replaces usage of `hasHeader` of `getHeader` and also ensures we include
`hasHeader` in our `mockRes` we create during revalidate for good
measure.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Closes: https://github.com/vercel/next.js/issues/34929
Closes: https://github.com/vercel/next.js/issues/37338
Closes: https://github.com/vercel/next.js/issues/45481
2023-02-07 17:51:26 -08:00
Jiachi Liu
e36fb42e30
Add warning for head.js with metadata docs link (#45680)
Warn users when there's `head.js` being used in `app/`, and recommend to
use metadata. Will show a warning in console while rendering

Closes NEXT-268

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Lee Robinson <me@leerob.io>
2023-02-07 17:02:40 -08:00
JJ Kasper
01649d93ab
Skip prefetching for bots in app-router too (#45678)
Same as https://github.com/vercel/next.js/pull/40435 this ensures we
don't prefetch for bots in `app-router` as well.

Fixes: https://github.com/vercel/next.js/issues/45677

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-07 14:15:10 -08:00
Jiachi Liu
c26fc2456b
Picking apple-icon instead of apple-touch-icon (#45673)
Fix up a icon convention in #45612, we should pick up the
`apple-icon.<ext>` as this is a shorter path for users to remember.

Also addessing some feedbacks from @shuding in #45612

---------
2023-02-07 13:25:39 -08:00
Jiachi Liu
25dfdbb131
Support filebased metadata icon and apple touch icons (#45612)
This PR add supports for a shortcut for adding `icons.icon` or
`icons.apple` metadata for page or layout with static files.

Closes NEXT-263
Closes NEXT-260

If you specific icon.png or apple-touch-icon.png, they will be
automatically picked by and added into metadata as `icon` and
`apple-touch-icon` fields, and replace the `icons` field specified in
page/layout level metadata exports.

File matching rule:
```
icon -> /^icon\d?\.(ico|jpg|png|svg)$/
apple-touch-icon -> /^apple-touch-icon\d?\.(ico|jpg|png|svg)$/
```

## Feature

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-07 18:30:59 +01:00
Jan Kaifer
3827d8fbfb
Fix issue where layout-router wouldn't auto-scroll if we imported styles or fonts (#45487)
fixes https://github.com/vercel/next.js/issues/42492
2023-02-07 12:03:18 +00:00
Tim Neutkens
30a6c51296
Refactor server-patch-reducer and refresh-reducer to use applyFlightData and handleMutable (#45608)Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Jan Kaifer <jan@kaifer.cz>
Follow-up to #45555. This uses the same handling of mutable for
serverPatchReducer and refreshReducer.

Fixes NEXT-213

Ensures scroll position is still applied when calling `router.push()`
and `router.refresh()` in a single transition:
```tsx
startTransition(() => {
    router.push('/dashboard')
    router.refresh()
})
```
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Jan Kaifer <jan@kaifer.cz>
2023-02-06 14:53:34 +01:00
Jiachi Liu
a2dc530f44
Separate next/dynamic implementation for app and pages (#45565)
## Issue

To address the problem that we introduced in 13.0.7 (#42589) where we thought we could use same implementation `next/dynamic` for both `pages/` and `app/` directory. But it turns out it leads to many problems, such as:

* SSR preloading could miss the content, especially with nested dynamic calls
  * Closes #45213
* Introducing suspense boundary into `next/dynamic` with extra wrapped `<Suspense>` outside will lead to content is not resolevd during SSR
  * Related #45151
  * Closes #45099
* Unexpected hydration errors for suspense boundaries. Though react removed this error but the 18.3 is not out yet.
  * Closes #44083
  * Closes #45246
 
## Solution

Separate the dynamic implementation for `app/` dir and `pages/`. 

For `app/` dir we can encourage users to: 
  * Directly use `React.lazy` + `Suspense` for SSR'd content, and `next/dynamic` 
  * For non SSR components since it requires some internal integeration with next.js.

For `pages/` dir we still keep the original implementation

If you want to use `<Suspense>` with dynamic `fallback` value, use `React.lazy` + `Suspense` directly instead of picking up `next/dynamic` 
  * Closes #45116

This will solve various issue before react 18.3 is out and let users still progressively upgrade to new versions of next.js.

## Bug Fix

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-04 01:45:35 +00:00
Sam Ko
a85c636bfe
Fix middleware matcher for i18n with negative look ahead (#45504)closes https://github.com/vercel/next.js/issues/40305
<!--
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:
-->

Found a bug with excluding `/_next/static` from Edge Middleware due to
`/_next` being special-cased when deployed and i18n is configured.

```
export const config = {
  matcher: [
    '/',
    '/((?!api|_next/static|favicon|.well-known|auth|sitemap|robots.txt|files).*)',
  ],
};
```

closes: https://github.com/vercel/next.js/issues/40305

## Bug

- [X] Related issues linked using `fixes #number`
- [X] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-01 17:30:48 -08:00
Jiachi Liu
c5f1b45923
Fix metadata alternate and refactor twitter item (#45480)
x-ref: https://github.com/vercel/next.js/discussions/41745#discussioncomment-4827270

refactor twitter related items based on @gnoff 's feedback

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-02-01 13:43:12 +00:00
Jiachi Liu
a1c04b0162
Support generateMetadata export (#45401)Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Closes NEXT-397

Resolve `metadata` and `generateMetadata()` exports along with head
during rendering, this is the easy way for now to collect all the
metadata properly. Since we can access segment params and search params
only in rendering, so I moved all the resolving logic from loader to
render process.

<!--
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 that you're making:
-->


## Feature

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

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-02-01 12:54:39 +01:00
Jan Kaifer
659a75177b
Update error message for dynamic = "error" (#45432)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-01 11:20:35 +00:00
Hannes Bornö
e8fcf8b569
Add data attributes on @next/font usage (#45296)
Adds `data-next-font` data attribute to the preload tag if added by
`@next/font`.
```js
// Using `size-adjust` fallback font.
<link data-next-font="size-adjust" rel="preload" href="..." as="font" type="font/woff2" crossorigin="anonymous">

// Not using `size-adjust` fallback font.
<link data-next-font="" rel="preload" href="..." as="font" type="font/woff2" crossorigin="anonymous">
```

If no fonts are preloaded, the tag is added on the preconnect tag.

Fixes NEXT-350

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-31 14:16:13 -08:00
Shu Ding
326485c06e
Export the Metadata type (#45445)
This allows people to manually type their exported `metadata` field:

<img width="610" alt="CleanShot 2023-01-31 at 15 43 00@2x"
src="https://user-images.githubusercontent.com/3676859/215792182-8d9cf72a-dedf-4cc9-8613-d4eb49501abc.png">

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------
2023-01-31 10:49:07 -08:00
Tim Neutkens
78c5be4e32
Add support for navigating to external urls (#45388)
Adds support for `router.push('https://google.com')`,
`router.replace('https://google.com')`, and
`redirect('https://google.com')`.

<!--
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 that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-01-31 19:39:36 +01:00
Hannes Bornö
eef157f9df
@next/font change default font-display (#45430)
Change default font-display from `optional` to `swap`.

[slack
ref](https://vercel.slack.com/archives/C03KED0D4N7/p1674949620477649)

Fixes NEXT-430

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-31 08:26:38 -08:00
Jiachi Liu
41e2613aca
Update robots meta and add verification rendering (#45409)
Follow up for: #45237

* Adding more fields for robots meta, most related to googlebot
* Add `me` and `yandex` field and render for verification field
2023-01-30 20:49:30 +00:00
JJ Kasper
d3a9f5a54a
Fix trailing slash redirect applying for data request (#45417)
This ensures we don't apply the trailing slash redirect for `_next/data`
requests as it can cause props to fail to resolve on client transition.
This also fixes `missing` fields not being applied correctly for
`headers` and `redirects` as the field wasn't being passed through.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Closes: https://github.com/vercel/next.js/pull/45398
Fixes: https://github.com/vercel/next.js/issues/45393
x-ref: https://github.com/vercel/next.js/issues/45340
2023-01-30 12:10:30 -08:00
JJ Kasper
c7deecfd29
Fix flakey app metadata test (#45391)
We shouldn't use an arbitrary timeout here.

x-ref:
https://github.com/vercel/next.js/actions/runs/4038320521/jobs/6942258801
2023-01-29 20:57:23 -08:00
JJ Kasper
bcd63af2c9
Fix fetch stack test on deploy 2023-01-27 18:23:27 -08:00
JJ Kasper
1404eedf79
Update flakey app prefetch test (#45361)
x-ref:
https://github.com/vercel/next.js/actions/runs/4028868244/jobs/6926255942
2023-01-27 16:18:27 -08:00
Jiachi Liu
9822f78f1f
Resolve metadata fields (#45237)
## Feature

- [x] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [x]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-01-27 12:57:48 +01:00
JJ Kasper
eed2086cc6
Update flakey fetch stack test (#45318)
x-ref:
https://github.com/vercel/next.js/actions/runs/4017855404/jobs/6902831642

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-01-26 12:55:15 -08:00
Gal Schlezinger
35f68bc691
[edge] improve fetch stack traces in edge runtime (#44750)
Right now, when doing the following in an Edge API:

```typescript
export default async () => {
  await fetch("https://hello.world");
};
```

The stack trace generated does not contain the actual line of code that caused the error.
This gives a bad developer experience when working with `next dev`.
This PR fixes that for this specific use case and adds a test to make sure there's no regression.

For `next start`, there's also a small change, that needs to be pushed upstream to `edge-runtime`.
In order to run user code in the Edge Runtime, we call `vm.evaluate(code: string)`. However,
if we embrace the `options` from the signature of `vm.runInContext(code, ctx, options)`, we can
pass in the filename so the stack trace is correct.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-01-26 10:16:53 +00:00
JJ Kasper
8f05c0c07e
Update flakey test cases (#45290) 2023-01-25 22:55:49 -08:00
JJ Kasper
e868f77ede
Update app cache handling in development (#45248) 2023-01-25 11:51:53 -08:00
Hannes Bornö
018208fb15
Add editor links to RSC build error (#45179) 2023-01-24 15:13:37 -08:00
Jiachi Liu
45a9373113
Support metadata icons field (#45105)
NEXT-400

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2023-01-24 18:19:11 +00:00
Jan Kaifer
b386f680cc
Update handling of autoscrolling on navigation in app (#43845)
- Add support for scrolling to the sides and down when navigating
- Add tests for vertical scrolling
- Add tests for horizontal scrolling
- Add tests for `router.refresh()`
	- should not scroll by itself
	- should not block router.push from scrolling
	- should not scroll when page refreshed using fash refresh
- Scroll to the top of document if that gets page into viewport
	- I didn't want to implement some heuristics on if we can scroll to the top of the page so I just scroll there and check.
	- This implementation may not play well with some nested scrollable containers (but that never worked, just FYI)
	
- Improved typings on `BrowserInterface` a little - backward compatible change.

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-01-24 15:41:06 +00:00
JJ Kasper
2e251cb85f
Revert "Revert "Revert "Revert "Initial support for metadata (#44729)"" (#45113)"" (#45196)
Hopefully last time

Reverts vercel/next.js#45130
2023-01-24 13:21:59 +00:00
Hannes Bornö
6b5f5d2f9f
Add build time error if error.js is missing "use client" (#44961) 2023-01-24 09:57:40 +01:00
Jiachi Liu
e33e46d950
Fix dynamic no ssr with babel transform (#45091) 2023-01-23 13:39:47 -08:00
JJ Kasper
f931a636e1
Add debug info to static bailout message (#45192) 2023-01-23 13:25:00 -08:00
JJ Kasper
440560fbbb
Ensure config warnings only show once (#45142)
Since we now call `loadConfig()` in various processes our `execOnce`
handling isn't tracking when we have already shown warnings/logs in
another process so this adds a `silent` flag that we can leverage when
calling `loadConfig()`.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Fixes: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1674351677627259)
2023-01-21 22:47:24 -08:00
Maia Teegarden
b224c5f3ee
Revert "Revert "Revert "Initial support for metadata (#44729)"" (#45113)" (#45130)
This reverts commit 259cbc1806.

It does not have necessary changes to make Turbopack work.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-21 19:22:56 +00:00
JJ Kasper
259cbc1806
Revert "Revert "Initial support for metadata (#44729)"" (#45113) 2023-01-20 15:34:50 -08:00
JJ Kasper
e0865b10e0
Revert "Initial support for metadata (#44729)" (#45111) 2023-01-20 11:57:18 -08:00
Damien Simonin Feugas
e8ae4e219e
fix(#44077): allow edge runtime for api routes inside src/ folder (#45093)
fixes: https://github.com/vercel/next.js/issues/44382
closes: https://github.com/vercel/next.js/pull/44882
closes: https://github.com/vercel/next.js/pull/44383
2023-01-20 11:04:27 -08:00
JJ Kasper
dc119e20ba
Fix metadata e2e test on deploy (#45104) 2023-01-20 09:22:07 -08:00
Shu Ding
d1f6a4295b
Initial support for metadata (#44729)
This PR implements page and layout exported `metadata` field support with limited properties.

## Feature

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


Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-01-20 08:47:30 +00:00
Jiachi Liu
c648f9d413
Fix next/dynamic non ssr in pages when appDir is enabled (#45066)
When `appDir` is enabled, `next/dynamic` with `ssr: false` didn't get
correctly compiled with swc. The `server_components` condition in
next_dynamic transform should respect to the server components
compilation, but it was accidently turned on when server components is
enabled.

This PR fixes it that only turn on the flag when it's in server
components compilation (when `is_server` option is `true`)

reported by @MaxLeiter 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-01-20 00:25:46 +01:00
Rinku Chaudhari
a4d9373bd0
Remove useless ts-ignores (#45025) 2023-01-18 19:37:44 -08:00
JJ Kasper
4dfe831bbb
Add project directory rename/remove handling (#44911) 2023-01-18 14:37:40 -08:00
JJ Kasper
ad48202432
Ensure force-dynamic is honored during build (#45015) 2023-01-18 11:24:48 -08:00
JJ Kasper
6b7c69fa4d
Add proper error when app path switches static to dynamic (#44989) 2023-01-18 10:24:35 -08:00
JJ Kasper
8f0acdf781
Gracefully handle telemetry not being available (#44986) 2023-01-17 16:00:22 -08:00
Shu Ding
3a9bfe60d2
Fix CSS imports being tracked multiple times (#44938)
Currently the way our renderer injects CSS is to first track CSS imports on the module level, and then render these links on each layer. However, in a complex application it's possible that one CSS being imported in many modules, and in multiple layouts. This causes an issue of duplication. And if there are many rules the order could be messed up by that. 

This PR deduplicates CSS resources used by one entry (layout, page, error, ...) and all its parent layouts. If an entry is rendered, all its ancestors are rendered too.

See test case for more details. Currently those two tests will all fail.

Fixes #42862.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-17 18:36:00 +00:00
JJ Kasper
28bf703285
Update test env for E2E deploy mode (#44937) 2023-01-16 15:39:54 -08:00
JJ Kasper
d5a188de06
Update test env variable passing (#44912) 2023-01-15 23:20:16 -08:00
Jiachi Liu
375871620a
Handle empty module from the next dynamic loader (#44873) 2023-01-13 16:48:29 -08:00
Jiachi Liu
ff19e7ad30
Add built-in server-only and client-only (#44861) 2023-01-13 14:55:34 -08:00
Hannes Bornö
a0b45c3301
Correctly handle @next/font/google fonts without any preloadable subsets (#44809) 2023-01-12 08:23:09 -08:00
Tim Neutkens
223c974774
Fix router.refresh() resetting state and Suspense boundaries (#44775)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-01-12 15:48:59 +01:00
JJ Kasper
25b5845a0a
Fix app ISR handling with no generateStaticParams (#44787) 2023-01-11 15:28:03 -08:00
Hannes Bornö
b6f6179d5d
@next/font: Add preconnect tag when fonts are used but not preloaded in app-dir (#44746)
Add a preconnect tag to self with `crossorigin=anonymous` if fonts are used but not preloaded. This is already done in [`/pages`](https://github.com/vercel/next.js/blob/canary/packages/next/src/pages/_document.tsx#L384) but not yet for `/app`. 

Fixes NEXT-337

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-10 19:07:26 +00:00
Jimmy Lai
2d0323728f
fix: support runtime value when using multiple declarations per export (#44732)
Fixes a bug where the export syntax with multiple declarations didn't
work. I.e. this now works:

```
export const foo = 'bar', runtime = 'edge'
```


[x-slack-ref](https://vercel.slack.com/archives/C03LF48T3B7/p1673152323630709)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-09 18:58:31 +01:00
Jan Kaifer
015a7dd9ee
Change test template to use TS and improve template for app-dir (#44227)
Make templates actual executable tests to that we ensure there are no regressions.
It also makes the setup easier.

Also changes the layout to typescript because that's what we want to use by default anyway.

Also refactors helper function to use plop specific `{{ toFileName name }}` syntax for easier template modification.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-01-06 20:36:47 +00:00
Damien Simonin Feugas
3c87e1b52a
chore: improves console warnings related to edge runtime (#44563)
## 📖 What's in there?

With Edge Function GA for API Routes, it would make sense to suggest
developer to change their runtime key from `experimental-edge` to
`edge`.

Current behavior is:
1. when using `experimental-edge` in API route: 
> prints a warning _once:_ `warn - You are using an experimental edge
runtime, the API might change.`
   
1. when using `experimental-edge` in pages:
> prints a warning _once:_ `warn - You are using an experimental edge
runtime, the API might change. `
   
1. when using `edge` in pages:
> throws an error _for each page_: `error - Page /xyz provided runtime
'edge', the edge runtime for rendering is currently experimental. Use
runtime 'experimental-edge' instead.`

This PR adjust case # 1 to indicates which API file is using
`experimental-edge` (a warning per page), and suggest to migrate:
`warn - /pages/api/xyz provided runtime 'experimental-edge'. It can be
updated to 'edge' instead.`

- [x] Integration tests added

## 🧪 How to test?

Besides running e2e tests with `NEXT_TEST_MODE=dev pnpm testheadless
--testPathPattern edge-configurable-runtime`, you can create a test app
in `examples` folder:
```jsx
// examples/edge-warnings/pages/api/edge.js
export default () => new Response('ok')
export const config = { runtime: 'experimental-edge' }

// examples/edge-warnings/pages/index.jsx
export default () => <p>hello world</p>
export const runtime = 'experimental-edge'
```

Build next.js then run with `pnpm next dev examples/edge-warnings`.

You can try adding more pages with `experimental-edge` runtime (will not
produce more warnings), adding more API with `experimental-edge` (will
produce new warnings), or change page runtime to `edge` (will produce
errors).
2023-01-06 11:28:51 -08:00
Hannes Bornö
5f2c9d0b30
Update subset validation in @next/font/google and fix CJK bug (#44594)
Currently there's a bug when selecting Chinese, Japanese or Korean (CJK)
as subsets.
```js
const notoSans = Noto_Sans_JP({
  subsets: ['japanese'],
})
```
It actually doesn't work, nothing preloads. This PR solves this by
removing CJK languages as candidates for preloading. The reason is that
they contain so many glyphs that each font-family is split up in 100+
font files. It doesn't make sense to preload all of them.

So CJK users will have to disable preloading.
```js
const notoSansJapanese = Noto_Sans_JP({
  weight: '400',
  preload: false,
})
```
In case you do manually disable preloading like above, the default
`font-display` is changed to `swap`.

This PR also improves the validation errors of subsets.
1. Providing unknown subset
```
`@next/font` error:
Unknown subset `japanese` for font `Inter`.
Available subsets: `cyrillic`, `cyrillic-ext`, `greek`, `greek-ext`, `latin`, `latin-ext`, `vietnamese`
```
2. Missing specified subset. The error has a link with further
instructions.
```
`@next/font` error:
Missing selected subsets for font `Inter`. Please specify subsets in the function call or in your `next.config.js`. Read more: https://nextjs.org/docs/messages/google-fonts-missing-subsets
```

fixes NEXT-336

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-01-05 15:51:38 -08:00
Tim Neutkens
a79d85d1a9
Make static page prefetch apply on navigation in app dir (#44502)
The initial prefetching implementation was based on the response
returning below the common layout, however when static generation was
added the RSC payload for these changed to only include the router tree
patch and the fully rendered page.

Currently the flow for prefetch is this:

- `router.prefetch`
- Fetch RSC payload
- Dispatch `ACTION_PREFETCH` with RSC payload. Note: the fetch is
intentionally not in the reducer as the fetch happens during an event or
effect, e.g. hover or `useEffect`
- Reducer handles `ACTION_PREFETCH`, creates the router tree, applies
the `subTreeData` to the cache append-only. Saves the new router tree in
the `prefetchCache` part of the reducer state.
- Then, on navigation, the `subTreeData` should be already available so
there's no additional apply. The router state is applied based on the
`prefetchCache`.

This approach is fine when the RSC payload returned never overrides the
`subTreeData` of an already existing node, however that does happen in
case of static pages because the subTreeData is for the root cache node
instead of a deeper node.

The new flow for prefetching:

- `router.prefetch`
- Fetch RSC payload
- Dispatch `ACTION_PREFETCH` with RSC payload
- Reducer handles `ACTION_PREFETCH`, creates the router tree, Saves the
new router tree and `subTreeData` in the `prefetchCache` part of the
reducer state.
- Then, on navigation, the `subTreeData` and router state are applied
based on the `prefetchCache`.

<!--
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 that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-01-05 13:29:39 -08:00
Wyatt Johnson
ed59ad525a
Change NextInstance.fetch Signature (#44575)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-01-05 16:31:03 +01:00
Jan Kaifer
1dc8da96dd
Test navigation between multiple root layouts (#43762)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-01-05 13:27:29 +01:00
JJ Kasper
baccea324f
Remove extra pnp test (#44576)
This removes an extra Yarn PnP test that is failing from a nested
dependency change. We have three other examples being tested against PnP
which should be sufficient.

x-ref:
https://github.com/vercel/next.js/actions/runs/3840569532/jobs/6542443736
x-ref:
https://github.com/vercel/next.js/actions/runs/3840569532/jobs/6542444509
x-ref:
https://github.com/vercel/next.js/actions/runs/3840569532/jobs/6542448724
x-ref:
https://github.com/vercel/next.js/actions/runs/3840569532/jobs/6542449653
2023-01-04 14:28:21 -08:00
JJ Kasper
83bc5b6bb5
Remove un-used app-dir test fixture (#44546)
This fixture is not being used as we aren't currently able to test the
ts plugin directly and will need to investigate using a headless vs code
instance to test against.

x-ref: https://vercel.slack.com/archives/C04DUD7EB1B/p1672784680457859
2023-01-03 15:47:49 -08:00
Damien Simonin Feugas
c2229a3a40
chore: addresses leftover from #44045 (#44080)
## 📖 What's in there?

Yesterday we didn't had time to address leftovers from #44045.
Here it is.

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

## 🧪  How to test?

Several tests cases added:
- in dev mode, errors and warning: `NEXT_TEST_MODE=dev pnpm testheadless
--testPathPattern edge-configurable-runtime`
- in build mode, build error for pages on the `edge`:
`NEXT_TEST_MODE=start pnpm testheadless --testPathPattern
edge-configurable-runtime`

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-01-03 13:18:14 -08:00
Jan Kaifer
a7b046d92e
Cache package lock when running tests to speed up installation (#44520) 2023-01-03 11:55:28 +01:00
Tim Neutkens
efcec4c1e3
Move core files to src folder and move JS files to TypeScript (#44405) 2023-01-03 10:05:50 +01:00
Shu Ding
84531c5301
Add special error message for class component in server component (#44265)
This PR adjusts the error message so it's more accurate and makes more sense. Current error:

> You're importing a component that needs Component.

New:

> You’re importing a class component.

NEXT-317

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-24 14:18:34 +00:00
Tim Neutkens
9ee4c0cdf1
Enable allowMiddlewareResponseBody by default (#44224)
Follow-up to #44195


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-21 18:40:58 +00:00
Jiachi Liu
c24643ecff
Only once for the next/head usage in app dir (#44233)
Follow up for #43885

* only warn once for `next/head` usage in the loader
* add `Warning:` prefix
2022-12-21 17:23:28 +01:00
Shu Ding
e27c7fa61b
Honour distDir in type generation (#44207) 2022-12-21 16:01:59 +01:00
Jan Kaifer
2c70bc784c
Write tests for navigation between app-dir and pages (#43881)
- Add test for navigating app -> pages
- Add test for navigation pages -> app
- Remove unneeded React imports
- Document back and forward on the BrowserInterface
- Add test for navigating back and forth between pages and app pages using `back` and `forward`
2022-12-21 14:10:25 +00:00
Jan Kaifer
6713ce4cab
Move tests into their test folder (#44183) 2022-12-21 14:16:52 +01:00
Shu Ding
966d2b16c3
Fix CSS resources being duplicated in app dir (#44168)
Currently, to get all the chunk files that contain a specific module in a build, we use `chunk.files`. However a module itself can be included by multiple chunks, or even chunks from different entries. Theoretically that's correct but in our architecture, we only need these chunks that are from the entry that is currently rendering.

One solution is to add a 2-level key (the entry name) to modules in flight manifest, but that introduces too much size overhead to the manifest. So instead we leverage the `__entry_css_files__` field to generate a list of all files for a specific entry, and then find the intersection set of `{CSSFilesForEntry, CSSFilesForModule}` to get the corresponding CSS files for a specific Next.js entry.

Also renamed `__entry_css__` to be more specific, and did some performance optimizations.

NEXT-297

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-20 18:43:03 +00:00
Shu Ding
04daf7eb06
Move transpilePackages out of experimental (#44194)
Should be good to land and it got tests covered.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-12-20 17:27:30 +00:00
Shu Ding
cafb886ed6
Move options to stable (#44195)
This PR moves `allowMiddlewareResponseBody`, `skipMiddlewareUrlNormalize` and `skipTrailingSlashRedirect` to stable.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-20 16:17:40 +00:00
Steven
a32b3dde51
Fix test template example (#44170)
- Fixes typo from #44147 

`getElementByCss` => `elementByCss`
2022-12-19 16:31:28 -08:00
Jiachi Liu
9855fd7bc5
test: add test for notFound during streaming (#44078)
Add test for notFound case added in #41735
2022-12-19 14:15:51 -08:00
Jiachi Liu
ea7d85687b
Fix styled-components setup in turbo example (#44165)
Closes: #44164

Sync to the latest setup doc on https://beta.nextjs.org/docs/styling/css-in-js#styled-components

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-19 20:59:16 +00:00
Tim Neutkens
397fc57224
Update pnpm new-test to use createNextDescribe (#44147) 2022-12-19 20:08:50 +01:00
Jan Kaifer
887cbe4334
Add types as a default dependency into tests (#44140) 2022-12-19 19:05:53 +01:00
Jiachi Liu
ded93bf645
should not contain pages css in app dir (#44151)
* Filter out the css chunk from `pages/`
* add indent for flight manifests in dev mode for development convenience

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2022-12-19 17:51:34 +00:00
Jan Kaifer
fa880d04ea
Add test for rewriting in middleware in app-dir (#43971)
- add test for rewriting in middleware in app-dir
- add test for redirect
- add tests for router.push
- add test for rewrites in config.next.js
- add test for redirects in config.next.js
- add test for catchall rewrite in config.next.js

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2022-12-19 12:32:17 +00:00
Tim Neutkens
7a2ec41601
Refactor more tests to createNextDescribe (#44104) 2022-12-19 10:20:01 +01:00
Tim Neutkens
1e0acc2e58
Implement new core test API (#44086)
Adds a new way to write e2e tests for the Next.js core, mostly to reduce common boilerplate and make it easier to write tests for now team members.

```ts
// test/e2e/app-dir/head/head.test.ts
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
  'app dir head',
  {
    files: __dirname
  },
  ({ next }) => {
    test('handles ', async () => {
      // get cheerio (jQuery like API to traverse HTML)
      const $ = await next.render$('/')
      // get html
      const html = await next.render('/')
      // use fetch
      const res = await next.fetch('/')
      // get browser
      const browser = await next.browser('/')
    })
})
2022-12-16 17:21:02 +00:00
Jiachi Liu
137a63b90d
Fix ignoring dev warning for preload component (#44065)
Fix ignoring warning added in #41519
2022-12-16 17:47:30 +01:00
Jiachi Liu
595ecdbfdc
feat: app dir error-global component (#44066)
## Feature

NEXT-54

When there's an error in the one of the root level pages, there's no way to handle it. The team discussed this and decided there should be a global error boundary to pick up anything not handled further down in the tree. It can be called `global-error.js`.

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2022-12-16 11:04:43 +00:00
Jan Kaifer
20997f87c4
Add static test for useSelectedLayoutSegments (#43955) 2022-12-16 11:39:18 +01:00
Jan Kaifer
246c0cd87b
Test that adding query can be detected by useSearchParams (#43969) 2022-12-16 11:22:52 +01:00
Jan Kaifer
ab328c6c39
Add tracing for testing tools (#44046) 2022-12-16 09:58:04 +01:00
Damien Simonin Feugas
35f1a3501a
feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
Jiachi Liu
60dd6dfc9b
Fix module error for findDOMNode on edge (#43998)
## Bug

The `findDOMNode` will be exported from ReactDOM in esm mode, but it's
not defined for SSR since SSR is using react-dom server stub bundle
which doesn't contain any thing. So `import { findDOMNode } from
'react-dom'` will error in that case with bundling.

Since it's only being used on client, we import ReactDOM and call
`ReactDOM.findDOMNode` to avoid bundling error and adding a condition to
tree-shake it off on client

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

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2022-12-13 09:16:01 -08:00
Klein Torres
a34b20e6f2
Fix browser navigation buttons not working with shallow routing and middleware (#43919)
This PR fixes #41064.
In some particular cases, while using a middleware and shallow routing
the navigation get stucks and stop refreshing the page. After futher
investigation it seems that a line of code was added that causes the
router pathname to be incorrect and then making Next believe it's the
same page that is loading.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

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

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-12-12 20:02:06 -08:00
Jiachi Liu
be90c0b909
Add default head for app dir (#43963)
Add default head to app dir, when there's no`head.js`, use the default
head with the following meta tags

```html
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
```

It will be replaced if there's custom head.js in child layout.

NEXT-169
2022-12-12 19:10:42 -08:00
Ngô Đức Anh
482d78e1c2
Fix: fix pages in Route Groups returning 500 with output: "standalone" (#43746)
<!--
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 that you're making:
-->

Fixes [#43367
(comment)](https://github.com/vercel/next.js/issues/43367#issuecomment-1338617317)

This fixes the issue in which pages that are in Route Groups return
status code 500 when built with `output: "standalone"` because of the
lack of required chunks in `.next/standalone/.next/server/chunks` by
handling their `.nft.json` files properly through using their
denormalized page paths, rather than their normalized ones to resolve
those files in `copyTracedFiles`.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-12 19:06:40 -08:00
Wyatt Johnson
cba7070c08
Added support for query params on not found pages (#43836)
Previously, query parameters were not available on 404 pages because
calling the router methods would change the pathname in the browser.
This change adds support for the query to update for those pages without
updating the path to include the basePath.

This additionally narrows some Typescript types that were previous set
to `any` which highlighted some type errors that were corrected.

Fixes: https://github.com/vercel/next.js/issues/35990

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-12-12 16:10:44 -08:00
Hannes Bornö
b3dfa03767
useSearchParams - bailout to client rendering during static generation (#43603)
Currently `useSearchParams` bails out of static generation altogether, forcing the page to be dynamic. This behaviour is wrong. Instead it should still be statically generated, but `useSearchParams` should only run on the client.

This is achieved by throwing a "bailout to client rendering" error. If there's no suspense boundary the whole page will bailout to be rendered on the client. If there is a suspense boundary it will only bailout from that point.

~This PR also adds handling for `export const dynamic = 'force-static'` combined with `useSearchParams`. If it is enabled it will return an empty `ReadonlyURLSearchParams` and skip the bailout to client rendering. Since the `staticGenerationAsyncStorage` only is available on the server - `forceStatic` is sent to the `app-router` to enable sending an empty `URLSearchParams` to match the server response.~
https://github.com/vercel/next.js/pull/43603#discussion_r1042071542 the implementation was wrong, added skipped tests and todo comment for now.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-12 11:53:38 +00:00
Jiachi Liu
d8545e6273
fix: forwarding props to no ssr dynamic (#43901)
## Bug

Fixes: #43764

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
2022-12-09 19:00:28 +00:00
Shu Ding
5415a0d954
Fix error message for invalid runtime option in app dir (#43900)
Currently it shows `Provided runtime "undefined" is not supported`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-12-09 18:35:27 +00:00
Jiachi Liu
a7f29108f4
Alias next/head to noop for rsc and add upgration warning (#43885)
This will reduce the bundle size and also give user proper hint to upgrade to `head.js`

* Mark `next/head` as noop in app dir
* Add warning for users to check the upgration guide to migrate it to head.js
2022-12-09 14:45:31 +00:00