Merge pull request #16039 from storybookjs/fix/multiple-story-source-snippet

Addon-docs: Ensure we don't clobber multiple source container state updates
This commit is contained in:
Michael Shilman 2021-09-15 08:13:14 +08:00 committed by GitHub
commit 008867d787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,11 +21,14 @@ export const SourceContainer: FC<{}> = ({ children }) => {
useEffect(() => {
const handleSnippetRendered = (id: StoryId, newItem: SourceItem) => {
if (newItem !== sources[id]) {
const newSources = { ...sources, [id]: newItem };
setSources((current) => {
const newSources = { ...current, [id]: newItem };
if (!deepEqual(sources, newSources)) {
setSources(newSources);
}
if (!deepEqual(current, newSources)) {
return newSources;
}
return current;
});
}
};