@@ -137,7 +137,7 @@ import { createClient } from 'contentful';
137
137
138
138
App .getInitialProps = async ({Component, ctx, router}) => {
139
139
// Check whether route has `cms-preview` query parameter
140
- const isPreviewingContentful = Object . hasOwnProperty . call ( router .query , ' cms-preview' ) ;
140
+ const isPreviewingContentful = router .query [ ' cms-preview' ] != null ;
141
141
142
142
// Set the preview or regular host
143
143
const contentfulHost = isPreviewingContentful ? ' preview.contentful.com' : ' cdn.contentful.com' ;
@@ -208,9 +208,9 @@ export const buildStore = (initialState, { query }) => {
208
208
});
209
209
210
210
if (
211
- // For server-side, check wether `query` exists and has the `cms-preview` key
212
- ( typeof query !== ' undefined ' && Object . hasOwnProperty . call (query, ' cms-preview' )) ||
213
- // For client-side, check wether `window` exist and has the `cms-preview` query parameter
211
+ // For server-side, check whether `query` exists and has the `cms-preview` key
212
+ query? .[ ' cms-preview' ] != null ||
213
+ // For client-side, check whether `window` exists and has the `cms-preview` query parameter
214
214
(typeof window !== ' undefined' && new URLSearchParams (window .location .search ).has (' cms-preview' ))
215
215
) {
216
216
// In a positive case, switch the client instance to access the Preview API instead
@@ -331,7 +331,7 @@ const App = ({ Component, pageProps, rootSelector, router }) => {
331
331
const [isPreviewingContentful , setIsPreviewingContentful ] = useState (false );
332
332
333
333
// Using a useEffect hook with no dependencies guaranties that it fires only once per instance of App
334
- useEffect(() => setIsPreviewingContentful(Object.hasOwnProperty.call( router.query, ' cms- preview' ) ), []);
334
+ useEffect (() => setIsPreviewingContentful (router .query [ ' cms-preview' ] != null ), []);
335
335
336
336
return (
337
337
(... )
@@ -355,7 +355,7 @@ class App extends NextApp {
355
355
const { router } = this .props ;
356
356
357
357
this .setState ({
358
- isPreviewingContentful: Object.hasOwnProperty.call( router.query, ' cms- preview' );
358
+ isPreviewingContentful: router .query [ ' cms-preview' ] != null ,
359
359
});
360
360
}
361
361
0 commit comments