Commit graph

17238 commits

Author SHA1 Message Date
Steven
6773ea8636
fix: improve error message when output: export in app router (#54202)
There are a few cases that are not handled by App Router when using `output: export` config.

A few of them are expected, but some are yet to be implemented. Regardless of the intent of the future, this PR ensures the error messages match what was documented to be [unsupported](https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features).

- Documentation: https://github.com/vercel/next.js/pull/53592
- Issue: #48022
2023-08-21 14:45:00 +00:00
Lee Robinson
0718aec93b
Update Contentful example for App Router. (#54205)
This PR updates the `cms-contentful` example to use:

- App Router
- TypeScript
- Draft Mode (previously Preview Mode)
- ISR / Data Cache (revalidations through `revalidateTag`)

Further, it combines many separate files into more manageable single files, and tries to better bucket provider-specific logic into the `lib/` folder. I'm hoping this can be the foundation for re-writing the rest of the `cms-*` examples to use App Router.

Overall, the code is much easier to reason about IMO. Pretty happy with the change. I sprinkled some `any`'s throughout here, but if someone wants to make it better, go for it! 

https://app-router-contentful.vercel.app/
2023-08-21 13:21:37 +00:00
Laurent Thiebault
71d424e804
docs: update a small typo in 02-app/01-building-your-application/06-optimizing/01-images.mdx (#54311)
Hello,

I just make this PR because the `/me.png` example is not in "remote images" section but in "local images", that's why I propose to edit this :)

Thank you!

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide
2023-08-20 18:33:16 +00:00
Shu Ding
a47d92f55e
Fix default export of server action utility aliases (#54254)
Similar to #54004, this PR changes `private-next-rsc-action-validate`
and `private-next-rsc-action-client-wrapper` to export named values
instead of default values. In #54230 (currently broken), the Server
Action file was bundled via Vite/Rollup as an external dependency so
we're not doing the ESM interoperation correctly.

Closes #54230.
2023-08-20 18:09:38 +02:00
Nikhil Bhargava
24cd55c09f
Adds nonce to preinit scripts (#54059)
Fixes #54055.

A bug recently introduced in https://github.com/vercel/next.js/pull/53705 made it so that we were now preinitializing some of our scripts slightly better, but in doing so, we failed to pass in a nonce. This broke nonce-based CSP usage. The fix was to add the `nonce` to our `ReactDOM.preinit` calls.

Manual testing shows that this change fixes the error and the nonce is now passed in as expected.


Co-authored-by: Dan Ott <360261+danieltott@users.noreply.github.com>
2023-08-20 13:55:02 +00:00
vercel-release-bot
f1c286fff2 v13.4.20-canary.0 2023-08-20 12:56:16 +00:00
Jimmy Lai
6aa07fb999
app-router: tweak prefetch cache status heuristics (#53864)
This PR changes the heuristic in the client cache to only check and show the prefetched data when it was prefetched or last read 30s ago vs keeping it around as long as it was accessed within 30s.
2023-08-20 11:25:48 +00:00
Tim Neutkens
86fc1697d5
Remove unused array in router-server (#54278)
Noticed these arrays don't actually do anything specific, removed them.

Update: After the multi-zone test failed it seems this was added to ensure you can run multiple Next.js instances in the same process, this simplifies it a bit and adds a comment explaining why it's called.
2023-08-20 11:09:12 +00:00
Donny/강동윤
d2a8d4fa2d
Update swc_core to v0.79.69 (#54190)
### What?

Update swc crates to becea47a2d

### Why?

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

### How?

Closes WEB-1410
2023-08-20 10:55:41 +00:00
Jiachi Liu
f2a3fd9fc3
Handle basePath for redirect() (#54277)
### What & Why
Add base path handling for the url in redirect error if the `basePath` is configured.

This is only break for server rendering case as the `basePath` is missing in the `Location` header. When running `next build`, everything is managed well with app router and base path on client side so it didn't break.

### How

Adding `basePath` if it's presented for `Location` header.
Update the `RenderOpts` type as basePath is already passed down in it, also update them for turbopack entries

Fixes #54163
Closes NEXT-1529
2023-08-20 03:32:52 +00:00
Jiachi Liu
311eea4c6a
Fix emotion-js transform for server components (#54284)
### What & Why

emotion-js has its own [jsx transform](https://emotion.sh/docs/typescript#emotionreact) which is being applied when `compiler.emotion` is enabled in `next.config.js`.

Thanks to emotion-js team that provided an emotion-js example setup with app router [here](https://github.com/emotion-js/emotion/issues/2928#issuecomment-1319792703), so that we can use it as test example with app router. Based on the setup, we create a test case working with emotion js but failed with error mentioned in #41994 that some client hooks appearing in server components. That is because the emotion-js jsx factory includes some client hooks.

### How

For server components, css-in-js is not recommended to apply so we disabled the transform before, the emotion jsx factory is a separate config that should also not be applied in server components. So in this case we still use react jsx factory instead of the emotion-js one for server components then it won't error. The test case can also be used as an example for basic emotion-js use case with app router.


Fixes #41994
Closes NEXT-1368
2023-08-20 03:14:16 +00:00
Joseph
76997cc053
docs: Bump minimum Node.js version to 16.14 (#54285)
### What?

Docs change.

### Why?

- https://github.com/vercel/next.js/issues/54269

### How?

Bump the Node.js version shown at: https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#nodejs-version 

Fixes #54269
2023-08-20 03:03:02 +00:00
Jiachi Liu
85606472e4
Add test for using custom font in metadata image routes (#54274)
In the past few rounds of improving metadata image routes bundling, we have improved the bundling strategy and also updated [the usage tutorial of using custom fonts in og image routes](https://vercel.com/docs/functions/edge-functions/og-image-generation/og-image-examples) which should load the font in the image route handler.

Adding some tests to ensure custom fonts are working with metadata

Closes #48081
2023-08-19 14:29:18 +00:00
Zack Tanner
adc413b3fb
add experimental https support to next dev (#54016)
This adds an `--experimental-https` flag to `next dev` which will generate a self-signed certificate via [mkcert](https://github.com/FiloSottile/mkcert) and use it for the dev server.

also supports passing in pre-existing certs via `--experimental-https-cert` and `--experimental-https-key`

x-ref: https://github.com/vercel/next.js/discussions/33768 https://github.com/vercel/next.js/discussions/10935
2023-08-19 01:04:06 +00:00
Vercel Release Bot
bb9db03a41
Update font data (#54257)
This auto-generated PR updates font data with latest available
2023-08-19 00:49:32 +00:00
vercel-release-bot
d96e0258de v13.4.19 2023-08-19 00:23:31 +00:00
vercel-release-bot
1cf4aa6e51 v13.4.19-canary.0 2023-08-18 23:39:41 +00:00
Corey Larson
42abfd694d
Ensures App Router Link respects scroll-behavior: smooth when only hash is changed. (#54243)
Fixes https://github.com/vercel/next.js/issues/54240

The Link component in App Router is not respecting `scroll-behavior: smooth` when only the hash changes.

It appears to be caused by `focusAndScrollRef.onlyHashChange = false` being set before `handleSmoothScroll` is called, causing `htmlElement.style.scrollBehavior` to be overridden to `auto` before `scrollIntoView` is called.

Moving `focusAndScrollRef.onlyHashChange = false` to after `handleSmoothScroll` invocation resolves the issue.
2023-08-18 20:58:45 +00:00
Shu Ding
0e78798f37
Fix renamed export of Server Actions (#54241)
This fixes the compilation of `export { action as renamed }` syntax. Previously it's compiled as `export var action = ...` and with this fix, it will be `export var renamed = ...`.

Closes #54229.
2023-08-18 20:41:32 +00:00
Steven
2bb12fc6bb
chore(ci): bump cancel-workflow-action@0.11.0 (#54246)
https://github.com/styfle/cancel-workflow-action/releases/tag/0.11.0
2023-08-18 20:29:57 +00:00
David Goguen
a0749a5103
feat(image): add support for custom loaderFile when loader: default (#53417)
Image Optimization API currently does not work if a custom loaderFile is specified in next.config.js, even if loader is explicitly set to 'default', because it is currently being overridden to 'custom' simply because a loaderFile is specified. This is unnecessary and causing the Image Optimization API routes not to be initialized since the change to the config happens before the routes are initialized.

[Sandbox Reproduction](https://codesandbox.io/p/sandbox/purple-pine-t7hhgl?file=%2Fimage-loader.js%3A8%2C1)

- Fixes #53415
2023-08-18 20:05:17 +00:00
Balázs Orbán
725ddc7371
chore: skip CI run on forks (#54219)
Running the action added in #53541 on forks will result in always failing, so we can skip it.

Fixes #54210
2023-08-18 17:40:44 +00:00
vinay
5764c6e900
(Fix)Broken upgrading.mdx link (#54234)
Fixes #54223
2023-08-18 17:10:38 +00:00
Jiachi Liu
c305bf6afb
Add default not found to loader tree of group routes root layer (#54228)
For group routes, unlike normal routes, the root layout is located in the "group"'s segment instead of root layer.
To make it also able to leverage the default not found error component as root not found component, we need to determine if we're in the root group segment in the loader tree, and add the not-found boundary for it.


If you compre the loader tree visually they will look like this:

Normal route tree structure
```
['',
 { children: [segment, {...}, {...}]},
 { layout: ..., 'not-found': ... }
]
```

Group routes
```
[''
 { children: ['(group)', {...}, { layout, 'not-found': ... }]}
 {}
]
```

Comparing to normal case, we go 1 layer down in the tree for group routes, then insert the not-found boundary there

Fixes #52255
Closes NEXT-1532
2023-08-18 16:56:55 +00:00
Shu Ding
b906fdfbeb
Use createClientModuleProxy from Flight Server (#54232)
This PR removes our client module reference proxy implementation to directly use the one from the upstream Flight server, as it's added here: https://github.com/facebook/react/pull/27033.

Also updated the server reference creation code a bit to use `defineProperties` - we can't switch to the upstream `registerServerReference` API yet as our Server Actions compiler needs to change a bit to adapt that API since we might have existing `bound` and/or `originalAction` provided.
2023-08-18 15:31:25 +00:00
Shu Ding
b25407e4e4
Add Route and LinkProps stub generics (#54226)
Closes #53732. Closes #52929.

When using the statically typed routes feature, we might have code like:

```ts
export function Card<T extends string>({ href }: { href: Route<T> | URL })...
export function Card<T extends string>({ href }: LinkProps<T>)...
```

To statically check `<Card href={...}>` and make sure it's `href` is an existing route. However, in certain cases these route types are not generated (e.g. running `tsc` directly w/o a `next dev` or `next build`), which results in TS errors.

This PR adds stub generics to `Route` and `LinkProps` so even if that plugin isn't executed, these types will not block type checking.
2023-08-18 14:41:21 +00:00
Shu Ding
ec438418a4
Fix missing devPageFiles collection (#54224)
Closes #54168. This was accidentally removed from a code refactoring.
2023-08-18 14:16:11 +00:00
Zack Tanner
803bbe5c93
fix process.env not being available in standalone mode (#54203)
### What?
When running Next in standalone mode, `process.env` is not made
available to the render workers, making it impossible to access
environment variables that aren't provided in `.env` files.

### Why?
`initialEnv` is undefined in `createWorkers` when the server is started
in standalone mode.

### How?
This initializes the workers with `process.env` in case `initialEnv` is
unavailable, similar to the behavior of `loadEnvConfig()`

Closes NEXT-1508
Fixes #53367
2023-08-18 16:04:48 +02:00
Tim Neutkens
819a163fce
Update dd-trace used for internal tools (#54214)
This is only used for internal tools 👍
2023-08-18 13:55:22 +00:00
Steven
cfa07f4f63
chore: remove unnecessary type cast in dev-build-watcher (#54221)
I accidentally left this type cast in from previous PR https://github.com/vercel/next.js/pull/54074 but it is unnecessary.
2023-08-18 13:39:55 +00:00
Kim In Seop
132d3e8f97
fix: invalid module transform for @headlessui/react (#54206)
occured since #54188

- `*`: use kebabcase instead of lowercase
- Transition: `components/transitions/transition`
- Tab: `components/tabs/tabs`

```plain
- wait compiling /not-found (client and server)...
- error ./node_modules/.pnpm/@headlessui+react@1.7.17_react-dom@18.2.0_react@18.2.0/node_modules/@headlessui/react/dist/headlessui.esm.js:2:0
Module not found: Can't resolve '/Projects/node_modules/.pnpm/@headlessui+react@1.7.17_react-dom@18.2.0_react@18.2.0/node_modules/@headlessui/react/dist/components/tab/tab'
```




Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-08-18 10:33:33 +00:00
vercel-release-bot
87b66f64e5 v13.4.18 2023-08-18 00:16:08 +00:00
vercel-release-bot
89ed4dd105 v13.4.18-canary.0 2023-08-17 22:11:33 +00:00
Zack Tanner
c676f9357e
fix bfcache restoration behavior (#54198)
Follow up to https://github.com/vercel/next.js/pull/54081 -- this was
restoring the router tree improperly causing an error on bfcache hits

Had to override some default behaviors to prevent `forward` / `back` in
playwright from hanging indefinitely since no load event is firing in
these cases

Fixes #54184
Closes NEXT-1528
2023-08-18 00:05:26 +02:00
Malte Ubl
631018a674
Automatically modularizeImports for the popular @headlessui/react library (#54188)
`import { Listbox } from "@headlessui-float/react";` becomes
`import { Listbox } from "@headlessui/react/dist/components/listbox/listbox";`
2023-08-17 21:38:20 +00:00
Jiachi Liu
71149293e5
Allow range version for eslint config (#53751)
Fixes #52365

In #52275 that eslint config changed to a fixed canary version to leverage the improvement of `react-hooks` eslint plugin but breaks the installation when 3rd party packages having strict matching for certain version of eslint plugin.

This PR allows both previous version and the canary version be present.
2023-08-17 18:39:03 +00:00
Jiachi Liu
e20c8c824c
Assign default not-found boundary if custom not-found is not present for root layer only (#54185)
Fixes #54174 

We should only add default not-found boundary to loader tree components for root layout. It was accidently added for children routes before
2023-08-17 18:27:27 +00:00
Ben Brook
847c14ea15
Add size property to ReadonlySearchParams (#53144)
Closes #49774 (and my dupe https://github.com/vercel/next.js/issues/53141), where there's a type error when attempting to construct URLSearchParams from ReadonlyURLSearchParams, [as recommended in the Next docs here](https://nextjs.org/docs/app/api-reference/functions/use-search-params#updating-searchparams) and breaks `next build` on Node v18.16.0+, including on Vercel.


This is blocked by TS publishing the new `dom` types (https://github.com/microsoft/TypeScript/issues/54466). The [URL Standard](https://url.spec.whatwg.org/#dom-urlsearchparams-size) added the size property to URLSearchParams (https://github.com/whatwg/url/pull/734) and this now has wide [browser support](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/size).
2023-08-17 18:15:45 +00:00
Justin Ridgewell
11dfdf8d7a
Turbopack: Strip relative path prefix when generating PageLoaderAsset (#54040)
### What?

Strip the relative path prefix (`_next/`) when generating the `PageLoaderAsset`. This is necessary because the page loader will internally use `__turbopack_load__`, which prepends the prefix back onto the path.

### Why?

Without this, we'd try loading `_next/_next/path/to/file.js`, because we'd prepend the prefix onto a path that already contains it.

### How?

When generating the page loader asset, we "proxy" the `OutputAsset` onto a path which has the prefix removed.

~~Depends on https://github.com/vercel/turbo/pull/5717~~

Closes WEB-1377
2023-08-17 17:29:30 +00:00
Justin Ridgewell
8def0c8418
Update rust toolchain (#54130)
The current toolchain is very buggy.

Closes WEB-1400
2023-08-17 16:37:33 +00:00
Steven
3fadba5aba
chore: improve ts types for position in dev-build-watcher (#54124)
- Follow up to https://github.com/vercel/next.js/pull/54074
2023-08-17 15:36:35 +00:00
Shu Ding
df1de76c5c
Remove unused variables (#54149)
These are not referenced anywhere in the codebase.
2023-08-17 11:56:56 +00:00
Jiachi Liu
bc87328609
refactor: remove edge condition for module proxy path (#54167)
For edge-runtime we always bundle, and all the mapping of internal ESM files are configured in webpack. Adding a new alias of "next/dist/build" so we don't have to manually check the mapping path for module proxy
2023-08-17 11:33:26 +00:00
vercel-release-bot
236075362a v13.4.17 2023-08-17 09:32:20 +00:00
vercel-release-bot
645ba004d6 v13.4.17-canary.2 2023-08-17 08:55:11 +00:00
Jiachi Liu
02c258dd91
Revert "fix(47299): allow testing pages with metadata in jsdom test environment" (#54160)
Reverts vercel/next.js#53578

This PR (#53578) will break client components test, revert it for now.

Can repro by adding `"use client"` to `app/page.tsx` in `test/production/jest/server-only.test.ts`

```
    FAIL app/page.test.jsx
      ● Test suite failed to run·
        Cannot find module 'private-next-rsc-mod-ref-proxy' from 'app/page.jsx'·
        Require stack:
```
2023-08-17 08:49:08 +00:00
vercel-release-bot
fc3bf373c5 v13.4.17-canary.1 2023-08-17 07:33:02 +00:00
Jiwon Choi
043114773f
fix: cookies().has() breaks in app-route (#54112)
- Added `has` to ResponseCookies in [edge-runtime/cookies#533](https://github.com/vercel/edge-runtime/pull/533)
- Upgraded edge-runtime/cookies to 3.3.0 #54117 
- Added a test case


Fixes #54005 #54111
2023-08-17 01:06:07 +00:00
Will Binns-Smith
bd5b715d18
Debug tracing: Include navigation through hydration timing (#54078)
This:
- Adds a simple, generic tracer in the client that can be subscribed to in order to report spans
- Reports client spans through the HMR socket in the dev server
- Receives these spans and includes them in `.next/trace`


Closes WEB-1387
2023-08-17 00:48:44 +00:00
Max Leiter
6767454b57
node-web-streams: remove tee shim, use ReadableStream.tee (#54079)
### What?
~The `setTimeout(() => {}, 0)` was used in place of `setImmediate` due to lack of support in the Edge Runtime. This is no longer a problem.~ Not working like I expected. 

`ReadableStream.tee` should be widely supported as well as of [Node 16.5](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee#browser_compatibility)

### Why?
Use the platform!

### How?
Use the built-in `ReadableStream.tee()`
2023-08-17 00:27:49 +00:00