Skip to content

Commit 5d327a0

Browse files
committed
Merge pull request #5551 from Automattic/update/design-preview-refresh
DesignPreview: Refresh iframe the second time the preview is accessed
2 parents 1fd86f5 + 6e87223 commit 5d327a0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

client/my-sites/design-preview/index.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getSelectedSite, getSelectedSiteId } from 'state/ui/selectors';
2222
const debug = debugFactory( 'calypso:design-preview' );
2323

2424
const DesignPreview = React.createClass( {
25+
previewCounter: 0,
2526

2627
propTypes: {
2728
// Any additional classNames to set on this wrapper
@@ -44,6 +45,12 @@ const DesignPreview = React.createClass( {
4445
selectedSiteId: React.PropTypes.number,
4546
},
4647

48+
getInitialState() {
49+
return {
50+
previewCount: 0
51+
};
52+
},
53+
4754
getDefaultProps() {
4855
return {
4956
showPreview: false,
@@ -56,6 +63,20 @@ const DesignPreview = React.createClass( {
5663
};
5764
},
5865

66+
componentWillReceiveProps( nextProps ) {
67+
if ( ! config.isEnabled( 'preview-endpoint' ) ) {
68+
if ( this.props.selectedSiteId && this.props.selectedSiteId !== nextProps.selectedSiteId ) {
69+
this.previewCounter = 0;
70+
}
71+
72+
if ( ! this.props.showPreview && nextProps.showPreview ) {
73+
debug( 'forcing refresh' );
74+
this.previewCounter > 0 && this.setState( { previewCount: this.previewCounter } );
75+
this.previewCounter += 1;
76+
}
77+
}
78+
},
79+
5980
componentDidMount() {
6081
this.loadPreview();
6182
},
@@ -159,7 +180,7 @@ const DesignPreview = React.createClass( {
159180
parsed.query['frame-nonce'] = site.options.frame_nonce;
160181
}
161182
delete parsed.search;
162-
return url.format( parsed );
183+
return url.format( parsed ) + '&' + this.state.previewCount;
163184
},
164185

165186
render() {

0 commit comments

Comments
 (0)