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

feat(stega): allow setting stega options on client.fetch #419

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Nov 27, 2023

Allows setting stega options on client.fetch, so it's easy to toggle. For example an Next.js App Router website might wish to setup everything in one place:

import {createClient} from '@sanity/client/stega'

const createClient({
  // ... other options
  stega: {
    studioUrl: 'https://my-project.sanity.studio',
    filter: props => {
      if(props.sourcePath.some((path) => path === 'metadata' || path === 'openGraph' || path === 'twitter')) {
        return false
      }
      return props.filterDefault(props)
    },
  },
})

And later toggle stega on or off based on if draftMode is true:

import { draftMode } from 'next/headers'

export default async ReactServerComponent() {
  const data = await client.fetch(query, params, {stega: {enabled: draftMode().isEnabled}})
  // You can pass a boolean as a shortcut for setting stega.enabled
  const data = await client.fetch(query, params, {stega: draftMode().isEnabled})
}

It's also useful to be able to enable the logger on specific requests:

import { draftMode } from 'next/headers'

export default async ReactServerComponent() {
  const data = await client.fetch(query, params, {
    stega: {
      logger: console,
    }
  })
}

@stipsan stipsan force-pushed the ECO-329/toggle-stega-on-fetch branch 3 times, most recently from 75d478b to fa6eb75 Compare November 27, 2023 15:28
@stipsan stipsan force-pushed the ECO-329/toggle-stega-on-fetch branch from fa6eb75 to 1efc6f5 Compare November 27, 2023 15:31
@stipsan stipsan marked this pull request as ready for review November 27, 2023 15:40
@stipsan stipsan merged commit d38afd8 into main Nov 28, 2023
12 checks passed
@stipsan stipsan deleted the ECO-329/toggle-stega-on-fetch branch November 28, 2023 14:56
@ecospark ecospark bot mentioned this pull request Nov 28, 2023
stipsan added a commit that referenced this pull request Nov 28, 2023
stipsan added a commit that referenced this pull request Nov 28, 2023
)

Revert "feat(stega): allow setting `stega` options on `client.fetch` (#419)"

This reverts commit d38afd8.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant