Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft Mode isEnabled is always false on the Edge Runtime #52080

Closed
1 task done
alvarlagerlof opened this issue Jul 1, 2023 · 8 comments · Fixed by #67779
Closed
1 task done

Draft Mode isEnabled is always false on the Edge Runtime #52080

alvarlagerlof opened this issue Jul 1, 2023 · 8 comments · Fixed by #67779
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@alvarlagerlof
Copy link

alvarlagerlof commented Jul 1, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 15 02:15:40 UTC 2023
    Binaries:
      Node: 18.16.0
      npm: 8.11.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.8-canary.14
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/alvarlagerlof/next-js-draft-mode-repro

To Reproduce

Run the repro in dev or build.

  1. Click the link on / to enable draft mode.
  2. Go back to /
  3. Draft mode is not enabled

Describe the Bug

isEnabled from draftMode() always returns false with export const runtime = "edge"

Expected Behavior

isEnabled returns true after draftMode().enable() is ran,

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Seems to happen locally, in dev, build, and on Vercel

NEXT-1477

@alvarlagerlof alvarlagerlof added the bug Issue was opened via the bug report template. label Jul 1, 2023
@mattddean
Copy link
Contributor

mattddean commented Jul 8, 2023

It also seems like draft mode cannot be enabled from an edge Route Handler.

Navigating to /api/draft results in an error: "Error: Invariant: previewProps missing previewModeId this should never happen"

// /api/draft/route.ts
import { draftMode } from 'next/headers'

export const runtime = 'edge'

export async function GET() {
  draftMode().enable()
  return new Response('Draft mode is enabled')
}

Additionally, if export const runtime = 'edge' is configured on my root layout, I get the same "Error: Invariant: previewProps missing previewModeId this should never happen" error when navigating to /api/draft, whether or not /api/draft exports runtime = 'edge' itself. I'm not sure if the runtime constant is a valid layout configuration, but Next's TypeScript plugin seems to recognize that export on layout.tsx files.

@nickjackson
Copy link

There is a e2e test suite that suggests it should work, but I don't think any of those tests are actually testing pages with export const runtime = 'edge'.

The tests are just testing the standard node implementation.

@balazsorban44 balazsorban44 added Runtime Related to Node.js or Edge Runtime with Next.js. linear: next Confirmed issue that is tracked by the Next.js team. labels Jul 27, 2023
@DanielHirunrusme
Copy link

Any update on this? Experiencing this issue as well.

@dsbrianwebster
Copy link

Hoping this can make its way up the priority list for the next release. we sadly find ourselves having to opt-out of edge runtime on the majority of our projects/routes because of this issue.

@lightningspirit
Copy link

I ended up using request.cookies.has('__prerender_bypass') to test is draft mode is enabled. Temporary fix, not totally reliable for future upgrades.

@Multiply
Copy link

Multiply commented Feb 14, 2024

We're seeing either the same, or a similar issue when running in development.

In development mode, if no prerender manifest exists on the server instance it'll create a new one, which results in a new id for __prerender_bypass as expected.
However, the prerender manifest is stored on the server instance in memory, and is not shared with other server instances, such as the worker it starts up by defualt.

Maybe the prerender manifest should be written to disk in development-mode as well?

Edit: It's worth mentioning this only happened after upgrading from 13.x to 14.x. I don't know which version in between started "experimenting" with an IPC bridge, and workers, but that's definitely where it broke for us.

Edit 2: Another note to add, is that previously when an invalid __prerender_bypass was supplied, our server would simply just fail with a 5xx status code, now it simply removes the cookie silently.

@stephenmatthews
Copy link

stephenmatthews commented Apr 20, 2024

Is there an update on this? Upgraded to 14.2 and still having the same issue in development?

fraxachun added a commit to vivid-planet/comet that referenced this issue May 16, 2024
- Not necessary because the one cannot exist without the other
- Enables checking for previewParams in middleware (vercel/next.js#52080)
fraxachun added a commit to vivid-planet/comet that referenced this issue Jun 17, 2024
Required to allow checking for previewParams in middleware
(vercel/next.js#52080).

---------

Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
@huozhi huozhi closed this as completed in 1d9a78c Jul 15, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2024
lubieowoce pushed a commit that referenced this issue Aug 22, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 2, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 3, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 3, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 3, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 3, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
lubieowoce pushed a commit that referenced this issue Sep 3, 2024
Chnage the way of preview props injection to edge runtime, directly read
from env vars of preview props instead of writing to and reading from
prerender manifest.js

Previously we're trying to make these preview props values become
deterministic that we can replace in edge deployment pipeline in #64521

But the way of serializing process env vars in edge runtime is not
correct. They'll remain as string "process.env.xxx" in the manifest and
also after consumed. This PR fixes that behavior, instead of writing it
into manifest, alwyas consuming from process.env.var directly.

I created a shared util to access the preview props of edge runtime
across all the templates.

On draft provider side, we still need to handle dev mode case when
preview id is `development-id`, but we already have the cookie, it
cannot be aligned with the preview id. So we do a fallback check for dev
mode if the cookie is present and preview id is `development-id` then we
still treat it as draft mode is enabled.

Fixes #52080
Fixes #67075

Closes NEXT-3541
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants