Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/client/ui/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from '../';

const rootEl = document.getElementById('root');
const previousKind = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to make these as let. const variables cannot be re-assigned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @okonuskan
This should be a let right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats right. It's fixed now.

const previousStory = '';

export function renderError(data, error) {
// We always need to render redbox in the mainPage if we get an error.
Expand All @@ -26,11 +28,15 @@ export function renderMain(data) {
return ReactDOM.render(noPreview, rootEl);
}

// We need to unmount the existing set of components in the DOM node.
// Otherwise, React may not recrease instances for every story run.
// This could leads to issues like below:
// https://github.com/kadirahq/react-storybook/issues/81
ReactDOM.unmountComponentAtNode(rootEl);
if (selectedKind !== previousKind || previousStory !== selectedStory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment on why we do this and add the link to the related issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

// We need to unmount the existing set of components in the DOM node.
// Otherwise, React may not recrease instances for every story run.
// This could leads to issues like below:
// https://github.com/kadirahq/react-storybook/issues/81
previousKind = selectedKind;
previousStory = selectedStory;
ReactDOM.unmountComponentAtNode(rootEl);
}

return ReactDOM.render(story(), rootEl);
}
Expand Down