From b92b6ac43242db00c0c2d6190a7636acf5c167e4 Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Tue, 17 Dec 2019 15:02:47 +0100 Subject: [PATCH] [base] Maintain order of documents when collating drafts/published (#1665) --- packages/@sanity/base/src/util/draftUtils.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/@sanity/base/src/util/draftUtils.js b/packages/@sanity/base/src/util/draftUtils.js index c2e22ee44d0..9ef734888ac 100644 --- a/packages/@sanity/base/src/util/draftUtils.js +++ b/packages/@sanity/base/src/util/draftUtils.js @@ -47,11 +47,17 @@ export function createPublishedFrom(document) { export function collate(documents) { const byId = documents.reduce((res, doc) => { const id = getPublishedId(doc._id) - const entry = res[id] || (res[id] = {id}) + let entry = res.get(id) + if (!entry) { + entry = {id} + res.set(id, entry) + } + entry[id === doc._id ? 'published' : 'draft'] = doc return res - }, Object.create(null)) - return Object.values(byId) + }, new Map()) + + return Array.from(byId.values()) } // Removes published documents that also has a draft