Skip to content

Commit ceebfc5

Browse files
roonyharunoda
authored andcommitted
Completely avoid re-rendering the preview iframe (#631)
When manager re-rendered there is a chance that this component is rerendered. That makes the iframe to load again. So the complete story is remounted. This is not preferred except when changing stories.
1 parent b0a6f9e commit ceebfc5

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

src/client/manager/preview.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
22

33
const iframeStyle = {
44
width: '100%',
@@ -8,13 +8,28 @@ const iframeStyle = {
88
padding: 0,
99
};
1010

11-
const Preview = ({ url }) => (
12-
<iframe
13-
id="storybook-preview-iframe"
14-
style={iframeStyle}
15-
src={url}
16-
/>
17-
);
11+
class Preview extends Component {
12+
/* eslint-disable class-methods-use-this */
13+
shouldComponentUpdate() {
14+
// When the manager is re-rendered, due to changes in the layout (going full screen / changing
15+
// addon panel to right) Preview section will update. If its re-rendered the whole html page
16+
// inside the html is re-rendered making the story to re-mount.
17+
// We dont have to re-render this component for any reason since changes are communicated to
18+
// story using the channel and necessary changes are done by it.
19+
return false;
20+
}
21+
/* eslint-enable class-methods-use-this */
22+
23+
render() {
24+
return (
25+
<iframe
26+
id="storybook-preview-iframe"
27+
style={iframeStyle}
28+
src={this.props.url}
29+
/>
30+
);
31+
}
32+
}
1833

1934
Preview.propTypes = {
2035
url: React.PropTypes.string,

0 commit comments

Comments
 (0)