Skip to content

Commit c7927cc

Browse files
Use feature flags instead of accessing localStorage directly (codesandbox#3573)
* Use feature flags instead of accessing localStorage directly * Don't use Sandbox's `featureFlags` * Fix check
1 parent 8b83461 commit c7927cc

File tree

7 files changed

+23
-28
lines changed

7 files changed

+23
-28
lines changed

packages/app/src/app/overmind/effects/vscode/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
SandboxFs,
1212
Settings,
1313
} from '@codesandbox/common/lib/types';
14+
import { CONTAINER_LSP } from '@codesandbox/common/lib/utils/feature-flags';
1415
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
1516
import {
1617
NotificationMessage,
@@ -342,7 +343,7 @@ export class VSCodeEffect {
342343
//
343344
}
344345

345-
if (isServer && this.options.getCurrentUser()?.experiments.containerLsp) {
346+
if (isServer && CONTAINER_LSP === 'true') {
346347
childProcess.addDefaultForkHandler(this.createContainerForkHandler());
347348
const socket = this.createWebsocketFSRequest();
348349
const cache = await this.createFileSystem('WebsocketFS', {

packages/app/src/app/overmind/namespaces/editor/actions.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
WindowOrientation,
99
} from '@codesandbox/common/lib/types';
1010
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
11+
import { CONTAINER_LSP } from '@codesandbox/common/lib/utils/feature-flags';
1112
import { convertTypeToStatus } from '@codesandbox/common/lib/utils/notifications';
1213
import { Action, AsyncAction } from 'app/overmind';
1314
import { withLoadApp, withOwnedSandbox } from 'app/overmind/factories';
@@ -120,11 +121,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
120121
state.editor.modulesByPath = fs;
121122
});
122123

123-
if (
124-
sandbox.featureFlags &&
125-
sandbox.featureFlags.containerLsp &&
126-
!sandbox.owned
127-
) {
124+
if (CONTAINER_LSP === 'true' && !sandbox.owned) {
128125
effects.vscode.setReadOnly(true);
129126
effects.notificationToast.add({
130127
message:

packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/ContainerLSP.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CONTAINER_LSP } from '@codesandbox/common/lib/utils/feature-flags';
12
import React, { useState, useEffect } from 'react';
23
import { useOvermind } from 'app/overmind';
34
import { SubDescription, PaddedPreference } from '../elements';
@@ -6,9 +7,7 @@ export const ContainerLSP: React.FunctionComponent = () => {
67
const { state } = useOvermind();
78
const [containerLSP, setContainerLSP] = useState(false);
89
useEffect(() => {
9-
const value = window.localStorage.getItem('CONTAINER_LSP');
10-
11-
if (value === 'true') {
10+
if (CONTAINER_LSP === 'true') {
1211
return setContainerLSP(true);
1312
}
1413
return setContainerLSP(false);

packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/NewSidebar.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
import { REDESIGNED_SIDEBAR } from '@codesandbox/common/lib/utils/feature-flags';
12
import React, { useState, useEffect } from 'react';
23

34
import { SubDescription, PaddedPreference } from '../elements';
45

56
export const NewSidebar: React.FunctionComponent = () => {
67
const [newSidebar, setNewSidebar] = useState(false);
78
useEffect(() => {
8-
const value = window.localStorage.getItem('REDESIGNED_SIDEBAR');
9-
10-
if (value === 'true') {
9+
if (REDESIGNED_SIDEBAR === 'true') {
1110
return setNewSidebar(true);
1211
}
1312
return setNewSidebar(false);

packages/common/src/types/index.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ export type Sandbox = {
319319
userLiked: boolean;
320320
modules: Module[];
321321
directories: Directory[];
322-
featureFlags: {
323-
[key: string]: boolean;
324-
};
325322
collection?: {
326323
path: string;
327324
};
@@ -448,10 +445,10 @@ export type PackageJSON = {
448445
keywords?: string[];
449446
main?: string;
450447
module?: string;
451-
scripts?: { [command: string]: string; };
452-
dependencies?: { [dependency: string]: string; };
453-
devDependencies?: { [dependency: string]: string; };
454-
jest?: { setupFilesAfterEnv?: string[]; };
448+
scripts?: { [command: string]: string };
449+
dependencies?: { [dependency: string]: string };
450+
devDependencies?: { [dependency: string]: string };
451+
jest?: { setupFilesAfterEnv?: string[] };
455452
resolutions?: { [dependency: string]: string };
456453
};
457454

packages/common/src/utils/feature-flags.js

-9
This file was deleted.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
poor man's feature flags
3+
4+
you can export a constant which enables/disables a feature
5+
6+
it's a TS file, so you can add whatever logic you want as long as it's static
7+
*/
8+
9+
export const CONTAINER_LSP = localStorage.getItem('CONTAINER_LSP') || false;
10+
export const REDESIGNED_SIDEBAR =
11+
localStorage.getItem('REDESIGNED_SIDEBAR') || false;

0 commit comments

Comments
 (0)