Skip to content

Commit

Permalink
Ensure we don't clobber multiple source container state updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Sep 14, 2021
1 parent a308946 commit dd0821c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions addons/docs/src/blocks/SourceContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

if (!deepEqual(sources, newSources)) {
setSources(newSources);
}
setSources((current) => {
const newSources = { ...current, [id]: newItem };

if (!deepEqual(current, newSources)) {
return newSources;
}
return current;
});
}
};

Expand Down

0 comments on commit dd0821c

Please sign in to comment.