🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Query issue with Next JS App Router after updating Sanity version.

22 replies
Last updated: May 15, 2024
Hey everybody!
I have a query that works perfectly fine in Vison inside of Studio. However, the
global
query returns
null
inside my application (Next JS App Router). Any idea why this might be?
This query worked when I was using sanity
3.36.0
, I've recently updated to `3.41.1`and it is now broken.
May 14, 2024, 4:15 PM
Is that data published? If not, it would make sense as Vision is using the raw perspective, which includes drafts. Drafts won’t be included in an application unless you’re using a token in your client configuration.
May 14, 2024, 5:07 PM
user M
Yes, it's published.
May 14, 2024, 9:44 PM
What version of the API are you using in your app?
May 14, 2024, 10:28 PM
I have it set to this:
v2024-01-30
May 15, 2024, 3:40 PM
user M
Which, if I set it to that in Vision, it still works
May 15, 2024, 3:40 PM
It really sounds like the
settings.socialProof
document that you’re getting in your
global
projection isn’t published. If you fetch the
_id
of the document in Vision what does it look like?
May 15, 2024, 4:40 PM
user M
This is what i'm seeing in Vision. API Version set to what I mentioned above and perspective set to published
May 15, 2024, 6:35 PM
I can’t see the
_id
in that result. Can you just fetch that?
May 15, 2024, 6:37 PM
OK, I see it now. you have a
.
in your
_id
. That puts it on a non-root path and requires an authenticated request outside of the Studio. That happens by default in Vison.
May 15, 2024, 6:46 PM
Ah, interesting. Is there a way around this besides removing the
.
? I also use that naming convention with other doc types (body.textBanner), those seem to work
May 15, 2024, 6:52 PM
It’s fine for there to be a dot in the name of the schema. That’ll still show up publicly. If it’s in the
_id
it’s always going to need to be queried with a token.
May 15, 2024, 7:01 PM
Gotcha. How did that get in the
_id
?
May 15, 2024, 7:03 PM
Is it a singleton? That would have happened if you set it up as one in your structure.
May 15, 2024, 7:04 PM
Ok. Now it's making sense. Yes, it is a singleton.
May 15, 2024, 7:04 PM
That was it then!
May 15, 2024, 7:05 PM
Thanks for the help! I appreciate it.
May 15, 2024, 7:05 PM
Happy to! Glad we got it sorted.
May 15, 2024, 7:05 PM
I must be missing something: How would I go about changing it to a non-singleton?
May 15, 2024, 7:25 PM
Are you trying to change the id or have it not appear in your structure as a singleton?
May 15, 2024, 7:47 PM
Both? I don't need it as a singleton and need to remove the
.
so I can query outside of Vision without token
May 15, 2024, 7:50 PM
Ok, so document
_ids
are immutable, so you can use this method to change it or you can write a script that uses the JS client to create a duplicate version of the existing singleton with a different
_id
then delete the old one. To get it out of your structure, you’ll need to go to the file that you’re defining it in and remove it from the code you’ve written.
May 15, 2024, 8:39 PM
Really appreciate the help here!
May 15, 2024, 11:43 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?