Skip to content

Commit

Permalink
Merge pull request #20705 from storybookjs/>20626-fix-inconsistent-order
Browse files Browse the repository at this point in the history
Core: Fix issue with inconsistent CSF ordering in sandboxes
  • Loading branch information
tmeasday authored Jan 24, 2023
2 parents dc453c1 + 4eabf7e commit bcca0cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions code/lib/core-server/src/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class StoryIndexGenerator {

async initialize() {
// Find all matching paths for each specifier
await Promise.all(
const specifiersAndCaches = await Promise.all(
this.specifiers.map(async (specifier) => {
const pathToSubIndex = {} as SpecifierStoriesCache;

Expand All @@ -132,10 +132,16 @@ export class StoryIndexGenerator {
pathToSubIndex[absolutePath] = false;
});

this.specifierToCache.set(specifier, pathToSubIndex);
return [specifier, pathToSubIndex] as const;
})
);

// We do this in a second step to avoid timing issues with the Promise.all above -- to ensure
// the keys in the `specifierToCache` object are consistent with the order of specifiers.
specifiersAndCaches.forEach(([specifier, cache]) =>
this.specifierToCache.set(specifier, cache)
);

// Extract stories for each file
await this.ensureExtracted();
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ export const addStories: Task['run'] = async (

if (isCoreRenderer) {
const existingStories = await filterExistsInCodeDir(addonDirs, join('template', 'stories'));
await Promise.all(
existingStories.map(async (packageDir) => linkPackageStories(packageDir, { mainConfig, cwd }))
);
for (const packageDir of existingStories) {
await linkPackageStories(packageDir, { mainConfig, cwd });
}

// Add some extra settings (see above for what these do)
if (template.expected.builder === '@storybook/builder-webpack5') {
Expand Down

0 comments on commit bcca0cc

Please sign in to comment.