Issue with data not loading in preview mode due to a syntax issue in the query.
21 replies
Last updated: Apr 29, 2021
S
I’m using a catch-all route
If I log out
[[…slug]].tsx, and inside that page I have :
const test = usePreviewSubscription(routeQuery, { params: { slug }, initialData: data, enabled: preview && slug, });
test, in preview mode, it’s called 4 times.. but the last time
test.datais null… anyone experienced the same thing?
Apr 12, 2021, 6:07 PM
There are some known instances where specific whitespaces in your query will cause the query to return nothing, when otherwise it would return something.
If you comment out the entire hook, does
If you comment out the entire hook, does
datahave data in it?
Apr 12, 2021, 6:11 PM
S
Yes, then I have data coming from
getStaticProps
Apr 12, 2021, 6:11 PM
S
I’ve seen other people mentioning white space in query, but as far as I can see there are no whitespace in the query
Apr 12, 2021, 6:13 PM
Was looking for examples but yeah it’s most often in resolving references I think like
[] ->needs to be
[]->
Apr 12, 2021, 6:13 PM
S
Yes, I think everything is in order otherwise.
Apr 12, 2021, 6:14 PM
S
I tried to simplify my query now, and it actually works..
Apr 12, 2021, 6:15 PM
S
Hm, allright.. then I atleast know somewhat where the issue is
Apr 12, 2021, 6:15 PM
S
Thanks for helping out 🙂
Apr 12, 2021, 6:16 PM
S
Thanks!
Apr 12, 2021, 6:17 PM
It’ll be a syntax issue in your query. It works server side but not in the preview client. Most common cause is additional trailing comma’s.
*[] { one: "one", two: "two", <-- this comma is a problem }
Apr 29, 2021, 1:09 PM
It’ll be a syntax issue in your query. It works server side but not in the preview client. Most common cause is additional trailing comma’s.
*[] { one: "one", two: "two", <-- this comma is a problem }
Apr 29, 2021, 1:09 PM
If you’re using
Strip out parts of your query line-by-line until the data loads as you expect – and you’ll find the offending line.
select()my current understanding is that one won’t work at all in the preview client.
Strip out parts of your query line-by-line until the data loads as you expect – and you’ll find the offending line.
Apr 29, 2021, 1:11 PM
ah, turns out it was my own fault... was querying for a specific slug, but didn't pass it onto the component, so it worked server side but not client side
Apr 29, 2021, 1:16 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.