Bug with opening Sanity Studio in different windows/tabs after v3 upgrade
9 replies
Last updated: Feb 14, 2023
J
Hi awesome people!
Since upgrading to v3, I've got a bug where I can no longer open Sanity Studio in different windows/tabs. When opening a second tab, the other tab's instance of Sanity Studio crashes with an error
My initial guess is that the schema is being loaded twice in the same environment and thus the list of schema types/names are then duplicated.
Any help fixing this is greatly appreciated!
Since upgrading to v3, I've got a bug where I can no longer open Sanity Studio in different windows/tabs. When opening a second tab, the other tab's instance of Sanity Studio crashes with an error
Pane resolution error at index 0: List items with same ID found
My initial guess is that the schema is being loaded twice in the same environment and thus the list of schema types/names are then duplicated.
Any help fixing this is greatly appreciated!
Feb 14, 2023, 9:03 PM
R
What does the structure look like for the panes that cause this error?
Feb 14, 2023, 9:25 PM
J
I'm pretty sure the structure is breaking for the
Here's a section of my deskStructure.js:
Interactivespanes.
Here's a section of my deskStructure.js:
// deskStructure.js import interactives from './interactives' const interactiveUnitListItems = [] export default (S) => { for (const key in interactives) { const document = interactives[key].document let documentListItem = S.listItem().title(document.title).child(S.documentTypeList(document.name)) interactiveUnitListItems.push(documentListItem) } const interactiveUnitList = S.list().title('Interactive Units').items(interactiveUnitListItems) return S.list() .title('Main Menu') .items([ S.listItem().title('Course').child(S.documentTypeList('course')), S.listItem().title('Interactives').child(interactiveUnitList), S.listItem().title('Content Config').child(S.documentTypeList('config')), ]) }
Feb 14, 2023, 9:43 PM
J
I can now confirm that
So I think I need to find another way of creating a pane with its own array of list items.
S.listItem().title('Interactives').child(interactiveUnitList)is indeed creating the problem.
So I think I need to find another way of creating a pane with its own array of list items.
Feb 14, 2023, 9:51 PM
R
What does your
interactivesarray look like? It may be that youโre generating list items for both draft and published versions of documents.
Feb 14, 2023, 10:07 PM
J
I have a folder
schema/interactivesand we are importing this array from the `index.js`:
// schema/interactives/index.js import distortion_picker_quiz from './distortion_picker_quiz' import choice from './choice' import learn_more from './learn_more' import matching_game from './matching_game' import quiz from './quiz' import textbox from './textbox' import yes_no from './yes_no' import display_rich_text from './rich_text_display' export default { display_rich_text, distortion_picker_quiz, choice, learn_more, matching_game, quiz, textbox, yes_no, }
Feb 14, 2023, 10:13 PM
R
Can you try explicitly setting an
id()on each of your
documentListItems?
Feb 14, 2023, 10:18 PM
J
That worked!
I am setting the id with just a random string:
Thank you
I am setting the id with just a random string:
let documentListItem = S.listItem() .id(Math.random().toString()) .title(document.title) .child(S.documentTypeList(document.name))
user M
!!! ๐ ๐ ๐ ๐Feb 14, 2023, 10:28 PM
R
Awesome!!
Feb 14, 2023, 10:36 PM
J
Heya! I ended up digging a bit further and finally got to the root of the problem!
It turns out in the
The final solution is to move the array definition into the export block, which will reset on every render.
Fun times!
๐
It turns out in the
deskStructure.jsI was defining
const interactiveUnitListItems = []OUTSIDE of the export block. When a new tab opens, the previous tab's export gets re-rendered, and the export block tries to re-append additional items to the
interactiveUnitListItemsarray. Since it is outside the export block, its state has not changed, and thus duplicate list item builders are added to it.
The final solution is to move the array definition into the export block, which will reset on every render.
Fun times!
๐
Feb 14, 2023, 11:55 PM
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.