From ee614e806a0b08e6d2ffc53b9ae326a9427ef887 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Tue, 12 Nov 2019 10:33:15 +1100 Subject: [PATCH] Use the `stable` package to ensure story sorting is stable. Fixes #8792 --- lib/client-api/package.json | 1 + lib/client-api/src/story_store.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/client-api/package.json b/lib/client-api/package.json index 255bebc0430c..a4f7d5014abd 100644 --- a/lib/client-api/package.json +++ b/lib/client-api/package.json @@ -40,6 +40,7 @@ "lodash": "^4.17.15", "memoizerific": "^1.11.3", "qs": "^6.6.0", + "stable": "^0.1.8", "ts-dedent": "^1.1.0", "util-deprecate": "^1.0.2" }, diff --git a/lib/client-api/src/story_store.ts b/lib/client-api/src/story_store.ts index cc0633db47fb..9fe704f5bdc4 100644 --- a/lib/client-api/src/story_store.ts +++ b/lib/client-api/src/story_store.ts @@ -3,6 +3,7 @@ import EventEmitter from 'eventemitter3'; import memoize from 'memoizerific'; import debounce from 'lodash/debounce'; import dedent from 'ts-dedent'; +import stable from 'stable'; import { Channel } from '@storybook/channels'; import Events from '@storybook/core-events'; @@ -129,7 +130,7 @@ export default class StoryStore extends EventEmitter { ); if (index && this._data[index].parameters.options.storySort) { const sortFn = this._data[index].parameters.options.storySort; - stories.sort(sortFn); + stable.inplace(stories, sortFn); } } // removes function values from all stories so they are safe to transport over the channel