Discussion of unexpected behavior in Sanity v2.13.1 vs v2.7.4, fixed in 2.14.0
16 replies
Last updated: Aug 16, 2021
M
I’ve found an unexpected change in behaviour in Sanity v2.13.1 vs v2.7.4 (it’s been a while since I’ve upgraded).
I have a preview for an object type used in portable text that has a array of strings field. In the old version I could “select” this array and get the whole array of strings to use in “prepare”. In the new version the value passed to prepare is always undefined.
My preview code looks like this:
I have a preview for an object type used in portable text that has a array of strings field. In the old version I could “select” this array and get the whole array of strings to use in “prepare”. In the new version the value passed to prepare is always undefined.
My preview code looks like this:
preview: {
select: {
name: 'name',
editors: 'editors',
},
prepare(selection) {
const { name, editors } = selection;
const editorsText =
!editors || editors.length === 0
? '(no editors selected)'
: editors.map((e) => programmingLanguageTitleForValue(e)).join(', ');
return {`title:
${name || 'Untitled'} code for ${editorsText},
};`
},
},
Jul 21, 2021, 2:45 PM
M
Found another case where it’s easier for me to include the whole type to illustrate ^
Jul 21, 2021, 2:57 PM
M
This one now errors in the studio because
platformsis undefined in prepare.
Jul 21, 2021, 2:58 PM
M
I’ve fixed these with the
select: { platforms0: "platforms.0" }etc. approach.
Jul 21, 2021, 3:32 PM
M
I’d still like to know whether this is an expected change in behaviour. I think I was quite lucky to catch it when testing the upgrade.
Jul 23, 2021, 8:27 AM
M
Thank you
user H
🎉Jul 23, 2021, 11:48 AM
M
user J
In my case there were only 4 possible values in the list so I could get away with this:preview: { select: { platform0: 'platforms.0', platform1: 'platforms.1', platform2: 'platforms.2', platform3: 'platforms.3', }, prepare({ platform0, platform1, platform2, platform3 }) { const platforms = [platform0, platform1, platform2, platform3].filter( Boolean ); return { title: `Content for ${platforms.join(', ')}`, }; }, },
https://www.sanity.io/docs/previews-list-views#dbe115bb1388
Seems likely it’ll be fixed soon though.
Jul 23, 2021, 8:20 PM
user H
any updates on when this PR will get merged? Going on a week of busted previews for clients 😬Jul 29, 2021, 7:50 PM
D
I’m seeing a similar issue, but instead of an array of strings, I have a string with an array of options. When selecting this field, it comes through as undefined in prepare. If I remove the ‘options’ block for my string field, the value shows up. Also using 2.13.1
Aug 3, 2021, 7:00 PM
D
So, common thread is not the array of objects, but the array of options for the string field.
Aug 3, 2021, 7:04 PM
D
This is fixed for me in the conditional-fields build that was released today!(
https://sanity-io-land.slack.com/archives/CB4MVT2AE/p1627985808004500
2.13.2-conditional-fields.29)
https://sanity-io-land.slack.com/archives/CB4MVT2AE/p1627985808004500
Aug 3, 2021, 7:10 PM
D
This is fixed for me in the conditional-fields build that was released today.(
https://sanity-io-land.slack.com/archives/CB4MVT2AE/p1627985808004500
2.13.2-conditional-fields.29)
https://sanity-io-land.slack.com/archives/CB4MVT2AE/p1627985808004500
Aug 3, 2021, 7:10 PM
would really love to see this addressed in an official release, still haven’t seen any version upgrades available in the CLI
Aug 5, 2021, 6:06 PM
would really love to see this addressed in an official release, still haven’t seen any version upgrades available in the CLI
Aug 5, 2021, 6:06 PM
Hi! This should be fixed in 2.14.0 that was released last week. Let me know if you’re still having problems 🙂
Aug 16, 2021, 7:14 AM
Sanity– build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.