Questions tagged [sanity]
Sanity is a structured content platform and API that also offers an open source, React-based Studio that functions as like a headless CMS on top of the Sanity APIs.
813
questions
77
votes
1
answer
50k
views
Next.js: Reduce data fetching and share data between pages
I'm looking for solutions for better data fetching in a Next.js app. In this question I'm not just looking for a solution, I'm looking for multiple options so we can look at the pros and cons.
The ...
11
votes
10
answers
16k
views
Sanity.io [vite] Internal server error: [postcss] Cannot read properties of undefined (reading 'config') error
Spinning up the sanity studio gets me this error. The page spins up just fine in local host. Any help fixing this would be greatly appreciated
here is the error in full:
[plugin:vite:css] [postcss] ...
11
votes
3
answers
3k
views
Sanity Studio: Parsing Error for Babel Preset Env
I'm new to working with Sanity, and just set up a project. Everything is working fine, however, in Visual Studio Code, I keep getting a parsing error that won't disappear, and I'm wondering how I can ...
11
votes
3
answers
4k
views
Text/Image alignment in Sanity.io portable text rich text editor
Is there an option to align text (and also an image) to the center in sanity.io's rich text editor (Portable text)? Couldn't find anything in the docs
9
votes
2
answers
6k
views
Getting the "URLSearchParams.set is not implemented" error when trying to fetch data from my sanity backend using React Native
I am getting an error in my to react native project when pulling data from my sanity backend
this is the error
URLSearchParams.set is not implemented
This is where I am fetching he data
import {...
9
votes
1
answer
5k
views
How to upload multiple images to sanity.io?
I am searching for a way to uploading multiple images to sanity.io. Only thing that I found is this issue.
But maybe there is another way. Some npm-plugin or node.js app approach.
I'll be grateful ...
8
votes
4
answers
5k
views
The following files share their name; please adjust your hasteImpl: * <rootDir>\package.json * <rootDir>\sanity\package.json
This is my first time using sanity and I have encounter with this problem, When running expo start , I will be very thankful if you can help me with this
jest-haste-map: Haste module naming collision: ...
8
votes
1
answer
3k
views
How to fill arrays of references in a single query
I have a schema type Page which has an array of blocks:
{
title: 'Page',
name: 'page',
type: 'document',
fields: [
...
{
title: 'Blocks',
name: 'blocks',
type: '...
7
votes
2
answers
3k
views
Old records still showing on Sanity
I have created a Sanity.io CMS, I have made some alterations to the schema after content had already been entered. The problem now is that the content is still saved somewhere inside the cms and I ...
7
votes
1
answer
5k
views
How to create default value in field using sanity.io?
Is it possible to add to sanity field with default value? How can I extend it? I want to create some fields with default variables. For example I have this code:
export default {
name: 'name',
...
7
votes
1
answer
3k
views
Can't make search query work in Sanity CMS
I am trying to perform a very basic search query with Sanity CMS.
This is how the person schema I've created looks like:
export default {
title: "Person",
name: "person",
type: "document",
...
7
votes
2
answers
3k
views
Sanity and Nextjs: content is not updating until re-deploy
I am having an issue getting content from my production Sanity Studio onto my production blog. I am using Next.js v13 and Sanity v3. The site is deployed on Vercel.
When I post from both my local ...
6
votes
2
answers
9k
views
How to make sanity io array select as multiselect?
I have a lot of tags, and I need to select a lot for each document. It is uncomfortable to click one by one every time. Also I see selected elements. How can I remake it into somefield like a ...
6
votes
1
answer
2k
views
How do I make a inner join as a condition in GROQ?
I have a dataset with posts, which might have an array of categories.
How do I make a GROQ query that selects all posts with a category with the title "Page"?
I would think that I could do something ...
6
votes
2
answers
3k
views
Is there a way to get a structure of a Strapi CMS Content Type?
A content-type "Product" having the following fields:
string title
int qty
string description
double price
Is there an API endpoint to retrieve the structure or schema of the "Product&...
5
votes
4
answers
8k
views
How to retrieve a referenced field data inside inputComponent in Sanity.io?
In Sanity Studio, I was trying to get all Document's properties inside an input Component. Follow this article An officially supported way to get at the document content I was able to use withDocument ...
5
votes
1
answer
2k
views
How can I validate the dimensions of an uploaded image in Sanity?
I have an image type field in Sanity (docs) and I need to make sure that the dimensions are within a particular range to avoid breaking the website they're going on. Sanity offers validations, but the ...
5
votes
3
answers
2k
views
Error: No "sanity.json" file found in plugin "@sanity/base"
I am new to sanity and trying to follow along to a tutorial on youtube but I am getting this error when I run ' sanity start'. Can anyone give me advice on what I should do?
sanity error
5
votes
1
answer
2k
views
"sanity init" command fails at "Resolving dependencies" [closed]
I just wanted to create a new Sanity project. After running npm install -g @sanity/cli, which worked fine, I run sanity init. At the last step it crashed with the following warning:
Error Message From ...
5
votes
2
answers
2k
views
Resolve reference in Block Content in Sanity.io
I have the Content Block in Sanity like so:
export default {
title: "Block Content",
name: "blockContent",
type: "array",
of: [
/// stuff here
{
title: &...
5
votes
1
answer
2k
views
How to set value through patch event to any field from custom input in sanity.io?
I want to make patch event from custom component and set a value to another field in document, but couldn’t find documentation about patch events.
there are only example without field specification:
...
5
votes
2
answers
5k
views
next.js13 fetching data with an async function and also use state?
i hope you are having a great day ! i got a question... i'm currently learning next.js 13 and so i thought doing a personal project with it would be a good idea . Currently i'm doing an e-commmerce ...
5
votes
1
answer
3k
views
Ordering documents in Sanity
I have a set of documents and I want editors to be able to choose the order they appear. I haven't been able to find any information about this. Is there a standard or built-in way to handle this in ...
4
votes
2
answers
2k
views
How to create a default `creationDate` for a document in sanity.io?
I have checked the documentation of how to do this, but I have not found an answer.
Basically, when a document is created/published, I want to set a createdDate for the document (as a read-only/...
4
votes
1
answer
526
views
How to import custom CSS in Sanity Studio v3
I would like to make a small CSS modification in Sanity Studio V3.
The old method to import CSS no longer works.
How can I do it?
4
votes
1
answer
3k
views
WARN The default export of @sanity/client has been deprecated. Use the named export `createClient` instead
I'm currently learning React-Native. I try to use sanity in my project.
This is my sanity.js page. I could not get why sanityClient is strike-through.
I also get this error " WARN The default ...
4
votes
1
answer
7k
views
Why NextJS give me this hydrating error after refreshing the page?
When I refresh my page I got these erorrs :
Text content does not match server-rendered HTML.
Hydration failed because the initial UI does not match what was rendered on the server.
There was an ...
4
votes
4
answers
4k
views
Uncaught Error: Configuration must contain `projectId`( when using environment variable )
Only when using an environment variable for projectId inside sanityClient, it can't find it even though is inside the .env file
My goal is to connect backend data from Sanity to my frontend in ...
4
votes
5
answers
2k
views
How to increment property per document in Sanity?
We are making a system where users can submit orders. Orders have an incrementing property deliveryNumber; a new order should get a deliveryNumber that is one higher than the previous order.
Is there ...
4
votes
1
answer
3k
views
sanity.io - Adding color the text editor for the "block" type
I have an object of type block to get a WYSIWYG editor. It looks like this:
{
title: "Block",
type: "block",
styles: [
{ title: "Normal", value: "normal" },
{ title: "H1", value: "h1" }...
4
votes
4
answers
7k
views
Module not found: Can't resolve '@sanity/client' > 1 | import sanityClient from '@sanity/client';
I am using "npm install -g @sanity/cli
sanity init --coupon javascriptmastery2022" everything is workig well until I want to fetch the data from sanity client it says: ***Module not found: ...
4
votes
2
answers
2k
views
Querying images from Sanity for GatsbyImage
I'm having trouble sourcing images from Sanity using the new gatsby-plugin-image. The documentation says to do the following:
import React from 'react'
import {getGatsbyImageData} from 'gatsby-source-...
4
votes
1
answer
2k
views
Sanity draft preview not working with block content
I've made two iterations of a blog creation experience. The first consisted of an array of different object and document types such as paragraph, gallery, quote, etc while the second, and most recent ...
4
votes
1
answer
1k
views
Next.js - How to use getStaticProps to fetch Menu data and then pass it to the layout?
I am using Sanity.io as a backend, within Sanity I am handling the data for my main menu (parent/children object arrays).
Whilst I can fetch this data just fine, I want to do so via getStaticProps, as ...
4
votes
3
answers
6k
views
Sanity.io and Image from next/image issue
This is my first official post on Stack so bear with me; I am currently using Nextjs with Sanity as my headless CMS and I'm encountering what seems to be a TypeScript type issue. GH: https://github....
4
votes
0
answers
219
views
Getting fetch error when deploying Nextjs / TS app to Vercel
Im getting this error when I try to deploy an app using Nextjs / TS / Sanity to Vercel
18:39:44.458] Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/...
4
votes
1
answer
554
views
Vercel deployment: Error occurred prerendering page "/" TypeError: fetch failed
Yesterday I deployed my project (using Sanity.io) to Vercel and no issue.
Today I edited my code and want to deploy the new version with this commands:
vercel build
vercel deploy --prebuilt
vercel --...
3
votes
1
answer
2k
views
How to download file from Sanity via HTTP?
I would like to know if there is possibility to download file from Sanity with HTTP request?
I only have reference ID:
{
file: {
asset: {
_ref: "file-fxxxxxxxxxxxxxxxxxxxx-xlsx&...
3
votes
3
answers
2k
views
Cannot using React Syntax Highlighter in Next.js 13 & Sanity v3
Hello i have a problem for my project using Sanity v3 and React Syntax Highlighter. When i use Refactor library for showing my code in the browser it works by looking a tutorial in Code Input by ...
3
votes
1
answer
1k
views
How to define a tokenized tag field in Sanity?
I've seen people sport beautiful tokenized tag-fields in their Sanity studios. I don't think they are using a plug-in, so what's the incantation that will turn my homely array of strings into a ...
3
votes
2
answers
4k
views
How to get just the most recent of all documents
In sanity studio you get a nice list of the most recent version of all your documents. If there is a draft you get that, if not, you get the published one.
I need the same list for a few filters and ...
3
votes
1
answer
3k
views
Preview a reference
I want to preview a reference name in the studio
I have and icon type, for example one which has the title 'facebook'
export default {
name: 'icon',
title: 'Icon',
type: 'document',
fields: [
{
...
3
votes
1
answer
3k
views
How to import CSV to sanity.io
Im a hobby programmer exploring the free version of the new headless CMS sanity (www.sanity.io).
Bumping into a problem when trying to upload / import data into my project: Is there a way to import ...
3
votes
2
answers
1k
views
sanity start won't log me in
Did sanity upgrade -> npm install -> sanity init -> sanity start.
I was given localhost:3333 link. Was able to try either Google or Github when logging in but it just goes back to login ...
3
votes
8
answers
15k
views
Error when I try to execute 'sanity start' after success with 'sanity init'
I am trying to install the Sanity studio and I followed these steps:
npm install --global @sanity/cli
sanity install
sanity init
After the init step, I try to run the next step:
sanity start
but it ...
3
votes
2
answers
7k
views
Sanity.io GROQ query for array of objects
I'm learning to code and now I am on the stage of a small pet project with Sanity as a CMS.
Long story short, making an API I'm trying to fetch cocktails data with votes for the cocktails. The votes ...
3
votes
1
answer
4k
views
How do I query referenced document fields within an array of objects in Sanity with GROQ?
I have a document which has an array of objects of which one of the fields is a reference to another document. The following query returns the referenced document _id and _type only, and I need other ...
3
votes
1
answer
687
views
How to filter references based on change in another reference?
I have created an object with 3 reference fields - categories, subcategories, and types. I want the subcategories to show subcategories related to the selected category.
{
title: "Product ...
3
votes
1
answer
1k
views
How to deploy sanity studio in v3?
I'm getting started with sanity V3 and am using this official sanity starter https://www.sanity.io/templates/personal-website-with-built-in-content-editing
Maybe I'm missing the obvious but there are ...
3
votes
1
answer
839
views
Sanity IO CMS - What is the difference between sanity.config.js and sanity.json
Working with a Version 3 Sanity project to provide backend data.
However, I noticed that there are two files that deals with project settings/configurations.
PROJECT_DIR/sanity.config.js - included ...