next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

Next site breaks if I'm logged in in Drupal, with preview mode active

Open violabg opened this issue 1 year ago • 14 comments

I have configured the preview site, everything is working, I'm able to see the Next site on the iframe in Drupal.

But if I login in Drupal I get a 500 error on the iframe, and if I try to open the Next site in a new window I get the same 500 error.

The problem is on the __next_preview_data cookie, if I remove it, I can see the Next site again.

This only happens if I'm loggedIn in Drupal

violabg avatar Apr 26 '23 08:04 violabg

this is my exit-preview.tsx

import { NextApiResponse } from "next";

export default function exit(_, response: NextApiResponse) {
  response.clearPreviewData();
  response.writeHead(307, { Location: "/" });
  response.end();
}

and preview.tsx

import { NextApiRequest } from "next";

import { drupal } from "@/lib/drupal";

export default async function handler(request: NextApiRequest, response: any) {
  return await drupal.preview(request, response);
}

violabg avatar Apr 26 '23 08:04 violabg

I've the same problem Next-Drupal 1.6 Next.js 13 drupal 9

thebetti avatar Apr 26 '23 09:04 thebetti

Same here, Internal Error 500 in the same situation

spad avatar Apr 27 '23 06:04 spad

I'm looking into this.

shadcn avatar Apr 27 '23 16:04 shadcn

Which version are you on for Next.js? 13.x.x?

shadcn avatar Apr 27 '23 16:04 shadcn

13.3.0 but the bug was present even on 12

violabg avatar Apr 27 '23 20:04 violabg

Which node version are you using ? Do you have some logs when the internal error is occuring ? I had the same errors, but it was with the password policy (password expired) on the Next.js user.

--

We're getting other 500's errors (502, 503, 504) here, on AWS ECS (.25 vCPU / 1GB Ram). The Next.js container is killed and an another container is up. But we've 0 (application) error or log, it's just turn off.

To display an 500 error, we're refreshing a content in preview mode, and a content in Next.js site (sometime, multiples time), and the container crashes.

Next.js v13.2.1 (same issue with Next.js 12.x version) Node.js v18.16 (same issue with Node 16.x version) Drupal 9.5 (same issue with Drupal 10)

@shadcn I'm UP if you need more information and/or test.

AlexandreBourdeaudhui avatar May 02 '23 09:05 AlexandreBourdeaudhui

v 16

VinsMediaX avatar May 02 '23 10:05 VinsMediaX

Hello, the preview mode seems to be deprecated, in favor of Draft Mode, on Next.js (https://nextjs.org/docs/pages/building-your-application/configuring/preview-mode). Maybe a clue?

AlexandreBourdeaudhui avatar May 05 '23 16:05 AlexandreBourdeaudhui

Mine has been fine until i updated to 13.4.1, oddly though I don't get the issue on my local version only when it's deployed

dottodot avatar May 06 '23 08:05 dottodot

Same issue here.

I have a Drupal backend https://admin.xxxx.xx I have a NextJS frontend https://xxxx.xx

As an administrator, If I preview the node /node/example, my preview is broken, I get a 500 error on the iframe. On the same browser, If I go to the NextJs app, on the page /node/example, my page is broken, I get a 500 error. On the NextJs app tab, if I delete the cookie "__prerender_bypass", my page is back to normal.

This issues happened as soon as we moved from http to https on both Drupal and NextJs sides.

This error never occurs when I'm not connected to Drupal (ie: the cookie doesn't exist).

EDIT: If I'm doing the same test locally, without HTTPS, everything is working.

Regards,

EDIT2: We finally made it. We added in the preview.ts file:

forceIframeSameSiteCookie: process.env.NODE_ENV === "development",

And removed in the src/pages/[...slug].tsx

	if (preview) {
		const previewBannerContainer = document.getElementById("preview-banner");
		const Test = () => <Alert color="error">You are in preview mode</Alert>;
		previewBannerContainer ? createPortal(<Test />, previewBannerContainer) : <></>;
	}

fabrer avatar May 25 '23 09:05 fabrer

Is there any update on this issue? If there's no immediate plans to fix it I'll attempt to do a PR if I get time.

dottodot avatar Jul 18 '23 07:07 dottodot

I am facing the same issue here. I am running multilanguage configuration and only main language is affected thought.

roundpanda avatar Aug 07 '23 15:08 roundpanda

I think this may have been an issue in nextjs, just installed the latest version and not getting the error anymore

dottodot avatar Aug 28 '23 08:08 dottodot