Commit graph

18461 commits

Author SHA1 Message Date
Tim Neutkens
97ba91097d
Support passing a relative string to pushState/replaceState (#58438)
Follow-up to #58335.

Fixes
https://github.com/vercel/next.js/discussions/48110#discussioncomment-7565394

As reported in the discussion passing a origin-relative string didn't
work as `new URL` will throw an error. This ensures the `origin`
parameter is provided to `new URL`.
Added tests for the string behavior.

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

## For Contributors

### Improving Documentation

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

### Adding or Updating Examples

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

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

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


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-11-16 22:11:14 +01:00
Tim Neutkens
4ba64e2e0b
Remove early return that is duplicated in useSearchParams (#58545)
## What?

Noticed that the return is the same, so we don't have to add this specific return.
2023-11-16 19:35:56 +00:00
vercel-release-bot
391471b315 v14.0.3 2023-11-16 18:37:33 +00:00
Gonzalo Pozzo
637ead09e2
Update 04-metadata.mdx (#58535)
Update wrong link
2023-11-16 17:56:02 +00:00
Shu Ding
ce973905a9
Add code comments (#58529)
The code comments added in 2dc0ba4bd9 are missing somehow. These are very necessary to understand the code as it looks confusing.
2023-11-16 16:21:35 +00:00
vercel-release-bot
32875e4fe4 v14.0.3-canary.12 2023-11-16 16:00:52 +00:00
Zack Tanner
3cd9264abc
tweak cache + revalidate fetch warning (#58505)
### What?
When using a `Request` object with fetch, we'll log a warning indicating that using the `cache` property in addition to `revalidate` is unsupported.

### Why?
`Request` sets some defaults on the request init, such as `cache: "default"`. This makes the warning confusing and there's no way to avoid it aside from switching the resource argument to be a URL string instead.

### How?
This keeps existing behavior but omits the log in the case where a request object is used and no explicit cache overrides are specified.

Fixes #58109
2023-11-16 15:57:26 +00:00
Jiachi Liu
d6d6d56133
Remove client only dynamic chunks from edge bundle (#56761)
### Issue

In the client components world, when you're using `next/dynamic` with `ssr: false` to split chunks in pages of edge runtime, you could get the dynamic imported module still bundled in the server bundle for edge runtime. This could easily hit the bundle limit on edge runtime if you're loading a large size of non-SSR module.

This is caused by the whole chunk is still being included when we're creating the client entry. Since the client entry is imported eagerily, webpack will bundle all the modules under it, unless it's explicitly marked not being included.

### Fix

For client components, SSR rendering layer of bundle, non-SSR `next/dynamic` calls, we're transform the result of `dynamic()` call from to conditional import the dynamic loaded module.

From
```js
dynamic(() => import(...))
```
To
```js
dynamic(() => {
  require.resolveWeak(...)
}, { ssr: false })
```

This will only be applied to SSR layer bundle client components non-SSR `next/dynamic` calls and only when webpack is bundling since turbopack doesn't need this. In this way, the server side will be stripped but it can still enter the module graph since we need to traverse if there's SA in client modules with using webpack API `require.resolveWeak`. And for client side bundle will still include the actual module.

Close NEXT-1703
2023-11-16 15:10:28 +00:00
Andrew Clark
b017261047
Inline ChildProp (#58519)
I'm working on a refactor to seed the CacheNodes as soon as the Flight
payload is received, rather than lazily during the render phase. This
means we no longer need to pass a child element prop to LayoutRouter via
childProp.

ChildProp includes two fields: a segment and a child element. The child
element is the part that will soon be removed, because we'll instead
always read from the cache nodes.

But even after this refactor, we still need to pass the segment to
LayoutRouter. So as an incremental step, I've inlined both fields into
separate props:

- childProp.current -> initialChildNode. This will be removed in a later
step in favor of reading from the cache nodes. In fact, we already
always read from the cache nodes — childProp is ignored completely once
the cache node is populated, hence the updated name.
- childProp.segment -> childPropSegment. This probably isn't the best
name anymore but I'll leave renaming until later once more of this
refactor has settled.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-11-16 12:01:09 +01:00
Tom Milewski
c26c7713b5
fix: set x-forwarded-host based on request (#58500)
Co-authored-by: @BRKalow <bryce@clerk.dev>

### What?

A number of our customers have been experiencing issues stemming from an
`x-forwarded-host` header that doesn't match the `host` header.

### Why?

[This PR](https://github.com/vercel/next.js/pull/57815) removes
functionality which sets `x-forwarded-host` to `req.headers['host']` and
relies solely on the server's hostname and port.

This can be seen locally when visiting the app via a localhost
subdomain.

The `x-forwarded-host` header will remain as `localhost:${port}` while
the actual requested host will contain the subdomain.

### Related 

- https://github.com/vercel/next.js/pull/57815#issuecomment-1808496790

---------

Co-authored-by: BRKalow <bryce@clerk.dev>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-11-16 12:00:41 +01:00
Zack Tanner
24b2ff16ab
remove optimistic navigation behavior when prefetch is false (#58413)
### What?
When navigating between pages (via `prefetch: false`) within a dynamic
segment, the shared layout is re-rendered. This can cause unexpected
behavior like layout data changing when navigating between child
segments.

### Why?
When prefetch is false, we're currently opting into an "optimistic
navigation" codepath, which will optimistically render layout-routers up
to the point where data is missing, while kicking off data fetches. It
attempts to determine where refetching needs to happen by traversing the
router cache nodes and checking where data is missing. However, it
locates these cache nodes by using "segments" obtained by
[deconstructing the
URL](https://github.com/vercel/next.js/blob/fix/optimistic-bailout/packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts#L142),
which won't accurately contain dynamic segment data. For ex, `/en` which
corresponds with `/app/[lang]/page.tsx` will have a cache node key of
`lang|en|d`, not `en`. Similarly, the optimistic tree that gets
constructed will also be incorrect, since it uses the URL segment.

### How?
My initial fix was to match the dynamic segment against the segment
constructed by the URL. But after discussion with @sebmarkbage and the
team, it seems more correct to remove the optimistic case all together
as there's no guarantee that the url will actually match to that
segment.

Fixes #50670

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-11-16 11:58:17 +01:00
Zack Tanner
8d4f4fcd38
revalidate APIs should make route handlers dynamic (#58466)
### What?
Using `revalidateTag` or `revalidatePath` in a route handler will not
currently opt the handler into dynamic behavior. This means that if you
use these APIs and don't opt into dynamic behavior by some other means,
the revalidation call won't do anything as the route handler will be
served statically.

### Why?
During static generation, we do not currently indicate that usage of
these APIs should opt into dynamic usage.

### How?
This updates `revalidateTag` to throw a `DynamicUsageError` (similar to
our other scenarios, such as search params bailout, headers/cookies, or
fetch + revalidate/no-store)

Closes NEXT-1712
2023-11-16 11:57:55 +01:00
Wyatt Johnson
02103feb29
onHeaders updates for App Pages (#58410)
This serves to address a few problems as it relates to headers handling within the App Page render pipeline.

1. During static generation, we should not write to the response directly as the revalidation for static responses is performed out of band from the actual request/response as a stale version can be served early. This is partially addressed by modifying the `onHeaders` to only write when there it is not during static generation, but long term I'd hope to see that we can instead pass a immutable request and `null` for the response to help indicate to the render pipeline that it should instead persist the data into the `RenderResult` objects. Alternatively, the response could use a mocked version that would then supersede the `RenderResult` and be used instead.

2. The types for rendering App Pages were merged incorrectly, so this additionally restructures the way that we initialize those renderers such that only the options that are applicable to each renderer is passed down.
2023-11-16 05:44:58 +00:00
Tom Ballinger
2b0288912b
examples: Upgrade Convex example to convex@1.2.1 (#54910)
Co-authored-by: Lee Robinson <me@leerob.io>
2023-11-15 23:14:32 -06:00
rodrigo
6d9ce62f13
examples: update styled-components (#56457)
Co-authored-by: Lee Robinson <me@leerob.io>
2023-11-15 23:14:00 -06:00
Joshua Santos
f163dd097f
examples: fix unhandled runtime error for forms (#56600)
Co-authored-by: Lee Robinson <me@leerob.io>
2023-11-15 23:13:23 -06:00
ihommani
70389d0cfd
examples: update Dockerfile comment (#56646)
Co-authored-by: Lee Robinson <me@leerob.io>
2023-11-15 23:11:21 -06:00
Kom ॐ
d58008279f
docs: Add Jenkins build caching information (#58001) 2023-11-15 23:01:54 -06:00
Heloi Neto
c6d30da394
examples: fix typo for component (#58330) 2023-11-15 23:00:27 -06:00
Prince Agrawal
6d29fc1bfd
examples: Fix hydration error in headers example (#58383) 2023-11-15 22:59:07 -06:00
Sean Gray
f5f0767ee5
examples: update Geist font path (#58349) 2023-11-15 22:58:44 -06:00
Antonis Angelis
7226746051
docs: fix filename when it should be dynamic route (#58032) 2023-11-15 22:56:39 -06:00
Mojtaba
8d9282ce9d
docs: fix grammar issue in "Data Fetching Patterns" (#58056) 2023-11-15 22:55:19 -06:00
kentobento
f8343e80dd
docs: Fix grammar in Dynamic Rendering section (#58062) 2023-11-15 22:54:42 -06:00
kentobento
bdbc30f14a
docs: Fix grammar in Client Components section (#58065) 2023-11-15 22:54:21 -06:00
kentobento
1d5c78b925
docs: Fix grammar in Styling section (#58071) 2023-11-15 22:53:10 -06:00
Andreas
05374d3a0c
docs: make example of passing down a Server Action more clear (#57972) 2023-11-15 22:52:48 -06:00
Asad Khan
ee99c9f6e5
docs: fix grammar in revalidateTag docs (#58210) 2023-11-15 22:51:10 -06:00
Marcos Martini
dd4593b937
docs: Added Kinde auth provider (#58231) 2023-11-15 22:50:20 -06:00
Bryn Dyment
123f753042
docs: add missing apostrophe (#58236) 2023-11-15 22:49:43 -06:00
Robbert Stevens
6c422514f6
docs: update MDX metadata docs (#58396) 2023-11-15 22:49:16 -06:00
Maxime Richard
afdd5043ac
docs: fix typo on environment variables (#58188) 2023-11-15 22:46:57 -06:00
Asad Khan
8cc406e090
docs: simplify rendering docs (#58185) 2023-11-15 22:46:17 -06:00
Arham Khawar
e5bdc42621
docs: fix unnecessary capitalization (#58141) 2023-11-15 22:45:25 -06:00
Zack Tanner
9f9c74b69e
skip flushToDisk in minimal mode for fetch cache (#58516)
This temporarily disables flushing fetch cache to disk during builds in minimal mode as some additional changes are needed to support it better.

[slack context](https://vercel.slack.com/archives/C042LHPJ1NX/p1699928670252259?thread_ts=1699468188.418499&cid=C042LHPJ1NX)
2023-11-16 02:34:20 +00:00
vercel-release-bot
c8bfda4367 v14.0.3-canary.11 2023-11-15 23:22:09 +00:00
Will Binns-Smith
5f8be1f0d3
Turbopack: Use structured styled text in issue descriptions (#58156)
Requires vercel/turbo#6388

This uses the structure implemented in vercel/turbo#6388 to support formatted text when reporting. Right now only the `Line` and basic `String` cases are handled.
2023-11-15 22:33:14 +00:00
vercel-release-bot
a5515693bc v14.0.3-canary.10 2023-11-15 21:51:36 +00:00
Will Binns-Smith
9ab8828f72
Apply next/font to foreign code (#58461)
This applies next/font to third party code like that in `node_modules`


Closes PACK-1964
2023-11-15 18:52:09 +00:00
Janicklas Ralph
3ec0551fa7
Add performance.mark for next/third-parties for feature measurement (#57439)
### What?

Adding a `performance.mark` for next/third-parties for feature measurement

### Why?

We’re working with the Chrome Speed Metrics team to develop an API to better identify specific features used by frameworks and/or CMS platforms. Instead of a entirely new API surface, we've agreed to use `performance.mark` as the signal along with mark_use_counter as a signature.

In the past, we've used HTML attributes for Next which have been helpful, but this will improve the accuracy of our feature detection. In this instance, this will better help us analyze and compare sites that use `@next/third-parties` versus those that don't, and to see if our efforts are actually improving performance.

It's worth noting that this metric will have a public arm, but we're starting to incorporate its usage now to gather early data. performance.mark calls are indeed low-overhead and shouldn't affect loading/rendering performance whatsoever.
2023-11-15 17:48:38 +00:00
Delba de Oliveira
4e5702c1d3
Docs: Update middleware example snippet (#58488)
Sync with example updates made here: https://github.com/vercel/next.js/issues/57410
2023-11-15 15:30:11 +00:00
Shu Ding
036f4806a6
Upgrade vendored React (#58489)
### React upstream changes

- https://github.com/facebook/react/pull/27694
- https://github.com/facebook/react/pull/27695
- https://github.com/facebook/react/pull/27689
- https://github.com/facebook/react/pull/27687
- https://github.com/facebook/react/pull/27677
- https://github.com/facebook/react/pull/27681
2023-11-15 14:48:27 +00:00
Sukka
27dcd26c43
chore: replace fs-extra usage in scripts/ (#57215)
The PR is the continuation of #56917 and #57030.

The PR replaces `fs-extra#copy` with Node.js built-in `fs.cp` API (which is almost identical to `fs-extra#copy`, and has been available since Node.js 16). The PR also provides a workaround for flaky Windows `fs.rename` operation (#57030).

cc @styfle @wbinnssmith
2023-11-15 13:34:18 +00:00
vercel-release-bot
7281cd3fc4 v14.0.3-canary.9 2023-11-15 13:00:05 +00:00
Janicklas Ralph
280b9f9821
Add types to package.json (#58420)
cc: @housseindjirdeh
2023-11-15 12:30:21 +00:00
Donny/강동윤
f99242baca
Update turbopack (#58408)
* https://github.com/vercel/turbo/pull/6424 
* https://github.com/vercel/turbo/pull/6433 

Closes PACK-1967
2023-11-15 11:48:31 +00:00
Justin Ridgewell
52e8c4d10b
turbopack: Don't error with legacy server actions boolean (#58416)
### What?

This stops Turbopack from erroring out when trying to parse apps using NextConfig's legacy `experimental.serverActions` boolean value.

### Why?

Old apps may not have removed the legacy boolean flag, but should still run.

### How?

At first I attempted updating Zod's configuration to use a default option config when a boolean was encountered, and passing the updated config to Turbopack, but this would hide the warning message. Then I tried implementing a custom `Deserializer` on the Rust side to handle boolean values and default. But, it was just so much easier to implement with a enum supporting both the current and the legacy configuration.

Closes PACK-1962
2023-11-15 04:33:14 +00:00
Zack Tanner
4cbfe7d7e8
fix incorrect fetch cache handling (#58460)
### What?
When `FetchCache` is used, cache gets were incorrectly bailing. This would result in unexpected behavior, like continuously revalidating a cache key, as described in #57978.

### Why?
#57902 introduced a refactor to the `FileSystemCache` and changed the interface of `get`, but this change was not propagated to `FetchCache`. Specifically, `fetchCache` was removed in favor of a new type `kindHint`. As a result, cache reads would always short circuit because `fetchCache` would never be defined.

### How?
This updates the interface on `FetchCache` to match what is defined on the base `CacheHandler`. I've also updated the args to both `get` and `set` to be derived from `CacheHandler` so we don't have any type inconsistencies in the future.

I will be following up with a test in the CLI repo to test against a deployed app (since minimalMode cannot be easily mocked in our test suite). Manually verified these changes against the repro in the original issue below, at the following URLs:

https://revalidate-vercel-test-iota.vercel.app/fetch-cache-test
https://revalidate-vercel-test-iota.vercel.app/revalidate-tag-test

Fixes #57978
Fixes #58306
2023-11-15 01:24:08 +00:00
Wyatt Johnson
375d85d95e
fix: ensure batch values are sharable (#58315)
Previously, the incremental cache returned objects with a readable stream (that were consumed). These can't be shared. Instead, this modifies the cache to instead return strings which are sharable.

This also fixes a bug related to revalidation when writing an updated prefetch RSC payload to the filesystem when PPR is enabled. Previously it just wrote to `.rsc` and now it correctly writes a `.prefetch.rsc` file instead.
2023-11-15 00:20:35 +00:00
vercel-release-bot
44613dc045 v14.0.3-canary.8 2023-11-14 23:23:29 +00:00