Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely avoid re-rendering the preview iframe #631

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Changes from all commits
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
31 changes: 23 additions & 8 deletions src/client/manager/preview.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { Component } from 'react';

const iframeStyle = {
width: '100%',
Expand All @@ -8,13 +8,28 @@ const iframeStyle = {
padding: 0,
};

const Preview = ({ url }) => (
<iframe
id="storybook-preview-iframe"
style={iframeStyle}
src={url}
/>
);
class Preview extends Component {
/* eslint-disable class-methods-use-this */
shouldComponentUpdate() {
// When the manager is re-rendered, due to changes in the layout (going full screen / changing
// addon panel to right) Preview section will update. If its re-rendered the whole html page
// inside the html is re-rendered making the story to re-mount.
// We dont have to re-render this component for any reason since changes are communicated to
// story using the channel and necessary changes are done by it.
return false;
}
/* eslint-enable class-methods-use-this */

render() {
return (
<iframe
id="storybook-preview-iframe"
style={iframeStyle}
src={this.props.url}
/>
);
}
}

Preview.propTypes = {
url: React.PropTypes.string,
Expand Down