diff --git a/packages/docs-md/assets/TryItNow/index.tsx b/packages/docs-md/assets/TryItNow/index.tsx index 5e1b632e0..a378a303d 100644 --- a/packages/docs-md/assets/TryItNow/index.tsx +++ b/packages/docs-md/assets/TryItNow/index.tsx @@ -1,16 +1,12 @@ -import type { - SandpackOptions, - SandpackSetup, -} from "@codesandbox/sandpack-react"; import { SandpackCodeEditor, SandpackConsole, SandpackLayout, SandpackPreview, SandpackProvider, + useErrorMessage, } from "@codesandbox/sandpack-react"; import { useAtomValue } from "jotai"; -import { Fragment } from "react"; import { CodeEditor } from "./CodeEditor/index.tsx"; import { dependenciesAtom, lastEditorValueAtom } from "./state/index.ts"; @@ -30,17 +26,6 @@ type TryItNowProps = { * Starting value of the editor */ defaultValue?: string; - /** - * Props for the container that wraps the editor and console output. - */ - containerProps?: React.HTMLAttributes; - /** - * Render only the Sandpack provider and components to use in a - * custom container. - */ - disableContainer?: boolean; - sandpackOptions?: Partial; - sandpackSetupOptions?: Partial; /** * Experimental: When enabled, the editor will automatically * scan for external dependencies from npm as the user adds them @@ -49,34 +34,48 @@ type TryItNowProps = { _enableUnsafeAutoImport?: boolean; }; +const TryItNowContents = ({ + _enableUnsafeAutoImport, +}: { + _enableUnsafeAutoImport?: boolean; +}) => { + const error = useErrorMessage(); + return ( + + {_enableUnsafeAutoImport ? : } + {!error && ( + + )} + + {error ?
{error}
: null} +
+
+ ); +}; + export const TryItNow = ({ externalDependencies, defaultValue = "", _enableUnsafeAutoImport, - containerProps, - disableContainer, - sandpackOptions = {}, - sandpackSetupOptions = {}, }: TryItNowProps) => { const autoImportDependencies = useAtomValue(dependenciesAtom); const previousCodeAtomValue = useAtomValue(lastEditorValueAtom); - const OuterContainer = disableContainer ? Fragment : "div"; return ( - +
- - - {_enableUnsafeAutoImport ? : } - - + - +
); }; diff --git a/packages/docs-md/src/generator/mdx/renderer.ts b/packages/docs-md/src/generator/mdx/renderer.ts index ec5cc0f4f..d83b45d6b 100644 --- a/packages/docs-md/src/generator/mdx/renderer.ts +++ b/packages/docs-md/src/generator/mdx/renderer.ts @@ -43,7 +43,7 @@ export class Site { recursive: true, withFileTypes: true, }) - .filter((f) => f.isFile()) + .filter((f) => f.isFile() && f.name !== "tsconfig.json") .map((f) => join(f.parentPath, f.name).replace(ASSET_PATH + "/", "")); for (const assetFile of assetFileList) { this.#pages.set( @@ -213,13 +213,14 @@ sidebarTitle: ${this.escapeText(sidebarLabel)} title: string; embedName: string; }) { - this.#includeSidebar = true; - this.insertComponentImport("SideBarCta", "SideBar/index.tsx"); - this.insertComponentImport("SideBar", "SideBar/index.tsx"); + // If this is a circular import, skip processing sidebar if (!this.#insertEmbedImport(embedName)) { - console.error(`Direct circular import detected, skipping sidebar link`); + // TODO: add debug logging return; } + this.#includeSidebar = true; + this.insertComponentImport("SideBarCta", "SideBar/index.tsx"); + this.insertComponentImport("SideBar", "SideBar/index.tsx"); this.#lines.push( `