@@ -128,21 +128,25 @@ function sendOnSocket(request) {
128
128
* @param {Object } api Api object.
129
129
* @returns {Promise } Action promise.
130
130
*/
131
+ let isHydrating = __CLIENT__ ? true : false ;
132
+
131
133
const apiMiddlewareFactory =
132
134
( api ) =>
133
135
( { dispatch, getState } ) =>
134
136
( next ) =>
135
137
( action ) => {
136
138
const { settings } = config ;
137
139
138
- const token = getState ( ) . userSession . token ;
139
- let uploadedFiles = getState ( ) . content . uploadedFiles ;
140
+ const state = getState ( ) ;
141
+ const token = state . userSession . token ;
142
+ let uploadedFiles = state . content . uploadedFiles ;
140
143
let isAnonymous = true ;
141
144
if ( token ) {
142
145
const tokenExpiration = jwtDecode ( token ) . exp ;
143
146
const currentTime = new Date ( ) . getTime ( ) / 1000 ;
144
147
isAnonymous = ! token || currentTime > tokenExpiration ;
145
148
}
149
+ const hasExistingError = state . content . get ?. error ;
146
150
147
151
if ( typeof action === 'function' ) {
148
152
return action ( dispatch , getState ) ;
@@ -223,6 +227,7 @@ const apiMiddlewareFactory =
223
227
} ) ;
224
228
actionPromise . then (
225
229
( result ) => {
230
+ isHydrating = false ;
226
231
if ( uploadedFiles !== 0 ) {
227
232
dispatch ( updateUploadedFiles ( 0 ) ) ;
228
233
}
@@ -298,6 +303,14 @@ const apiMiddlewareFactory =
298
303
}
299
304
} ,
300
305
( error ) => {
306
+ // Make sure an error during hydration
307
+ // (for example when serving an archived page)
308
+ // doesn't hide the SSR content.
309
+ if ( isHydrating && ! hasExistingError ) {
310
+ isHydrating = false ;
311
+ return ;
312
+ }
313
+
301
314
// Only SSR can set ECONNREFUSED
302
315
if ( error . code === 'ECONNREFUSED' ) {
303
316
next ( {
0 commit comments