@@ -187,7 +187,7 @@ export default function Playground({
187
187
* Otherwise, if there is a saved mode from previously clicking
188
188
* the mode button, use that.
189
189
*/
190
- const storedMode = localStorage . getItem ( MODE_STORAGE_KEY ) ;
190
+ const storedMode = window !== undefined ? localStorage . getItem ( MODE_STORAGE_KEY ) : null ;
191
191
if ( storedMode ) return storedMode ;
192
192
193
193
/**
@@ -201,7 +201,7 @@ export default function Playground({
201
201
* If there is a saved target from previously clicking the
202
202
* framework buttons, and there is code for it, use that.
203
203
*/
204
- const storedTarget = localStorage . getItem ( USAGE_TARGET_STORAGE_KEY ) ;
204
+ const storedTarget = window !== undefined ? localStorage . getItem ( USAGE_TARGET_STORAGE_KEY ) : null ;
205
205
if ( storedTarget && code [ storedTarget ] !== undefined ) {
206
206
return storedTarget ;
207
207
}
@@ -242,43 +242,49 @@ export default function Playground({
242
242
const [ resetCount , setResetCount ] = useState ( 0 ) ;
243
243
244
244
const setAndSaveMode = ( mode : Mode ) => {
245
- localStorage . setItem ( MODE_STORAGE_KEY , mode ) ;
246
245
setIonicMode ( mode ) ;
247
246
248
- /**
249
- * Tell other playgrounds on the page that the mode has
250
- * updated, so they can sync up.
251
- */
252
- window . dispatchEvent (
253
- new CustomEvent ( MODE_UPDATED_EVENT , {
254
- detail : mode ,
255
- } )
256
- ) ;
247
+ if ( window !== undefined ) {
248
+ localStorage . setItem ( MODE_STORAGE_KEY , mode ) ;
249
+
250
+ /**
251
+ * Tell other playgrounds on the page that the mode has
252
+ * updated, so they can sync up.
253
+ */
254
+ window . dispatchEvent (
255
+ new CustomEvent ( MODE_UPDATED_EVENT , {
256
+ detail : mode ,
257
+ } )
258
+ ) ;
259
+ }
257
260
} ;
258
261
259
262
const setAndSaveUsageTarget = ( target : UsageTarget , tab : HTMLElement ) => {
260
- localStorage . setItem ( USAGE_TARGET_STORAGE_KEY , target ) ;
261
263
setUsageTarget ( target ) ;
262
264
263
- /**
264
- * This prevents the scroll position from jumping around if
265
- * there is a playground above this one with code that changes
266
- * in length between frameworks.
267
- *
268
- * Note that we don't need this when changing the mode because
269
- * the two mode iframes are always the same height.
270
- */
271
- blockElementScrollPositionUntilNextRender ( tab ) ;
265
+ if ( window !== undefined ) {
266
+ localStorage . setItem ( USAGE_TARGET_STORAGE_KEY , target ) ;
272
267
273
- /**
274
- * Tell other playgrounds on the page that the framework
275
- * has updated, so they can sync up.
276
- */
277
- window . dispatchEvent (
278
- new CustomEvent ( USAGE_TARGET_UPDATED_EVENT , {
279
- detail : target ,
280
- } )
281
- ) ;
268
+ /**
269
+ * This prevents the scroll position from jumping around if
270
+ * there is a playground above this one with code that changes
271
+ * in length between frameworks.
272
+ *
273
+ * Note that we don't need this when changing the mode because
274
+ * the two mode iframes are always the same height.
275
+ */
276
+ blockElementScrollPositionUntilNextRender ( tab ) ;
277
+
278
+ /**
279
+ * Tell other playgrounds on the page that the framework
280
+ * has updated, so they can sync up.
281
+ */
282
+ window . dispatchEvent (
283
+ new CustomEvent ( USAGE_TARGET_UPDATED_EVENT , {
284
+ detail : target ,
285
+ } )
286
+ ) ;
287
+ }
282
288
} ;
283
289
284
290
/**
0 commit comments