{"record":{"id":"c1676227d8ef7f8e","repo":"vercel/next.js","slug":"draft-mode-cannot-be-disabled-during-build-time-in","errorCode":null,"errorMessage":"Draft mode cannot be disabled during build-time instant validation.","messagePattern":"Draft mode cannot be disabled during build-time instant validation\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/app-render/instant-validation/instant-samples.ts","lineNumber":244,"sourceCode":"/**\n * Creates a DraftModeProvider that always returns isEnabled: false.\n */\nexport function createDraftModeForValidation(): DraftModeProvider {\n  // Create a minimal DraftModeProvider-compatible object\n  // that always reports draft mode as disabled.\n  //\n  // private properties that can't be set from outside the class.\n  return {\n    get isEnabled() {\n      return false\n    },\n    enable() {\n      throw new Error(\n        'Draft mode cannot be enabled during build-time instant validation.'\n      )\n    },\n    disable() {\n      throw new Error(\n        'Draft mode cannot be disabled during build-time instant validation.'\n      )\n    },\n  } as Partial<DraftModeProvider> as DraftModeProvider\n}\n\n/**\n * Creates params wrapped with an exhaustive proxy.\n * Accessing a param not declared in the sample will throw an error.\n */\nexport function createExhaustiveParamsProxy<TParams extends Params>(\n  underlyingParams: TParams,\n  declaredParamNames: Set<string>,\n  route: string\n): TParams {\n  return new Proxy(underlyingParams, {\n    get(target, prop, receiver) {\n      if (","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/app-render/instant-validation/instant-samples.ts#L226-L262","documentation":"The companion to error 151: the instant-validation DraftModeProvider.disable() stub throws because disabling draft mode is meaningless during build-time validation (draft mode is never enabled there). Any call to draftMode().disable() in code exercised by instant validation triggers it.","triggerScenarios":"During instant validation, application code calls draftMode().disable(). The validation provider's disable() throws.","commonSituations":"A 'disable preview' route handler or a component that clears draft mode is run during validation; shared cleanup code unconditionally disables draft mode; preview-exit logic invoked at build time.","solutions":["Guard draftMode().disable() so it does not run during build/validation.","Place draft-mode disable logic in a runtime-only route handler excluded from validation.","Condition the call on a real request context (e.g. presence of a query param).","Ensure the disable path is not reachable from statically-validated routes."],"exampleFix":"// before\n// export default function Handler() { draftMode().disable() }\n\n// after\n// if (process.env.NEXT_RUNTIME) draftMode().disable()","handlingStrategy":"validation","validationCode":"// Skip draft-mode disablement during build/validation.\nfunction disablePreview() {\n  if (process.env.NEXT_PHASE === 'phase-production-build') return\n  draftMode().disable()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep draftMode().disable() in runtime-only route handlers.","Exclude preview-exit routes from instant validation samples.","Guard draft-mode calls with a runtime/phase check.","Avoid calling draft APIs from statically validated components."],"tags":["instant-validation","draft-mode","build","validation"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}