Skip to content

Workspace switcher tries iframe navigation instead of URL change in v4.12.0 #10995

@kimsintonowl

Description

@kimsintonowl

I added profiles to my sanity.config.ts file.

After adding profiles the profile switcher shows up. However if I try to switch profiles using the drop down profile switcher I get this console error.

chrome-error://chromewebdata/:1 Refused to display 'https://ss-web-prod.sanity.studio/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

However if I just switch the URL manually from:

https://www.sanity.io/@ofD9VF5ga/studio/bo4n46nda5nnix1zdkhtgwly/default/prod/structure

to

https://www.sanity.io/@ofD9VF5ga/studio/bo4n46nda5nnix1zdkhtgwly/default/dev/structure

then the profile loads fine. So it seems the profile switcher just needs to switch the url rather than loading a different iframe

my sanity.config.ts looks like this:

import {defineConfig} from 'sanity'
import {visionTool} from '@sanity/vision'
import {schema} from './sanity/schemas'
import {structure} from './sanity/structure'
import {deskTool} from 'sanity/desk'
import {simplerColorInput} from 'sanity-plugin-simpler-color-input'
import {table} from '@sanity/table'
import {deployButton} from './sanity/plugins/deployButton'
import {
  presentationTool,
  defineDocuments,
  defineLocations,
} from 'sanity/presentation'
import {Deploy} from './sanity/plugins/components/DeploymentButton/DeployButton'
import {RocketIcon, CodeIcon} from '@sanity/icons'

const projectId = process.env.SANITY_STUDIO_PROJECT_ID || ''
if (!projectId) {
  throw new Error('SANITY_STUDIO_PROJECT_ID environment variable is required')
}

// helper to build a workspace with all your shared plugins/settings
function makeWorkspace(
    name: 'prod' | 'dev',
    title: 'Production' | 'Development',
    dataset: 'production' | 'development',
    icon: typeof RocketIcon
) {
  return {
    name,
    title,
    basePath: `/${name}`,
    projectId: projectId as string,
    dataset: dataset as string,
    icon,
    plugins: [
      deskTool({ structure }),
      visionTool(),
      table(),
      simplerColorInput({
        defaultColorFormat: 'rgba',
        defaultColorList: [
          { label: 'Text Light', value: 'white' },
          { label: 'Text Dark', value: '#464646' },
          { label: 'Text Red', value: '#821517' },
          { label: 'Custom...', value: 'custom' },
        ],
        enableSearch: true,
      }),
      // Include presentationTool for both workspaces with same config
      presentationTool({
        previewUrl: {
          origin: 'https://sanity-visual-editing-rho.vercel.app/',
          previewMode: { enable: '/api/draft-mode/enable' },
        },
        resolve: {
          // Main Document Resolver API - resolves documents from routes
          mainDocuments: defineDocuments([
            { route: '/',                filter: `_type == "landingPage" && _id == "homepage"` },
            { route: '/landing/[slug]',  filter: `_type == "landingPage" && slug.current == $slug` },
            { route: '/[category]',      filter: `_type == "productCategory" && slug.current == $category` },
            { route: '/[category]/[product]', filter: `_type == "product" && slug.current == $product` },
          ]),
          // Locations Resolver API - defines where data is used in your application
          locations: {
            landingPage: defineLocations({
              select: { title: 'title', slug: 'slug.current', _id: '_id' },
              resolve: (doc) => ({
                locations: [
                  {
                    title: doc?.title || 'Homepage',
                    href: doc?._id === 'homepage' ? '/' : `/landing/${doc?.slug}`,
                  },
                ],
              }),
            }),
            productCategory: defineLocations({
              select: { title: 'title', slug: 'slug.current' },
              resolve: (doc) => ({
                locations: [{ title: doc?.title || 'Category', href: `/${doc?.slug}` }],
              }),
            }),
            product: defineLocations({
              select: { title: 'title', slug: 'slug.current', category: 'category->slug.current' },
              resolve: (doc) => ({
                locations: [{ title: doc?.title || 'Product', href: `/${doc?.category}/${doc?.slug}` }],
              }),
            }),
          },
        },
        allowOrigins: [
          'http://localhost:3000',
          'https://ss-web-virid.vercel.app',
          'http://localhost:3333',
          // Note: Removed ss-web-prod.sanity.studio from allowOrigins to prevent iframe navigation issues
          // The Studio URL shouldn't be in allowOrigins as it's not meant to be embedded
        ],
      }),
    ],
    tools: [Deploy()], // Re-enabled since it wasn't causing the issue
    schema,
  }
}

// Export workspaces - production first as it's the default
// Note: Workspace switcher requires proper basePath configuration and a fresh Studio deploy
export default defineConfig([
  makeWorkspace('prod', 'Production', 'production', RocketIcon),
  makeWorkspace('dev', 'Development', 'development', CodeIcon),
])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions