mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## What Using methods from `next/headers` in middleware would throw a `requestAsyncStorage` invariant. Additionally, using `draftMode()` in middleware/an edge runtime is not possible ## Why We do not expose `requestAsyncStorage` to the middleware adapter. Also, the prerender manifest wasn't available to the `EdgeRouteModuleWrapper` & middleware adapter, so it wasn't possible to enable/disable it. ## How This makes `requestAsyncStorage` available for middleware, and makes the preview mode data available from build to the edge runtime/middleware. Fixes #52557
19 lines
376 B
TypeScript
19 lines
376 B
TypeScript
import React from 'react'
|
|
import { draftMode } from 'next/headers'
|
|
|
|
export default function Page() {
|
|
const { isEnabled } = draftMode()
|
|
|
|
return (
|
|
<>
|
|
<h1>Draft Mode in Edge</h1>
|
|
<p>
|
|
Random: <em id="rand">{Math.random()}</em>
|
|
</p>
|
|
<p>
|
|
State: <strong id="mode">{isEnabled ? 'ENABLED' : 'DISABLED'}</strong>
|
|
</p>
|
|
</>
|
|
)
|
|
}
|