Skip to content

Commit 49212c7

Browse files
committed
fix(next-drupal): optimize draft data fetching to support SSG
Resolved dynamic server error by checking draft mode before accessing cookies. This maintains SSG while still allowing draft mode when needed. Fixes #852
1 parent c1a9054 commit 49212c7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/next-drupal/src/draft.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ export interface DraftData {
7272

7373
export async function getDraftData() {
7474
let data: DraftData = {}
75-
const cookieStore = await cookies()
75+
7676
const draft = await draftMode()
77-
if (draft.isEnabled && cookieStore.has(DRAFT_DATA_COOKIE_NAME)) {
77+
if (!draft.isEnabled) {
78+
return data
79+
}
80+
81+
const cookieStore = await cookies()
82+
if (cookieStore.has(DRAFT_DATA_COOKIE_NAME)) {
7883
data = JSON.parse(cookieStore.get(DRAFT_DATA_COOKIE_NAME)?.value || "{}")
7984
}
8085

0 commit comments

Comments
 (0)