-
Notifications
You must be signed in to change notification settings - Fork 30.7k
docs: add deploymentId config and clarify encryption key for self-hosting #89795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f23f924
docs: add deploymentId config and clarify encryption key for self-hos…
icyJoseph b7fbf6a
docs: Include Version Skew in Glossary
icyJoseph 79ab0c9
docs: encryption key build cache behavior and deploymentId feedback
icyJoseph bd2f385
docs: further improvement to build/runtime encryption key
icyJoseph b2e2b22
docs: dpl query params is for proxies
icyJoseph a431c34
docs: simpler dpl good to know
icyJoseph eec06d8
docs: overriding order for deploymentId
icyJoseph 488d4d9
Merge branch 'canary' into docs/deployment-id-encryption-key
icyJoseph 46f0f18
docs: actionable version-aware routing indication
icyJoseph 9a49163
Apply suggestions from code review
icyJoseph ed4b7e0
docs: remove server functions from Pages Router version
icyJoseph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
docs/01-app/03-api-reference/05-config/01-next-config-js/deploymentId.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| --- | ||
| title: deploymentId | ||
| description: Configure a deployment identifier used for version skew protection and cache busting. | ||
| --- | ||
|
|
||
| {/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} | ||
|
|
||
| The `deploymentId` option allows you to set an identifier for your deployment. This identifier is used for [version skew](/docs/app/guides/self-hosting#version-skew) protection and cache busting during rolling deployments. | ||
|
|
||
| ```js filename="next.config.js" | ||
| module.exports = { | ||
| deploymentId: 'my-deployment-id', | ||
| } | ||
| ``` | ||
|
|
||
| You can also set the deployment ID using the `NEXT_DEPLOYMENT_ID` environment variable: | ||
|
|
||
| ```bash | ||
| NEXT_DEPLOYMENT_ID=my-deployment-id next build | ||
| ``` | ||
|
|
||
| > **Good to know:** If both are set, the `deploymentId` value in `next.config.js` takes precedence over the `NEXT_DEPLOYMENT_ID` environment variable. | ||
mischnic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## How it works | ||
|
|
||
| When a `deploymentId` is configured, Next.js: | ||
|
|
||
| 1. Appends `?dpl=<deploymentId>` to static asset URLs (JavaScript, CSS, images) | ||
| 2. Adds an `x-deployment-id` header to client-side navigation requests | ||
| 3. Adds an `x-nextjs-deployment-id` header to navigation responses | ||
| 4. Injects a `data-dpl-id` attribute on the `<html>` element | ||
|
|
||
| When the client detects a mismatch between its deployment ID and the server's (via the response header), it triggers a hard navigation (full page reload) instead of a client-side navigation. This ensures users always receive assets <AppOnly>and Server Functions</AppOnly> from a consistent deployment version. | ||
|
|
||
| > **Good to know:** Next.js does not read the `?dpl=` query parameter on incoming requests. The query parameter is for cache busting (ensuring browsers and CDNs fetch fresh assets), not for routing. If you need version-aware routing, consult your hosting provider or CDN's documentation for implementing deployment-based routing. | ||
|
|
||
| ## Use cases | ||
|
|
||
| ### Rolling deployments | ||
|
|
||
| During a rolling deployment, some server instances may be running the new version while others are still running the old version. Without a deployment ID, users might receive a mix of old and new assets, causing errors. | ||
|
|
||
| Setting a consistent `deploymentId` per deployment ensures: | ||
|
|
||
| <AppOnly> | ||
|
|
||
| - Clients always request assets from a matching deployment version | ||
| - Mismatches trigger a full reload to fetch the correct assets | ||
| - Server Functions work correctly across deployment boundaries | ||
|
|
||
| </AppOnly> | ||
|
|
||
| <PagesOnly> | ||
|
|
||
| - Clients always request assets from a matching deployment version | ||
| - Mismatches trigger a full reload to fetch the correct assets | ||
|
|
||
| </PagesOnly> | ||
|
|
||
| ### Multi-server environments | ||
|
|
||
| When running multiple instances of your Next.js application behind a load balancer, all instances for the same deployment should use the same `deploymentId`. | ||
|
|
||
| ```js filename="next.config.js" | ||
| module.exports = { | ||
| deploymentId: process.env.DEPLOYMENT_VERSION || process.env.GIT_SHA, | ||
| } | ||
| ``` | ||
|
|
||
| ## Version History | ||
|
|
||
| | Version | Changes | | ||
| | ---------- | ----------------------------------------------------- | | ||
| | `v14.1.4` | `deploymentId` stabilized as top-level config option. | | ||
| | `v13.4.10` | `experimental.deploymentId` introduced. | | ||
|
|
||
| ## Related | ||
|
|
||
| - [Self-Hosting - Version Skew](/docs/app/guides/self-hosting#version-skew) | ||
| - [generateBuildId](/docs/app/api-reference/config/next-config-js/generateBuildId) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
docs/02-pages/04-api-reference/04-config/01-next-config-js/deploymentId.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| title: deploymentId | ||
| description: Configure a deployment identifier used for version skew protection and cache busting. | ||
| source: app/api-reference/config/next-config-js/deploymentId | ||
| --- | ||
|
|
||
| {/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this list exists two times now?
once here and then another time (slightly differently) in docs/01-app/03-api-reference/05-config/01-next-config-js/deploymentId.mdx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's OK, because it is a Guide vs API Reference