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

Middleware causing data loss with with preview apis #76138

Open
jaandrews opened this issue Feb 18, 2025 · 0 comments
Open

Middleware causing data loss with with preview apis #76138

jaandrews opened this issue Feb 18, 2025 · 0 comments
Labels
Middleware Related to Next.js Middleware.

Comments

@jaandrews
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/muddy-sunset-nqqdr9

To Reproduce

I wasn't able to reproduce the issue in the sandbox, but it shows a simplified version of what I'm doing.

  1. Open a preview in a new window, since the nested preview window doesn't add the preview cookie somewhere it can read.
  2. Click "Enter Preview Mode" link to enter preview mode.
  3. Click "End Preview"

Current vs. Expected behavior

When the "End Preview" link is clicked it should turn off preview mode and redirect back to the page that was previewed (based on documentation here). Instead it throws an error in my local environment because the data object is undefined.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 32370
  Available CPU cores: 16
Binaries:
  Node: 20.10.0
  npm: 8.18.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.1.6 // There is a newer version (15.1.7) available, upgrade recommended! (I also tested this with 15.2.0-canary.64, but had the same results)
  eslint-config-next: 14.2.3
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.4.5
Next.js Config:
  output: standalone
 ⚠ There is a newer version (15.1.7) available, upgrade recommended!
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next dev (local), Vercel (Deployed)

Additional context

When I delete middleware.ts it works as expected, so it's definitely something about how the middleware functions that is causing it to fail. I did notice that the data was there at there when the getStaticProps retrieves the data after preview mode is exited. This data is lost somehow by the time the page is rendered though. I'm not making any changes in _app.tsx to how the props are passed along. I am just passing the pageProps to the Component element.

@github-actions github-actions bot added the Middleware Related to Next.js Middleware. label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Middleware Related to Next.js Middleware.
Projects
None yet
Development

No branches or pull requests

1 participant