Skip to content

Commit 827e440

Browse files
committed
Added error reporting for try it now
1 parent 00107f8 commit 827e440

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed
Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import type {
2-
SandpackOptions,
3-
SandpackSetup,
4-
} from "@codesandbox/sandpack-react";
51
import {
62
SandpackCodeEditor,
73
SandpackConsole,
84
SandpackLayout,
95
SandpackPreview,
106
SandpackProvider,
7+
useErrorMessage,
118
} from "@codesandbox/sandpack-react";
129
import { useAtomValue } from "jotai";
13-
import { Fragment } from "react";
1410

15-
import { CodeEditor } from "./CodeEditor/index.tsx";
1611
import { dependenciesAtom, lastEditorValueAtom } from "./state/index.ts";
1712
import { styles } from "./styles.ts";
1813

@@ -30,17 +25,6 @@ type TryItNowProps = {
3025
* Starting value of the editor
3126
*/
3227
defaultValue?: string;
33-
/**
34-
* Props for the container that wraps the editor and console output.
35-
*/
36-
containerProps?: React.HTMLAttributes<HTMLDivElement>;
37-
/**
38-
* Render only the Sandpack provider and components to use in a
39-
* custom container.
40-
*/
41-
disableContainer?: boolean;
42-
sandpackOptions?: Partial<SandpackOptions>;
43-
sandpackSetupOptions?: Partial<SandpackSetup>;
4428
/**
4529
* Experimental: When enabled, the editor will automatically
4630
* scan for external dependencies from npm as the user adds them
@@ -49,30 +33,40 @@ type TryItNowProps = {
4933
_enableUnsafeAutoImport?: boolean;
5034
};
5135

36+
const TryItNowContents = () => {
37+
const error = useErrorMessage();
38+
return (
39+
<SandpackLayout>
40+
<SandpackCodeEditor />
41+
{!error && (
42+
<SandpackConsole
43+
resetOnPreviewRestart
44+
showSetupProgress
45+
showRestartButton
46+
/>
47+
)}
48+
<SandpackPreview style={error ? undefined : styles.preview}>
49+
{error ? <pre>{error}</pre> : null}
50+
</SandpackPreview>
51+
</SandpackLayout>
52+
);
53+
};
54+
5255
export const TryItNow = ({
5356
externalDependencies,
5457
defaultValue = "",
5558
_enableUnsafeAutoImport,
56-
containerProps,
57-
disableContainer,
58-
sandpackOptions = {},
59-
sandpackSetupOptions = {},
6059
}: TryItNowProps) => {
6160
const autoImportDependencies = useAtomValue(dependenciesAtom);
6261
const previousCodeAtomValue = useAtomValue(lastEditorValueAtom);
63-
const OuterContainer = disableContainer ? Fragment : "div";
6462

6563
return (
66-
<OuterContainer
67-
style={{ ...styles.container, ...containerProps?.style }}
68-
{...containerProps}
69-
>
64+
<div style={{ ...styles.container }}>
7065
<SandpackProvider
7166
options={{
7267
autoReload: false,
7368
autorun: false,
7469
activeFile: "index.tsx",
75-
...sandpackOptions,
7670
}}
7771
template="vanilla-ts"
7872
files={{
@@ -90,20 +84,11 @@ export const TryItNow = ({
9084
? { ...autoImportDependencies, ...externalDependencies }
9185
: externalDependencies,
9286
entry: "index.tsx",
93-
...sandpackSetupOptions,
9487
}}
9588
theme="dark"
9689
>
97-
<SandpackLayout>
98-
<SandpackPreview style={styles.preview} />
99-
{_enableUnsafeAutoImport ? <CodeEditor /> : <SandpackCodeEditor />}
100-
<SandpackConsole
101-
resetOnPreviewRestart
102-
showSetupProgress
103-
showRestartButton
104-
/>
105-
</SandpackLayout>
90+
<TryItNowContents />
10691
</SandpackProvider>
107-
</OuterContainer>
92+
</div>
10893
);
10994
};

packages/docs-md/src/generator/mdx/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Site {
4343
recursive: true,
4444
withFileTypes: true,
4545
})
46-
.filter((f) => f.isFile())
46+
.filter((f) => f.isFile() && f.name !== "tsconfig.json")
4747
.map((f) => join(f.parentPath, f.name).replace(ASSET_PATH + "/", ""));
4848
for (const assetFile of assetFileList) {
4949
this.#pages.set(

0 commit comments

Comments
 (0)