Files
Tobias KoppersandGitHub 689f6fe38e Add NEXT_DEPLOYMENT_ID global (#86738)
- Adds a `process.env.NEXT_DEPLOYMENT_ID` -> `globalThis.NEXT_DEPLOYMENT_ID` replacement
- On startup, `globalThis.NEXT_DEPLOYMENT_ID` is initialized to `process.env.NEXT_DEPLOYMENT_ID_COMPILE_TIME`

This prepares for https://github.com/vercel/next.js/pull/88761 to replace `process.env.NEXT_DEPLOYMENT_ID_COMPILE_TIME` with reading `<html data-dpl-id>` so that we can remove the env var inlining

However, all of this is only done for Turbopack, because we cannot forward `globalThis.NEXT_DEPLOYMENT_ID` to web workers with Webpack easily.
2026-01-20 15:28:59 +01:00

36 lines
894 B
JavaScript

'use client'
import { useState } from 'react'
export default function Home() {
const [workerDeploymentId, setWorkerDeploymentId] = useState('default')
const mainDeploymentId = process.env.NEXT_DEPLOYMENT_ID
return (
<div>
<button
onClick={() => {
const worker = new Worker(
new URL('../deployment-id-worker', import.meta.url),
{
type: 'module',
}
)
worker.addEventListener('message', (event) => {
setWorkerDeploymentId(event.data)
})
}}
>
Get deployment ID from worker
</button>
<p>
Main deployment ID:{' '}
<span id="main-deployment-id">{mainDeploymentId}</span>
</p>
<p>
Worker deployment ID:{' '}
<span id="worker-deployment-id">{workerDeploymentId}</span>
</p>
</div>
)
}