Skip to content

Commit 2352b37

Browse files
committed
Make it so showInternals is preserved across reset/sessions
1 parent 89b35c5 commit 2352b37

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

compiler/apps/playground/components/Editor/Output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import parserBabel from 'prettier/plugins/babel';
2020
import * as prettierPluginEstree from 'prettier/plugins/estree';
2121
import * as prettier from 'prettier/standalone';
22-
import {memo, ReactNode, useEffect, useMemo, useState} from 'react';
22+
import {memo, ReactNode, useEffect, useState} from 'react';
2323
import {type Store} from '../../lib/stores';
2424
import TabbedWindow from '../TabbedWindow';
2525
import {monacoOptions} from './monacoOptions';

compiler/apps/playground/components/Header.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ export default function Header(): JSX.Element {
3232
* such as "Bad URL" will be closed by the outputs calling `closeSnackbar`.
3333
*/
3434
closeSnackbar();
35-
dispatchStore({type: 'setStore', payload: {store: defaultStore}});
35+
dispatchStore({
36+
type: 'setStore',
37+
payload: {
38+
store: {
39+
...defaultStore,
40+
showInternals: store.showInternals,
41+
},
42+
},
43+
});
3644
}
3745
};
3846

compiler/apps/playground/lib/stores/store.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export function decodeStore(hash: string): any {
3232
*/
3333
export function saveStore(store: Store): void {
3434
const hash = encodeStore(store);
35+
localStorage.setItem(
36+
'playgroundShowInternals',
37+
store.showInternals.toString(),
38+
);
3539
localStorage.setItem('playgroundStore', hash);
3640
history.replaceState({}, '', `#${hash}`);
3741
}
@@ -58,20 +62,29 @@ export function initStoreFromUrlOrLocalStorage(): Store {
5862
const encodedSourceFromLocal = localStorage.getItem('playgroundStore');
5963
const encodedSource = encodedSourceFromUrl || encodedSourceFromLocal;
6064

65+
// Prioritize local storage for showInternals field
66+
const showInternals =
67+
localStorage.getItem('playgroundShowInternals') === 'true';
68+
6169
/**
6270
* No data in the URL and no data in the localStorage to fallback to.
6371
* Initialize with the default store.
6472
*/
65-
if (!encodedSource) return defaultStore;
73+
if (!encodedSource) {
74+
return {
75+
...defaultStore,
76+
showInternals,
77+
};
78+
}
6679

67-
const raw: any = decodeStore(encodedSource);
80+
const raw = decodeStore(encodedSource);
6881

6982
invariant(isValidStore(raw), 'Invalid Store');
7083

7184
// Make sure all properties are populated
7285
return {
7386
source: raw.source,
7487
config: 'config' in raw ? raw.config : defaultConfig,
75-
showInternals: 'showInternals' in raw ? raw.showInternals : false,
88+
showInternals,
7689
};
7790
}

0 commit comments

Comments
 (0)