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

Unable to access drafts in Studio preview (Iframe) #1062

Open
3 tasks done
gduteaud opened this issue Sep 27, 2024 · 1 comment
Open
3 tasks done

Unable to access drafts in Studio preview (Iframe) #1062

gduteaud opened this issue Sep 27, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@gduteaud
Copy link

gduteaud commented Sep 27, 2024

Version

module: 1.12.1
nuxt: 3.12.4

Nuxt configuration

nuxt.config.ts

export default defineNuxtConfig({
...
sanity: {
    projectId: "[my actual project ID]",
    dataset: process.env.SANITY_DATASET,
    apiVersion: "2024-09-24",
    withCredentials: true,
  },
})

Reproduction

Steps to reproduce

Install Iframe Pane plugin in Sanity Studio

Sanity setup:

sanity.config.js

import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemaTypes'
import {defaultDocumentNode} from './src/defaultDocumentNode'

export default defineConfig([{
    name: 'developmentWorkspace',
    title: 'Solume (Development)',
    projectId: '[my actual project ID]',
    dataset: 'development',
    basePath: '/development',
    icon: Logo,
    plugins: [
      structureTool({
        defaultDocumentNode
      }),
      visionTool(),
    ],
    schema: {
      types: schemaTypes,
    },
  },
])

defaultDocumentNode.js

import {Iframe} from 'sanity-plugin-iframe-pane'
import { resolveBaseUrl } from './resolveBaseUrl'

export const defaultDocumentNode = (S, {schemaType}) => {
  switch (schemaType) {
    case `post`:
      return S.document().views([
        S.view.form(),
        S.view
          .component(Iframe)
          .options({
            url: (doc) => `${resolveBaseUrl()}/blog/${doc.slug.current}?preview=true`,
            reload: {
              button: true, // default `undefined`
            },
          })
          .title('Preview'),
      ])
    default:
      return S.document().views([S.view.form()])
  }
}

Note: resolveBaseUrl() just returns either my prod domain or localhost depending on the current environment.

Nuxt setup:

In addition to my config in the dedicated section above, here is a minimal reproduction of the specific page I'm previewing in Sanity Studio:

[slug].vue

<script setup>
const route = useRoute();
const slug = route.params.slug;

const query = groq`
*[_type == "post" && slug.current == $slug] | order(_updatedAt desc)[0]
`;

const { data: post } = await useSanityQuery(query, { slug });
console.log(post);
</script>

<template>
  <main>
        <h1>{{ post.articleTitle }}</h1>
        <p>By {{ post.author.name }}</p>
        <p>Published on: {{ formatDate(post.publishedAt) }}</p>
        <SanityContent :blocks="post.body" :serializers="serializers" />
  </main>
</template>

What is expected?

I would expect to see the latest draft of the post I'm previewing in my Sanity Studio preview iframe.

What is actually happening?

I can only see the latest published version.

Additional information

This seems to be a similar issue to 799 except I already have withCredentials set to true in my Nuxt config and yet I'm still not able to see drafts in my Sanity Studio iframe.

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet
@gduteaud gduteaud added the bug Something isn't working label Sep 27, 2024
@plcdnl
Copy link

plcdnl commented Oct 22, 2024

https://www.sanity.io/docs/perspectives

you should add the new option perspectives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants