@@ -30,9 +30,23 @@ class InstructorsEdit extends Component {
3030
3131 this . state = {
3232 instructors : this . props . instructors ,
33+ // Used to force a remount of <ServerSideRender /> after a save finishes.
34+ ssrNonce : 0 ,
3335 } ;
3436 }
3537
38+ /**
39+ * When a save transitions from "saving" -> "not saving", bump the nonce
40+ * so the SSR component remounts and refetches fresh HTML.
41+ *
42+ * @param {Object } prevProps
43+ */
44+ componentDidUpdate ( prevProps ) {
45+ if ( prevProps . isSavingPost && ! this . props . isSavingPost ) {
46+ this . setState ( { ssrNonce : Date . now ( ) } ) ;
47+ }
48+ }
49+
3650 /**
3751 * Render component
3852 *
@@ -42,15 +56,15 @@ class InstructorsEdit extends Component {
4256 */
4357 render = ( ) => {
4458 const { name, attributes, post_id } = this . props ; // eslint-disable-line camelcase
59+ const { ssrNonce } = this . state ;
4560
4661 return (
4762 < Fragment >
4863 < ServerSideRender
64+ key = { ssrNonce } // remount -> refetch on save complete
4965 block = { name }
5066 attributes = { attributes }
51- urlQueryArgs = { {
52- post_id,
53- } }
67+ urlQueryArgs = { { post_id } }
5468 />
5569 </ Fragment >
5670 ) ;
@@ -66,12 +80,13 @@ class InstructorsEdit extends Component {
6680 */
6781export default compose ( [
6882 withSelect ( ( select ) => {
69- const { getEditedPostAttribute, getCurrentPostId } = select (
70- 'core/editor'
71- ) ;
83+ const { getEditedPostAttribute, getCurrentPostId, isSavingPost } =
84+ select ( 'core/editor' ) ;
85+
7286 return {
7387 post_id : getCurrentPostId ( ) ,
7488 instructors : getEditedPostAttribute ( 'instructors' ) ,
89+ isSavingPost : isSavingPost ( ) ,
7590 } ;
7691 } ) ,
7792] ) ( InstructorsEdit ) ;
0 commit comments