Commit Graph

3472 Commits

Author SHA1 Message Date
Eddy (Frontend Engineer) 579ff601b4 example(cache-handler-redis): fix connection leak, hangs on a down Redis, and cross-page tag invalidation (#98716)
Three runtime problems in `examples/cache-handler-redis`.

### 1. One new Redis connection per request, never closed

Next.js constructs the singular `cacheHandler` class once per request
(`new CurCacheHandler(...)` in `IncrementalCache`, which
`route-module.ts` creates per request). The example's constructor calls
`createClient()` + `connect()`, so every request opens a connection that
is never closed.

```
$ redis-cli client list | wc -l      # before
102
$ for i in $(seq 1 10); do curl -s -o /dev/null localhost:3000/cet; done
$ redis-cli client list | wc -l
132                                  # +3 per request
```

With Redis' default `maxclients 10000`, a single instance runs out after
a few thousand requests.

### 2. Requests hang while Redis is unavailable

The README says the handlers "degrade gracefully when Redis is
unavailable, so the app still builds and runs, just without a shared
cache". At runtime they don't: with Redis stopped, every request on
every instance blocks until Redis comes back.

```
$ docker stop cache-handler-redis
$ curl -s -o /dev/null -m 60 -w "%{http_code} %{time_total}s\n" localhost:3000/cet
000 60.007305s                       # (uncapped: 188s, returned the moment Redis was started again)
```

Same when the app is started while Redis is down. Cause: node-redis
keeps retrying in the background and `client.connect()` does not settle
until a connection succeeds. Isolated:

```js
const c = createClient({ url: "redis://localhost:6379" }); c.on("error", () => {});
await Promise.race([c.connect(), new Promise(r => setTimeout(() => r("pending"), 15000))]);
// -> "pending" after 15s, isOpen=true isReady=false   (redis@6.2.1)
```

Because each request built a new handler, each request awaited a fresh,
never-settling `connect()` in `getClient()`. `remote-cache-handler.js`
has one module-level client, but its `getClient()` awaits the same
promise, so it hangs the same way if the app starts while Redis is down.

### 3. `updateTag` never reaches other pages' remote entries

The remote handler's `get` never checks the entry's own tags. Next.js
only passes soft tags to `getExpiration`, and the `"use cache"` wrapper
only knows about tags revalidated in the current request, so
`updateTag("time-data")` from `/cet` left the `/gmt` entry stale on
every instance, including the one that ran it, until it expired
(`cacheLife` `expire: 3600`). The [`cacheHandlers`
docs](https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheHandlers#get)
say `get` should report an entry whose tag was invalidated as missing or
stale.

### Fix

- Hoist the client in `cache-handler.js` to module scope (the pattern
`remote-cache-handler.js` already uses).
- `getClient()` awaits the connect promise raced against a 1s
`unref()`'d timer (suggested in review), then returns the client when
`isReady` and `null` otherwise. Requests during startup still wait for
the connection, and a down Redis costs one bounded wait instead of
blocking every request. The client keeps retrying and `isReady` flips
back on its own.
- `disableOfflineQueue: true`, so a command issued while the connection
is down rejects immediately (`ClientOfflineError`) instead of being
queued for the 5s command timeout.
- Entry `get` / `set` catch the Redis call only and degrade to a miss.
- Remote `get` compares the entry's tags against their revalidation
timestamps (one `MGET`) and misses when any is newer, the same
comparison as the built-in handler. `getExpiration` returns `Date.now()`
when Redis can't answer, so the entry is discarded rather than served.
- `revalidateTag` / `updateTags` throw when Redis isn't ready, so an
invalidation that never reached Redis surfaces as an error instead of a
success whose entries come back once Redis does.

### After

Two `next start` instances on one Redis, same script on `next@16.3.5`
and `16.4.0-canary.35` (identical results), canary's handlers vs this
PR:

| scenario | before | after |
| --- | --- | --- |
| `updateTag` from `/cet`, read `/gmt` on both instances | stale |
refreshed |
| `revalidateTag("time-data", "max")` | neither page refreshed | both
refreshed |
| tag lookup fails | 500 | 200, regenerated |
| request while Redis is stopped | no response | 200, uncached |
| `updateTag` while Redis is stopped | no response | 500, error logged |
| app started without Redis | no response | first ISR read waits ≤1.1s
once |
| Redis connections, 200 requests | 173 → 773 | 7 → 7 |
| `/cet` under load (autocannon, 10 connections × 10s, `16.3.5`) | 332
req/s, hits Redis `maxclients` | 1,106 req/s median, p99 20ms, 3
connections |
| 10 readers during 20 `updateTag`s: reads served a value from before a
completed invalidation | 3,089 of 3,089 | 0 of 33,899 |
| Redis down ~4s under load | timeouts, caching doesn't come back | 0
errors, caching resumes |

The tag check costs one Redis round trip per remote hit (−9 to −13% on a
route that only reads one remote entry). Handler-level cases, full
tables and the benchmark breakdown are in [this
comment](https://github.com/vercel/next.js/pull/98716#issuecomment-5724918096).
2026-09-18 12:07:48 +02:00
next-js-bot[bot] 83cb4fb70f Upgrade React from 6c0e1047-20260908 to 019019be-20260911 (#98576) 2026-09-11 17:58:49 +00:00
Joseph 26b2bbe024 example: Use a Redis cacheHandler w/o dependencies (#95346)
Verify locally:

- Copy the example to a local directory
- Install deps
- docker compose up -d
- npm run build && npm run start 
- navigate to localhost:3000/cet (or gmt)
- open the Redis view (link in localhost:3000/cet)
- revalidate data on /cet or /gmt
- verify it on the Redis view

I had to update the app to async params, updateTag, and write the
handler in such a way that it solved:

```
⨯ TypeError: p.segmentData.get is not a function
    at ignore-listed frames
⨯ Error: failed to pipe response
```

Also adding docs edits with this caveat.

An agent review, and cross checking with a community implementation,
surfaced, that we had to read tags from
`data.headers['x-next-cache-tags']`. This agent review added a few
comments, I think they are useful, but can cut down if needed.

Last but not least, had to update the Time API endpoint (former no
longer worked).
2026-09-09 14:42:25 +02:00
Joseph 9a7061053e docs(examples): document env var handling in the Docker examples (#97968)
Improve with-docker example env var usage documentation.

Closes: https://github.com/vercel/next.js/issues/97959
2026-08-28 11:08:57 +02:00
niketchandivade 844c62e1a6 fix: add accessible label to icon-only link (#96334)
## Summary

This PR improves the accessibility of the Ant Design example by adding
an accessible label to the icon-only `Link`.

### Changes

- Added `aria-label="Home"` to the icon-only link.

### Why

The link currently renders only an icon, so it does not provide an
accessible name for assistive technologies. Adding an `aria-label` makes
its purpose clear to screen reader users without changing the visual
appearance.

### Before

Screen readers announce the element as an unlabeled link.

### After

Screen readers announce the link as **"Home"**.

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
2026-08-19 21:10:39 +00:00
niketchandivade 0eb3775416 style(examples): remove redundant justify-content declaration (#97222)
## Summary

While reviewing the examples in the Next.js repository for potential
improvements, I noticed a redundant `justify-content` declaration in the
`.submit` styles.

## Changes

- Removed the redundant `justify-content: flex-end` declaration.
- Kept `justify-content: space-between`, which overrides the previous
declaration.

## Testing

No functional changes. This is a CSS cleanup only.

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
2026-08-18 22:41:00 +00:00
niketchandivade 520de42f19 fix: improve form accessibility by associating labels with inputs (#96335)
## Summary

This PR improves the accessibility of the `with-apivideo-upload` example
by associating form labels with their corresponding form controls using
the `htmlFor` attribute.

## Changes

- Added `htmlFor="link"` to the "Play button color" label.
- Added `htmlFor="linkHover"` to the "Buttons hover color" label.
- Added an `id` to the "Hide controls" checkbox and associated its label
using `htmlFor`.

## Why

Associating labels with their corresponding form controls improves
accessibility by:

- Allowing screen readers to correctly announce form labels.
- Enabling users to focus or toggle controls by clicking their labels.
- Following HTML and WCAG best practices for accessible forms.

## Before

- Labels were visually displayed but were not programmatically
associated with their respective inputs.

## After

- Each label is associated with its corresponding form control via
`htmlFor` and `id`, improving accessibility without changing
functionality.

### Testing

- Verified that clicking each label focuses or toggles the associated
control.
- No visual changes.

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
2026-08-18 22:33:46 +00:00
niketchandivade 0ff70fd55b fix(examples): correct error message typo (#97223)
## Summary

While reviewing the examples in the Next.js repository for potential
improvements, I noticed a typo in the error message displayed when an
unexpected error occurs.

## Changes

- Corrected `"An unexpected error happened occurred:"` to `"An
unexpected error occurred:"`.

## Testing

No functional changes. This is a text-only fix.

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
2026-08-18 22:31:36 +00:00
이동현 fe87d7ac75 docs: fix typos in example links (#97149)
Fixes typos in the `analytics.tsx` link syntax in the two Segment
example READMEs.

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
2026-08-18 15:08:17 -07:00
Gary Tyr a4420747ab Update blob version. (#97342) 2026-08-14 08:41:33 +02:00
Marcos Hernanz 8c1c9a6922 examples: fix Webiny API env variable name (#97134)
## Summary

Fix the `cms-webiny` example so non-preview requests read
`NEXT_PUBLIC_WEBINY_API_URL`, matching the README, deploy button, and
`.env.local.example`. The previous `NEXT_PUBLIC_WEBINY_API_UR` typo
caused the default API endpoint to resolve to `undefined`.

## Verification

- `rg -n
"NEXT_PUBLIC_WEBINY_API_UR|NEXT_PUBLIC_WEBINY_API_URL|NEXT_PUBLIC_WEBINY_PREVIEW_API_URL"
examples/cms-webiny`
- `git diff --check`
- Not run: full example runtime (`cms-webiny` requires external Webiny
API credentials)

Attribution: This change was originally authored by @tianma-if in
#95413.

<!-- NEXT_JS_LLM_PR -->

Co-authored-by: tianma <tianma@tianmadeMac-mini.local>
2026-08-10 15:49:14 -07:00
Joseph 8ff8f1b82e docs: add authentication with Cache Components guide and iron-session example (#95802)
- new guide, Auth w/ Cache Components
- iron-session example w/ Cache Components

TODO:

- [x] opt-out from the instant requirements
- [x] e2e for the example, using instant helper

---------

Co-authored-by: Aurora Scharff <66901228+aurorascharff@users.noreply.github.com>
Co-authored-by: Aurora Scharff <aurora.sofie@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 09:49:57 +00:00
Joseph ec76f095ab docs: document query-only href resolution and fix with-vercel-blob (#96280)
Closes: https://github.com/vercel/next.js/issues/96204

The fix to manage rewrites introduced in
https://github.com/vercel/next.js/pull/82236 PR made it so that,
push/replace without explicit pathname broke the `as` pattern, for
example in `with-vercel-blob`.

Also documents the resolution rule in the `useRouter` API reference.
2026-07-27 17:57:37 -04:00
MOHAMMED WASIM KHAN 3ab9d196ab fix: remove deprecated url.parse() from custom-server example (#96105)
Fixes #86951

Removes the deprecated legacy `url.parse()` API (DEP0169) from the
custom-server example. The `parsedUrl` parameter is optional, so the
simplest fix is to remove the `parse()` call and pass only `(req, res)`
to the handler, matching the docs code block that was already updated in
#86986.
2026-07-24 00:04:08 +02:00
Vercel Release Bot cee9824aa5 Upgrade React from 172742b4-20260716 to 81e442ea-20260721 (#96016)
Co-authored-by: next-js-bot[bot] <279046576+next-js-bot[bot]@users.noreply.github.com>
2026-07-21 17:25:13 +00:00
Zafor Abdullah 93c59f02f8 fix: error handling and loading states in with-apollo-and-redux example (#91457)
## For Contributors

### Fixing a bug

- Fixes #(open or reference an issue if one exists, otherwise omit)
- No tests required — this is an `examples/` change only
- No custom error links needed — failures are surfaced via Apollo's
built-in error state

---

## Summary

- `PostList` destructured `data` before checking `loading`/`error`, so
the component threw when `data` was `undefined` (e.g., on the initial
fetch or after a query error) instead of showing the loading/error UI.
- Move the `error`/`loading`/`!data` guard clauses above the `data`
destructuring and `loadMorePosts` definition, and add a `!data` check so
the component never accesses properties on an undefined value.
- Bump `graphql` (`14.5.8` → `16.13.1`) and `lodash` (`4.17.20` →
`4.17.23`) in the example's `package.json` to pick up fixes in
dependencies the example relies on.

## Note: 
Initially this PR suppose to target upstream DB issue
2026-07-21 17:44:56 +02:00
Manoraj K 8669b07f19 fix(cms-contentful): await draftMode() and use Promise<> params type (#95631)
### What?
Fix the `cms-contentful` example to use the async APIs introduced in
Next.js 15:
- Await `draftMode()` in `app/page.tsx`, `app/posts/[slug]/page.tsx`,
and
  `app/api/disable-draft/route.ts`
  - Update `params` type to `Promise<{ slug: string }>` and await it in
  `app/posts/[slug]/page.tsx`

### Why?
In Next.js 15, `draftMode()` from `next/headers` became async and must
be awaited.
Page `params` are also now typed as a `Promise`. The example was using
the old
synchronous patterns, causing the build to fail and the app to not work
when running against the latest
version of Next.js -- this example project uses latest version of
next.js in the package.json.

### How?
Awaited `draftMode()` at each call site and updated the `params` type
signature to
  `Promise<{ slug: string }>` with a corresponding `await`.

Closes NEXT-
Fixes #
2026-07-20 18:18:38 +02:00
Luke Sandberg e4e5bc2c87 align dev and build output (#94916)
Log the version of next _before_ evaluating the config in `next build`
just like `next dev`

Also, if `withRspack` is used, print a simple line saying that the
bundler has changed.
2026-07-08 05:38:20 +00:00
niketchandivade 6a5dde6132 docs: fix preview message typo (#95050)
## What?

Fixes a typo in the preview message.

- This is page is a preview.
+ This page is a preview.

## Why?

The current text contains a grammatical error that is shown when preview
mode is enabled.

## Testing

* Verified the updated text renders correctly.
* No functional changes.
2026-06-26 11:42:50 +02:00
Owen Pearson 56fe894489 examples/with-ably: update to App Router + Ably v2 (#94600)
## Summary

Modernizes the `examples/with-ably` example off the deprecated Pages
Router and `@ably-labs/react-hooks` package, onto the App Router and the
React hooks that ship with ably-js v2.

The previous example created the Realtime client at module scope inside
`pages/_app.tsx`, which caused connections to be created during SSR. The
rewrite creates it inside a `useEffect` in a client component
(`app/ably-client-provider.tsx`), gated by an `AblyReadyContext` so
consumer components don't try to call `ably/react` hooks before the
provider is in place.

## Notable changes

- Replace Pages Router with App Router.
- Upgrade `ably` to v2; drop `@ably-labs/react-hooks` (hooks now ship as
`ably/react`).
- Bump React, react-dom and their `@types` to v19 to match
recently-modernized examples like `with-supabase`.
- `app/api/createTokenRequest/route.ts` now returns 400 when `clientId`
is missing rather than coalescing to a shared `"NO_CLIENT_ID"` value.
- Various improvements to README.md

## How I tested these changes

Ran the example with Chrome and Firefox. Verified in two browser
windows:

- Pub/sub: messages published from one window appear in both.
- Server publish: `POST /api/send-message` round-trips and broadcasts.
- Presence: events propagate between windows.
- No errors or warnings in browser console or dev console.

Co-authored-by: Fiona Corden <fiona.corden@ably.com>
2026-06-18 14:12:28 +02:00
Vercel Release Bot 84f9247617 Upgrade React from f0dfee38-20260529 to 43bcbf80-20260603 (#94440)
[diff
facebook/react@f0dfee38...43bcbf80](https://github.com/facebook/react/compare/f0dfee38...43bcbf80)

<details>
<summary>React upstream changes</summary>

- https://github.com/facebook/react/pull/36586
- https://github.com/facebook/react/pull/36603
- https://github.com/facebook/react/pull/36585
- https://github.com/facebook/react/pull/36580
- https://github.com/facebook/react/pull/36584
- https://github.com/facebook/react/pull/36583
- https://github.com/facebook/react/pull/36576
- https://github.com/facebook/react/pull/36575
- https://github.com/facebook/react/pull/36574

</details>

---------

Co-authored-by: next-js-bot[bot] <279046576+next-js-bot[bot]@users.noreply.github.com>
Co-authored-by: Josh Story <gnoff@storyposted.com>
2026-06-05 08:11:55 -07:00
christopherkindl 020d79bb27 [examples] migrate cloudinary to vercel-blob (#93762)
## Summary

Replaces the Cloudinary-backed image gallery example with a Vercel
Blob–backed equivalent. The migration is driven by the broader move of
[`vercel/nextconf-image-gallery`](https://github.com/vercel/nextconf-image-gallery)
(the deployed companion to this example) off Cloudinary.

- Renamed `examples/with-cloudinary` → `examples/with-vercel-blob` via
`git mv` (history preserved).
- Images are discovered at build time via the `@vercel/blob` SDK's
`list()` API, then probed with
[`sharp`](https://github.com/lovell/sharp) for dimensions and to
pre-generate base64 blur placeholders. `next/image` (Vercel's image
optimizer) handles resizing — no Cloudinary `c_scale,w_*` transform
URLs.
- `ImageProps` is now `{ id, url, width, height, blurDataUrl }` (was `{
public_id, format, ... }`).
- `utils/cachedImages.ts` does the listing + dimension probe + blur
placeholder generation.
- Removed `utils/cloudinary.ts` and `utils/generateBlurPlaceholder.ts`.
- `next.config.js` `remotePatterns` now allows
`*.public.blob.vercel-storage.com`.
- Deps: dropped `cloudinary`, `imagemin`, `imagemin-jpegtran`; added
`@vercel/blob` and `sharp`.
- `.env.local.example` reduced to a single `BLOB_READ_WRITE_TOKEN`.
- README rewritten: blob description, deploy-button env, setup steps,
references.

## Test plan

- [x] `npx create-next-app --example with-vercel-blob ./blob-app` clones
cleanly
- [x] After populating a blob store and `.env.local`, `npm run dev`
renders the gallery with blur placeholders
- [x] `npm run build` succeeds (sharp probe + placeholder generation
runs at build time)
- [x] Vercel deploy button flow prompts only for `BLOB_READ_WRITE_TOKEN`

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-05-12 11:01:10 +02:00
Vercel Release Bot bab166a0d2 Upgrade React from f4e0d4ed-20260429 to dd453071-20260506 (#93547)
Co-authored-by: next-js-bot[bot] <279046576+next-js-bot[bot]@users.noreply.github.com>
2026-05-06 18:19:56 +00:00
Joseph fb06f5f389 example: remove with-supertokens (#93212)
Retaking the example clean up cycle.
2026-04-24 22:02:27 +02:00
Sebastian "Sebbie" Silbermann bdf8bea015 Update React from 74568e86-20260328 to 404b38c7-20260408 (#92536) 2026-04-08 22:10:09 +02:00
Jam Balaya 7dd1fcfc92 chore(examples): remove with-styletron example (#81842)
## Summary

Remove
[with-styletron](https://github.com/vercel/next.js/tree/canary/examples/with-styletron)
example and its references from the repository.

Documentation:
- Remove the Styletron link from the CSS-in-JS examples list in the docs

Tests:
- Remove the Styletron entry from the
turbopack-dev-examples-manifest.json

Chores:
- Delete the examples/with-styletron directory and its contents

## Why?

[styletron](https://github.com/styletron/styletron) package hasn't been
maintained in 2 years.

## Adding or Updating Examples

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

cc: @samcx

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-03-24 02:25:32 +01:00
Kowyo 5a22623262 example: remove duplicate items in .dockerignore (#91079)
Removed duplicate entries for cache and temporary directories.

```diff
- # Cache directories and temporary data
- .cache/
- .parcel-cache/
- .eslintcache
- .stylelintcache
- .turbo/
- .tmp/
# Cache directories and temporary data
.cache/
.parcel-cache/
.eslintcache
.stylelintcache
.swc/
.turbo/
.tmp/
.temp/
```

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-03-09 13:21:27 +01:00
Karl Horky a0d293fc08 with-docker: add new config file formats (#90731)
<!-- 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

### 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 #

-->

### What?

Update config files in the `with-docker` example inside the
`.dockerignore`

### Why?

They are outdated

### How?

Add lines

cc @icyJoseph

---------

Co-authored-by: Joseph <sephxd1234@gmail.com>
2026-03-02 11:39:03 +01:00
Joseph 7643fc9483 example: restore .next handling for with-docker examples (#90651)
- Remove BuildKit cache mount on `.next/cache` that trapped fetch cache
in a volume unreachable by the runner stage
- Restore `mkdir .next && chown` in runner stage for writable prerender
cache
- Add commented-out `COPY .next/cache` line as opt-in for persisting
build-time fetch cache
- Apply same fixes to `Dockerfile.bun` (only needed the `mkdir`/`chown`,
it never had the BuildKit mount)

Closes #90648
2026-02-27 15:23:45 +01:00
Hayden Bleasel 22e46a40ad Migrate from react-markdown to Streamdown static in EdgeDB example (#86435)
This pull request updates the blog post rendering in the EdgeDB example
to use our `streamdown` library in static mode instead of
`react-markdown` for Markdown parsing and rendering.

---------

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-02-21 00:39:53 +01:00
Kristiyan Velkov d7732c57d6 [feat] Added Docker examples for standalone output and export output following best practices (#87069)
## What?

Modernizes the existing `with-docker` example and adds a new
`with-docker-export-output` example demonstrating different Next.js
deployment strategies with Docker best practices:

1. **`with-docker` (updated)** - Modernized to use App Router,
TypeScript, Tailwind CSS v4, and comprehensive Docker best practices.
Now includes both Node.js and Bun Dockerfile options, Docker Compose
with profiles, BuildKit cache mounts, and extensive documentation.

2. **`with-docker-export-output` (new)** - Demonstrates Next.js static
export mode deployment with Docker, offering two serving options:
**Nginx** (production-grade) and **serve** package (Node.js-based,
simpler setup). Includes optimized Nginx configuration, BuildKit cache
mounts, and comprehensive documentation.

Both examples include detailed documentation explaining Docker best
practices, implementation decisions, and deployment guidance.

## Why?

The existing `with-docker` example was using the Pages Router and
lacked:

- Modern Next.js patterns (App Router, TypeScript)
- Detailed documentation explaining Docker best practices and
implementation decisions
- BuildKit cache mounts for optimized build performance
- Bun runtime support as an alternative to Node.js
- Docker Compose configurations for easier local development
- Clear documentation about Node.js image variant choices (slim vs
Alpine)
- Examples demonstrating static export mode

These updates serve as comprehensive references for developers who want
to understand:

- How to Dockerize Next.js applications for different deployment
scenarios
- Why certain choices are made and how to optimize Docker setups for
production
- When to use standalone mode vs static export mode
- How to choose between Node.js and Bun runtimes
- How to choose between different web servers (Nginx vs serve) for
static sites

## How?

### `with-docker` example (updated)

- **Migrated to App Router** with TypeScript and Tailwind CSS v4
- **Multi-stage Dockerfile** with three stages: dependencies
installation, build, and runtime
- **Bun support** via `Dockerfile.bun` with optimized configuration
- **BuildKit cache mounts** for package manager stores (`npm`, `yarn`,
`pnpm`, `bun`) and Next.js build cache
- **Security best practices** with non-root user execution (built-in
`node` and `bun` users)
- **Docker Compose configuration** with profiles for Node.js (default)
and Bun
- **Comprehensive `.dockerignore`** to minimize build context size
- **Detailed README** explaining standalone mode benefits, Node.js image
choices, and deployment guidance
- **Deleted** `with-docker-standalone-output` (merged into this example)

### `with-docker-export-output` example (new)

- **Two Dockerfile options:**
- `Dockerfile` - Nginx-based serving with `nginxinc/nginx-unprivileged`
for security
- `Dockerfile.serve` - Node.js serve package-based serving for simpler
deployments
- **Multi-stage builds** for both options with separate dependency,
build, and runtime stages
- **BuildKit cache mounts** for package manager stores and Next.js build
cache
- **Production Nginx configuration** (`nginx.conf`) with gzip
compression, caching headers, and security best practices
- **Docker Compose configuration** supporting both serving options via
profiles
- **Comprehensive README** explaining static export mode, trade-offs
between Nginx and serve

### Docker best practices implemented (both examples)

| Practice | Description |
|----------|-------------|
| Multi-stage builds | Optimal image size reduction |
| Layer caching | Package files copied first |
| Minimal build context | Comprehensive `.dockerignore` files |
| BuildKit cache mounts | Faster subsequent builds |
| Security hardening | Non-root user execution |
| Corepack | yarn/pnpm version management |
| Package manager auto-detection | npm, yarn, pnpm support |
| Node.js 24.13.0-slim | Clear upgrade guidance |

## Breaking Changes

> **Warning**
> - `with-docker` now uses App Router instead of Pages Router
> - `with-docker-standalone-output` has been removed (merged into
`with-docker`)

---

**Note:** After this PR is approved and merged, I plan to open a
follow-up PR to update the Next.js documentation with proper links to
these Docker examples.

---------

Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
Co-authored-by: kristiyan.velkov <kristiyan.velkov@ffw.com>
2026-02-20 15:57:11 +01:00
Joseph d6d84be211 Remove more examples (#89709)
Removing examples that we are not using, or maintaining anymore.
2026-02-09 10:36:57 +00:00
Jam Balaya 1ac8cb06e3 chore(examples): remove with-tigris example (#81843)
## Summary

Remove the
[with-tigris](https://github.com/vercel/next.js/tree/canary/examples/with-tigris)
example and clean up its references in lint and test configs

Build:
- Remove with-tigris paths from .eslintignore
- Remove with-tigris entry from turbopack-dev-examples-manifest.json

Chores:
- Delete the with-tigris example directory and all its files

## Why?


[@tigrisdata/core](https://github.com/tigrisdata-archive/tigris-client-ts)
package hasn't been maintained in 2 years.

## Adding or Updating Examples

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

cc: @samcx

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-02-04 16:44:11 +01:00
Jam Balaya c2214e7aae chore(examples): remove with-recoil exmaple (#81836)
## Summary

Remove the deprecated
[with-recoil](https://github.com/vercel/next.js/tree/canary/examples/with-recoil)
example and update the examples manifest accordingly

Chores:
- Delete the examples/with-recoil directory and its contents
- Remove the with-recoil entry from
test/turbopack-dev-examples-manifest.json

## Why?

[Recoil](https://github.com/facebookexperimental/Recoil) was archived by
the owner on Jan 2, 2025.

## Adding or Updating Examples

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

cc: @samcx

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2026-02-03 21:45:37 +01:00
Sebastian "Sebbie" Silbermann a04499797e Re-enable types-and-precompiled (#89070) 2026-01-26 23:19:43 +00:00
Simeon Griggs 70d357a3ea Update with-mysql example to Next.js 15, Tailwind 4, Prisma 7 (#88475)
## Summary

Updates the `with-mysql` example to use latest versions of all
dependencies.

### What

- Migrate from Pages Router to App Router
- Update to React 19 and Next.js latest
- Update to Tailwind CSS v4 with `@import "tailwindcss"` syntax
- Update to Prisma 7 with `@prisma/adapter-planetscale` driver adapter
- Convert all files to TypeScript
- Remove unused API route and `vercel.svg`
- Update README to clarify this is for PlanetScale MySQL and link to
[vercel/postgres-next-starter](https://github.com/vercel/postgres-next-starter)
for Postgres users

### Why

The example was significantly outdated:
- Prisma 3.10.0 → Prisma 7 (latest)
- Tailwind 3.0.23 → Tailwind 4
- React 18.2.0 → React 19
- Pages Router → App Router

### How

Followed the official migration guides:
- [Prisma 7 upgrade
guide](https://www.prisma.io/docs/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-7)
- [PlanetScale quickstart with
Prisma](https://www.prisma.io/docs/getting-started/prisma-orm/quickstart/planetscale)
- Aligned configuration files with a fresh `create-next-app` output

## Related

N/A

## How to Test

```bash
cd examples/with-mysql
npm install
# Set up .env with your PlanetScale DATABASE_URL
npx prisma generate
npx prisma db push
npx prisma db seed
npm run dev
```

## Checklist

- [x] Tests and samples are included
- [x] Documentation is updated (README)

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
2026-01-20 12:16:44 +01:00
Nhan Nguyen c68d18c507 fix(examples): resolve hydration mismatch in blog-starter (#87703)
## What?
Add `suppressHydrationWarning` to the `<html>` element in the
blog-starter example.

## Why?
The ThemeSwitcher script runs before React hydration and adds `dark`
class and `data-mode` attribute to the `<html>` element, causing a
hydration mismatch error.

## How?
Add `suppressHydrationWarning` to the `<html>` element to tell React
this mismatch is intentional.

Fixes #74586

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-12-23 21:02:35 +00:00
pji2918 2446efeaa6 fix: Change Dockerfile.bun to use group/useradd instead of addgroup/user (#87443)
<!-- 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

### 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
-->

(sorry for my bad english)

### What?
Change `/examples/with-docker/Dockerfile.bun` to use group/useradd
instead of addgroup/user.

### Why?
Currently, the `docker build` command results in an error
`/bin/sh: 1: addgroup: not found`.
(related issue: oven-sh/bun#25441)

### How?
I changed the addgroup/user command to user/groupadd as a workaround.
[#](https://github.com/oven-sh/bun/issues/25441#issuecomment-3668036074)

fixes #87722.

---------

Co-authored-by: Joseph <sephxd1234@gmail.com>
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-12-23 18:34:44 +01:00
nextjs-bot 1c09f4494b Upgrade React from b45bb335-20251211 to f93b9fd4-20251217 (#87281) 2025-12-18 00:10:32 +00:00
Benjamin Woodruff ea927b583d Turbopack: Improve the description on InvalidLoaderRuleConditionIssue (#87008)
It's near-impossible to get this to error on the Rust side (issues are caught before we get here), but I hacked up the code to make it error. It looks like this:

![Screenshot 2025-12-09 at 4.39.24 PM.png](https://app.graphite.com/user-attachments/assets/796b5efa-b2e5-4a9c-bcf3-03cee0a0861d.png)
2025-12-12 12:51:14 -08:00
Sebastian "Sebbie" Silbermann 435000f407 Upgrade React from 55480b4d-20251208 to 80cb7a99-20251211 (#87078) 2025-12-11 22:05:41 +01:00
Joseph ac8d891d95 examples: ensure examples use latest versions (#86949) 2025-12-09 21:22:08 +01:00
nextjs-bot 6ef90ef49f Upgrade React from fd524fe0-20251121 to 7dc903cd-20251203 (#86771) 2025-12-03 16:20:59 +00:00
Jam Balaya 555838ecbe examples: fix typos in cms-agilitycms (#82504)
## Summary

Correct spelling errors in the cms-agilitycms example, including the
image prop spelling and dependency imports.

Bug Fixes:
- Fix misspelled intersectionTreshold prop to intersectionThreshold in
the Image component and its useInView configuration

Enhancements:
- Rename dependancies.ts to dependencies.ts and update
requireComponentDependancyByName to requireComponentDependencyByName
across API and component imports

### Adding or Updating Examples

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

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-11-26 00:05:18 +01:00
Jam Balaya 0dd4ba3fd6 chore(examples): remove with-windicss example (#81846)
## Summary

Delete the entire
[with-windicss](https://github.com/vercel/next.js/tree/canary/examples/with-windicss)
directory and its contents

## Why?

[windicss](https://github.com/windicss/windicss) is
[sunsetting](https://windicss.org/posts/sunsetting.html).

## Adding or Updating Examples

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

cc: @samcx

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-11-25 10:01:41 +01:00
Jam Balaya d45fc5ad95 examples: fix typos (#82506)
## Summary

Fix typos in code, styles, and documentation across multiple example
projects

Chores:
- Correct variable name typo in the with-slate example
(edtorState→editorState)
- Fix CSS/SASS class name misspellings (populer→popular, Serach→Search,
serachSelector→searchSelector)
- Update example documentation and comments to fix English typos (Data
SOUCE→SOURCE, accessiblity→accessibility, exchanges, doesn't, deploying,
validates, quickly)

### Adding or Updating Examples

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

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-11-24 14:04:41 +01:00
Jon Meyers fc4f062ba9 Chore: Update with-supabase example to Next.js 16 (#86105)
### What?

Upgrade with-supabase example to be compatible with Next.js 16

### Why?

1. Users get console warnings about middleware vs proxy
2. Enabling Cache Components config results in build errors for async
behaviour outside Suspense boundary
3. Turbopack flag is default and therefore, no longer necessary on `npm
run dev`

### How?

1. Renamed all instances of `middleware` to `proxy`
2. Wraped async behaviour in Suspense boundaries
3. Removed --turbopack flag from `npm run dev`

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2025-11-17 22:41:21 -08:00
Jiwon Choi 61136d8e4b [devtools] Remove title from preferences (#85698)
The heading sections in DevTools regressed. We decided to remove them as
"Dev Server" settings are obviously dev server settings, no need to
differentiate as separate tabs.

| Before | After |
|--------|--------|
| <img width="1024" height="1006" alt="CleanShot 2025-11-02 at 12 59
21@2x"
src="https://github.com/user-attachments/assets/0a8b0c2f-3f0a-487d-9344-b33b5ee016f5"
/> | <img width="1024" height="1006" alt="CleanShot 2025-11-02 at 12 59
07@2x"
src="https://github.com/user-attachments/assets/ddd3b029-8957-4129-aaf2-7b1a57a52e00"
/> |
2025-11-02 13:14:20 +01:00
Luke Sandberg e2262334f8 [turbopack] Implement improved deobfuscation for free calls and module identifiers. (#85060)
Improve deobfuscation of 'imported module identifier' and attempt to deobfuscate error messages logged by the server.

Before
```
 ⨯ TypeError: (0 , __TURBOPACK__imported__module__$5b$project$5d2f$examples$2f$with$2d$turbopack$2f$app$2f$foo$2e$ts__$5b$app$2d$rsc$5d$__$28$ecmascript$29$__.foo) is not a function
    at Page (app/page.tsx:5:6)
  3 | export default function Page() {
  4 |   /** @ts-ignore */
> 5 |   foo();
    |      ^
  6 |   return <h1>Hello, Next.js!</h1>;
  7 | }
  8 | {
```
after 
```
 ⨯ TypeError: {imported module ./examples/with-turbopack/app/foo.ts}.foo is not a function
    at Page (app/page.tsx:5:6)
  3 | export default function Page() {
  4 |   /** @ts-ignore */
> 5 |   foo();
    |      ^
  6 |   return <h1>Hello, Next.js!</h1>;
  7 | }
  8 | {
```

Similarly in devtools
before:

![image.png](https://app.graphite.dev/user-attachments/assets/fd50d94a-d34a-4026-862e-0ca8ee6658ba.png)

after

![image.png](https://app.graphite.dev/user-attachments/assets/d9080ed7-29c8-428a-831a-9bbcd818cc3e.png)


This is definitely an improvement but i am not sure i put the deobfuscation logic in the best place for the console case.  Happy for feedback
2025-10-21 13:54:28 -07:00
Luke Sandberg d917d2e45f [turbopack] Prevent accidental access to .next (#84714)
Certain patterns in source code cause turbopack to scan the project directories for resources.  This can go wrong when one of those patterns can traverse into .next (oroborous!).

There is no usecase for turbopack to read files from the distDir during analysis and we can prevent that with a simple filter at the FileSystem layer which is what this PR does.  Given the recent `build/dev` split this is a little subtle, so i added a new property to `NextConfigComplete` so we always pass the original `distDir` down even when we are performing the `dev` split.

The semantics of this are implemented at the filesystem layer which means:
* writing into a 'denied_path' is an error
* reading a denied path is 'not found'
* reading the parent directory of a denied path filters it.

Closes PACK-5593
2025-10-17 16:18:16 -07:00