diff --git a/beta/package.json b/beta/package.json
index cca603d6a..f6996879d 100644
--- a/beta/package.json
+++ b/beta/package.json
@@ -22,7 +22,7 @@
"check-all": "npm-run-all prettier lint:fix tsc"
},
"dependencies": {
- "@codesandbox/sandpack-react": "1.3.3",
+ "@codesandbox/sandpack-react": "v0.19.8-experimental.7",
"@docsearch/css": "3.0.0-alpha.41",
"@docsearch/react": "3.0.0-alpha.41",
"@headlessui/react": "^1.3.0",
diff --git a/beta/patches/@codesandbox+sandpack-react+0.19.8-experimental.4.patch b/beta/patches/@codesandbox+sandpack-react+0.19.8-experimental.4.patch
new file mode 100644
index 000000000..2298cbd1a
--- /dev/null
+++ b/beta/patches/@codesandbox+sandpack-react+0.19.8-experimental.4.patch
@@ -0,0 +1,37 @@
+diff --git a/node_modules/@codesandbox/sandpack-react/dist/esm/index.js b/node_modules/@codesandbox/sandpack-react/dist/esm/index.js
+index ced9bd3..7e5e366 100644
+--- a/node_modules/@codesandbox/sandpack-react/dist/esm/index.js
++++ b/node_modules/@codesandbox/sandpack-react/dist/esm/index.js
+@@ -566,17 +566,16 @@ var REACT_TEMPLATE = {
+ },
+ "/index.js": {
+ code: `import React, { StrictMode } from "react";
+-import ReactDOM from "react-dom";
++import { createRoot } from "react-dom/client";
+ import "./styles.css";
+
+ import App from "./App";
+
+-const rootElement = document.getElementById("root");
+-ReactDOM.render(
++const root = createRoot(document.getElementById("root"));
++root.render(
+
+
+- ,
+- rootElement
++
+ );`
+ },
+ "/styles.css": {
+@@ -611,8 +610,8 @@ h1 {
+ }
+ },
+ dependencies: {
+- react: "^17.0.0",
+- "react-dom": "^17.0.0",
++ react: "^18.0.0",
++ "react-dom": "^18.0.0",
+ "react-scripts": "^4.0.0"
+ },
+ entry: "/index.js",
diff --git a/beta/src/components/MDX/CodeBlock/CodeBlock.tsx b/beta/src/components/MDX/CodeBlock/CodeBlock.tsx
index 24696e0ad..965bc816a 100644
--- a/beta/src/components/MDX/CodeBlock/CodeBlock.tsx
+++ b/beta/src/components/MDX/CodeBlock/CodeBlock.tsx
@@ -6,6 +6,7 @@ import cn from 'classnames';
import {
SandpackCodeViewer,
SandpackProvider,
+ SandpackThemeProvider,
} from '@codesandbox/sandpack-react';
import rangeParser from 'parse-numeric-range';
import {CustomTheme} from '../Sandpack/Themes';
@@ -67,29 +68,27 @@ const CodeBlock = function CodeBlock({
const decorators = getDecoratedLineInfo();
return (
-
+ files: {
+ [filename]: {
+ code: children.trimEnd(),
+ },
+ },
+ }}>
+
+
+
);
diff --git a/beta/src/components/MDX/Sandpack/CustomPreset.tsx b/beta/src/components/MDX/Sandpack/CustomPreset.tsx
index e5d44671f..bb0f1c671 100644
--- a/beta/src/components/MDX/Sandpack/CustomPreset.tsx
+++ b/beta/src/components/MDX/Sandpack/CustomPreset.tsx
@@ -8,8 +8,8 @@ import {
useSandpack,
useActiveCode,
SandpackCodeEditor,
- // SandpackReactDevTools,
- SandpackLayout,
+ SandpackThemeProvider,
+ SandpackReactDevTools,
} from '@codesandbox/sandpack-react';
import scrollIntoView from 'scroll-into-view-if-needed';
import cn from 'classnames';
@@ -17,9 +17,12 @@ import cn from 'classnames';
import {IconChevron} from 'components/Icon/IconChevron';
import {NavigationBar} from './NavigationBar';
import {Preview} from './Preview';
-
+import {CustomTheme} from './Themes';
import {useSandpackLint} from './useSandpackLint';
+// Workaround for https://github.com/reactjs/reactjs.org/issues/4686#issuecomment-1137402613.
+const emptyArray: Array = [];
+
export function CustomPreset({
isSingleFile,
showDevTools,
@@ -38,11 +41,11 @@ export function CustomPreset({
const {code} = useActiveCode();
const [isExpanded, setIsExpanded] = React.useState(false);
- const {activeFile} = sandpack;
- if (!lineCountRef.current[activeFile]) {
- lineCountRef.current[activeFile] = code.split('\n').length;
+ const {activePath} = sandpack;
+ if (!lineCountRef.current[activePath]) {
+ lineCountRef.current[activePath] = code.split('\n').length;
}
- const lineCount = lineCountRef.current[activeFile];
+ const lineCount = lineCountRef.current[activePath];
const isExpandable = lineCount > 16 || isExpanded;
return (
@@ -51,57 +54,59 @@ export function CustomPreset({
className="shadow-lg dark:shadow-lg-dark rounded-lg"
ref={containerRef}>
-
-
-
-
- {isExpandable && (
-