Skip to content

Commit

Permalink
fix(after): allow reading draftMode status in after
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Nov 28, 2024
1 parent 9e8822f commit 0de0eba
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/next/src/server/request/draft-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ export function draftMode(): Promise<DraftMode> {
const workUnitStore = workUnitAsyncStorage.getStore()

if (workUnitStore) {
if (workStore && workUnitStore.phase === 'after') {
throw new Error(
`Route ${workStore.route} used "draftMode" inside "unstable_after(...)". This is not supported, because "unstable_after(...)" runs after the request is finished and cannot affect the response. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/unstable_after`
)
}
if (
workUnitStore.type === 'cache' ||
workUnitStore.type === 'unstable-cache' ||
Expand Down Expand Up @@ -240,6 +235,10 @@ function trackDynamicDraftMode(expression: string) {
throw new Error(
`Route ${store.route} used "${expression}" inside a function cached with "unstable_cache(...)". The enabled status of draftMode can be read in caches but you must not enable or disable draftMode inside a cache. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache`
)
} else if (workUnitStore.phase === 'after') {
throw new Error(
`Route ${store.route} used "${expression}" inside \`unstable_after\`. The enabled status of draftMode can be read inside \`unstable_after\` but you cannot enable or disable draftMode. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_after`
)
}
}

Expand Down

0 comments on commit 0de0eba

Please sign in to comment.