sanity icon indicating copy to clipboard operation
sanity copied to clipboard

Cannot reorder items in array after publish

Open torstah opened this issue 2 years ago • 16 comments

Items in array are not draggable after either restoring to an older version or sometimes after publish

To Reproduce

Steps to reproduce the behavior:

  1. Create a fresh project using npm create sanity@latest -- --template clean --create-project "Sanity Project" --dataset production
  2. Add this simple schema
import { defineField, defineType, defineArrayMember } from 'sanity'

export default defineType({
  name: 'post',
  title: 'Post',
  type: 'document',
  fields: [
    defineField({
      name: 'title',
      title: 'Title',
      type: 'string',
    }),
    {
      name: "tags",
      type: "array",
      title: "Tags for item",
      of: [{
        type: 'item',
        name: 'tag',
       
      }]
    },
  
  ],
  preview: {
    select: {
      title: 'title',
   
    },

  },
})
  1. Edit things and refresh, sometimes the array sorting just stops working.
  2. Seems like the app is re-rendering and I get this error: ArrayOfObjectsField.tsx:248 Neither the item you are moving nor the item you are moving to have a key. Cannot continue.

Expected behavior

Sorting should be possible

Screenshots Here is a video:

https://github.com/sanity-io/sanity/assets/296355/18d5ea62-6d3c-4c56-9d6c-ff97ae0a938c

Which versions of Sanity are you using?

@sanity/cli (global) 3.15.1 (latest: 3.20.0) @sanity/eslint-config-studio 3.0.1 (up to date) @sanity/vision 3.20.0 (up to date) sanity 3.20.0 (up to date)

What operating system are you using?

MacOS Sonoma, Macbook pro M1

Which versions of Node.js / npm are you running?

Run npm -v && node -v in the terminal and copy-paste the result here.

8.15.0 v16.17.0

I have also created this https://codesandbox.io/p/sandbox/clever-einstein-r696v9, but cannot reproduce the issue there. But happens consistently on my local machine, I'm going crazy!!

Sometimes I get this error before this happens:

react-dom.development.js:86 Warning: React does not recognize the withTooltipprop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercasewithtooltip instead. If you accidentally passed it from a parent component, remove it from the DOM element....

torstah avatar Nov 17 '23 13:11 torstah

Also adding that i have tried this exact setup in a Chrome Incognito window, so without any extensions activated and a clean cache. Same bug...

torstah avatar Nov 20 '23 10:11 torstah

Any news on this? Could anyone reproduce? Thanks

torstah avatar Nov 30 '23 12:11 torstah

Any news on this? Could anyone reproduce? Thanks

torstah avatar Nov 30 '23 12:11 torstah

I got the same problem with the reordering and it's strange this isn't getting any attention since at least I have had this issue since v3.17 up to the latest 3.20.2 I also had a conversation with a Sanity representative here that is about losing scroll on lists inside of dialogs after editing. I need to make a full page refresh after each edit and that goes for the reordering as well. To me, these problems seem to have the same cause. Unfortunately, I haven't gotten any reply in four days, which is strange as this bug makes the studio very hard to use.

HumidBrains avatar Dec 01 '23 09:12 HumidBrains

Having trouble reproducing this - what does the item type look like?

rexxars avatar Dec 05 '23 02:12 rexxars

Item type could be what ever, same issue. For me anyways. Please review the video i posted above. Again the error message is: ArrayOfObjectsField.tsx:248 Neither the item you are moving nor the item you are moving to have a key. Cannot continue

torstah avatar Dec 06 '23 10:12 torstah

Any news on this. Very frustrating having to change back and forth between documents to get sorting working again in the structure app. @rexxars

torstah avatar Dec 11 '23 14:12 torstah

@rexxars I've updated to 3.21.3 and still have the same problem. We're about to start building sites for clients with Sanity but if the UI is ignored to this extent it won't be possible to release the product to customers. That also goes for the modals that stop scrolling (when needed) after field edit and/or publish. This has been going on for a long time, and I cannot wrap my head around why such important bugs don't get prioritized.

HumidBrains avatar Dec 13 '23 14:12 HumidBrains

@rexxars I'm happy to let you into a studio with this problem for you to have a look.

HumidBrains avatar Dec 13 '23 14:12 HumidBrains

@rexxars yes, happy to the same.

torstah avatar Dec 14 '23 14:12 torstah

I also noticed this bug ~4 Months ago, hope that it gets fixed soon... whenever I reorder some sections in my pagebuilder array it needs a reload or document change to proceed working. Very frustrating...

salex97 avatar Dec 14 '23 21:12 salex97

Experienced this right now, Sanity version 3.21.3

marcinincreo avatar Dec 19 '23 17:12 marcinincreo

@rexxars I just upgraded to the latest 3.23.2. The new UI looks a lot better, but the bug remains. It's about time to give this issue some love.

HumidBrains avatar Dec 22 '23 12:12 HumidBrains

@rexxars Yes would really appreciate a solve for this.

torstah avatar Jan 08 '24 08:01 torstah

@rexxars this problem remains in version 3.25.0. Please show some interest in fixing this bug. Thanks.

HumidBrains avatar Jan 23 '24 09:01 HumidBrains

For anyone looking at this in the future: This happens after the document has a syncing state, when the read-only components go back to the normal ones. This might actually be an issue with the dnd library as I'm not finding any issues.

function restrictToAxis(axis: Axis) {
  return axis === 'x' ? restrictToHorizontalAxis : restrictToVerticalAxis
}
function sortingStrategy(axis: Axis) {
  return axis === 'x' ? horizontalListSortingStrategy : verticalListSortingStrategy
}

const SortableList = memo(function SortableList(props: ListProps) {
  const {items, axis, onItemMove, onItemMoveStart, onItemMoveEnd, children, ...rest} = props

  const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, SENSOR_OPTIONS))

  const handleDragEnd = useCallback(
    (event: DragEndEvent) => {
      const {active, over} = event

      if (active.id !== over?.id) {
        onItemMove?.({
          fromIndex: active.data.current?.sortable?.index,
          toIndex: over?.data.current?.sortable?.index,
        })
      }

      onItemMoveEnd?.()
    },
    [onItemMove, onItemMoveEnd],
  )
  const modifiers = useMemo(
    () => [restrictToParentElementWithMargins({y: 4}), ...(axis ? [restrictToAxis(axis)] : [])],
    [axis],
  )

  return (
    <DndContext
      sensors={sensors}
      autoScroll={AUTO_SCROLL_OPTIONS}
      modifiers={modifiers}
      collisionDetection={closestCenter}
      onDragEnd={handleDragEnd}
      onDragStart={onItemMoveStart}
    >
      <SortableContext items={items} strategy={axis ? sortingStrategy(axis) : undefined}>
        <Grid {...rest}>{children}</Grid>
      </SortableContext>
    </DndContext>
  )
})

Tried removing the modifiers but that didn't work, same with the strategory on SortableContext

largis21 avatar Feb 05 '24 08:02 largis21

We have the same issue on version 3.30.0

alexandereneroth avatar Feb 28 '24 09:02 alexandereneroth

I encountered the same issue. Every time I reorder my PageBuilder Components (Sanity Array) and publish, I am not able to reorder again and have to reload. Very frustrating and now the second project with this issue.

Currently I work with 3.25.0 but had the same problem in previous versions as well.

joulzMorguet avatar Mar 26 '24 19:03 joulzMorguet

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Jul 08 '24 00:07 github-actions[bot]