Skip to content

Commit cc2e0fa

Browse files
committed
Add support for previewwindow= and prevent duplication
1 parent 10601b4 commit cc2e0fa

File tree

1 file changed

+19
-0
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Content

1 file changed

+19
-0
lines changed

packages/app/src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { Prompt } from 'react-router-dom';
55
import { reaction } from 'mobx';
66
import { TextOperation } from 'ot';
77
import { inject, observer } from 'mobx-react';
8+
import { uniqBy } from 'lodash-es';
89

10+
import { getSandboxOptions } from '@codesandbox/common/lib/url';
911
import getTemplateDefinition from '@codesandbox/common/lib/templates';
1012
import type { ModuleError } from '@codesandbox/common/lib/types';
1113
import { getPreviewTabs } from '@codesandbox/common/lib/templates/devtools';
@@ -468,11 +470,28 @@ class EditorPreview extends React.Component<Props, State> {
468470
}
469471
}
470472

473+
const sandboxOptions = getSandboxOptions(location.href);
474+
if (
475+
(sandboxOptions.previewWindow &&
476+
sandboxOptions.previewWindow === 'tests') ||
477+
sandboxOptions.previewWindow === 'console'
478+
) {
479+
// Backwards compatibility for ?previewwindow=
480+
481+
view = sandboxOptions.previewWindow;
482+
}
483+
471484
if (view !== 'browser') {
472485
// Backwards compatibility for sandbox.config.json
473486
if (view === 'console') {
487+
views[0].views = views[0].views.filter(
488+
t => t.id !== 'codesandbox.console'
489+
);
474490
views[0].views.unshift({ id: 'codesandbox.console' });
475491
} else if (view === 'tests') {
492+
views[0].views = views[0].views.filter(
493+
t => t.id !== 'codesandbox.tests'
494+
);
476495
views[0].views.unshift({ id: 'codesandbox.tests' });
477496
}
478497
}

0 commit comments

Comments
 (0)