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

Latest version displayed when viewing revisions and in draft content

Open Tweemo opened this issue 2 years ago • 4 comments

There are 2 separate but very similar issues that we are getting.

  1. When we try to view any revision of content, in the preview iFrame it shows the latest version.

Expected behaviour: when we view a revision, the preview iFrame would display the revision.

  1. When we are in the 'View' tab of draft content, the preview iFrame below shows the latest content instead of the draft content.

Expected behaviour: when in the 'View' tab of draft content the preview iFrame would show the draft content. 'Latest revision' tab currently shows the latest version so there are no issues there.

When viewing content revisions or draft content the iFrame source seems to be correct but when we try to access the link, it redirects us to the latest version on the front-end. The assumption here is that because on the front-end, the non-admin side, the revision or the draft doesn't exist/isn't visible to users so it redirects us to the current published version. Screenshot 2023-04-24 at 10 26 01 AM

A potential option we thought about was for the iFrame source to not be linked to the front-end as it will never have revisions or draft content available to view, but we weren't sure how we would go about creating the preview another way.

Tweemo avatar Apr 23 '23 22:04 Tweemo

Can you help me reproduce this? I assume this is a node type with revision enabled? Anything else?

shadcn avatar May 01 '23 07:05 shadcn

Yep sure thing.

Steps to reproduce:

  1. Create new content with any content type i.e Article and publish it.
  2. Edit the content and change it into draft state.

At this point, when you go into the 'View' tab, the preview iFrame will show the most recent published version instead of the content that is in the draft state. On the same content, if you go into the 'Revisions' tab and try to view any previous revisions, the preview iFrame still only shows the latest published content. This happens to revisions in any state, published and draft.

I have attached this loom as well to show the steps. https://www.loom.com/share/9b163f1a674d4a5e8e44702f81fe3d78

Tweemo avatar May 01 '23 20:05 Tweemo

This issue is still evident and relevant in latest version.

apmsooner avatar Dec 05 '23 05:12 apmsooner

From what I understood there is some preview logic that after validation it redirects to the slug to retrieve the content dynamically from the catch all route. But nothing about the revision is taken into account, so it just loads the latest revision.

The redirect with preview data: https://github.com/chapter-three/next-drupal/blob/main/packages/next-drupal/src/next-drupal-pages.ts#L403

Example request on the catch all route: https://github.com/chapter-three/next-drupal/blob/main/examples/example-blog/pages/%5B...slug%5D.tsx#L74-L76

After some more investigation I noticed the cookie which populates the context with the revision data was not being loaded from the iframe. The good news is the code has a fix if you pass the param forceIframeSameSiteCookie as true in your drupal client.

Maybe this will also solve your issue.

xavierbarbosa avatar Jun 04 '24 22:06 xavierbarbosa