Skip to content

Commit db8e3a6

Browse files
authored
Merge pull request #17 from reactjs/sync-bdc60c26
Sync with react.dev @ bdc60c2
2 parents e8623ce + c960a28 commit db8e3a6

24 files changed

+251
-818
lines changed

.env.development

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
SANDPACK_BARE_COMPONENTS=true

.env.production

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
NEXT_PUBLIC_GA_TRACKING_ID = 'UA-41298772-4'
2-
SANDPACK_BARE_COMPONENTS=true
1+
NEXT_PUBLIC_GA_TRACKING_ID = 'UA-41298772-4'

next.config.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const nextConfig = {
1414
scrollRestoration: true,
1515
legacyBrowsers: false,
1616
},
17-
env: {
18-
SANDPACK_BARE_COMPONENTS: process.env.SANDPACK_BARE_COMPONENTS,
19-
},
17+
env: {},
2018
webpack: (config, {dev, isServer, ...options}) => {
2119
if (process.env.ANALYZE) {
2220
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
@@ -35,10 +33,6 @@ const nextConfig = {
3533

3634
const {IgnorePlugin, NormalModuleReplacementPlugin} = require('webpack');
3735
config.plugins.push(
38-
new NormalModuleReplacementPlugin(
39-
/^@stitches\/core$/,
40-
require.resolve('./src/utils/emptyShim.js')
41-
),
4236
new NormalModuleReplacementPlugin(
4337
/^raf$/,
4438
require.resolve('./src/utils/rafShim.js')

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"check-all": "npm-run-all prettier lint:fix tsc"
2323
},
2424
"dependencies": {
25-
"@codesandbox/sandpack-react": "1.15.5",
25+
"@codesandbox/sandpack-react": "2.6.0",
2626
"@docsearch/css": "3.0.0-alpha.41",
2727
"@docsearch/react": "3.0.0-alpha.41",
2828
"@headlessui/react": "^1.7.0",

patches/@codemirror+lang-javascript+0.19.6.patch

-30
This file was deleted.

patches/@codesandbox+sandpack-react+1.15.5.patch

-62
This file was deleted.

patches/@lezer+javascript+0.15.2.patch

-345
This file was deleted.

src/components/MDX/CodeBlock/CodeBlock.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
*/
44

55
import cn from 'classnames';
6-
import {highlightTree, HighlightStyle, tags} from '@codemirror/highlight';
6+
import {HighlightStyle} from '@codemirror/language';
7+
import {highlightTree} from '@lezer/highlight';
78
import {javascript} from '@codemirror/lang-javascript';
89
import {html} from '@codemirror/lang-html';
910
import {css} from '@codemirror/lang-css';
1011
import rangeParser from 'parse-numeric-range';
12+
import {tags} from '@lezer/highlight';
13+
1114
import {CustomTheme} from '../Sandpack/Themes';
1215

1316
interface InlineHighlight {
@@ -52,7 +55,7 @@ const CodeBlock = function CodeBlock({
5255
let tokenStarts = new Map();
5356
let tokenEnds = new Map();
5457
const highlightTheme = getSyntaxHighlight(CustomTheme);
55-
highlightTree(tree, highlightTheme.match, (from, to, className) => {
58+
highlightTree(tree, highlightTheme, (from, to, className) => {
5659
tokenStarts.set(from, className);
5760
tokenEnds.set(to, className);
5861
});

src/components/MDX/Sandpack/Console.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import cn from 'classnames';
55
import {useState, useRef, useEffect} from 'react';
66
import {IconChevron} from 'components/Icon/IconChevron';
77

8-
import {SandpackCodeViewer, useSandpack} from '@codesandbox/sandpack-react';
8+
import {
9+
SandpackCodeViewer,
10+
useSandpack,
11+
} from '@codesandbox/sandpack-react/unstyled';
912
import type {SandpackMessageConsoleMethods} from '@codesandbox/sandpack-client';
1013

1114
const getType = (

src/components/MDX/Sandpack/CustomPreset.tsx

+1-22
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import {
77
useSandpack,
88
useActiveCode,
99
SandpackCodeEditor,
10-
// SandpackReactDevTools,
1110
SandpackLayout,
12-
} from '@codesandbox/sandpack-react';
11+
} from '@codesandbox/sandpack-react/unstyled';
1312
import cn from 'classnames';
1413

1514
import {IconChevron} from 'components/Icon/IconChevron';
@@ -19,14 +18,8 @@ import {Preview} from './Preview';
1918
import {useSandpackLint} from './useSandpackLint';
2019

2120
export const CustomPreset = memo(function CustomPreset({
22-
showDevTools,
23-
onDevToolsLoad,
24-
devToolsLoaded,
2521
providedFiles,
2622
}: {
27-
showDevTools: boolean;
28-
devToolsLoaded: boolean;
29-
onDevToolsLoad: () => void;
3023
providedFiles: Array<string>;
3124
}) {
3225
const {lintErrors, lintExtensions} = useSandpackLint();
@@ -41,9 +34,6 @@ export const CustomPreset = memo(function CustomPreset({
4134
const isExpandable = lineCount > 16;
4235
return (
4336
<SandboxShell
44-
showDevTools={showDevTools}
45-
onDevToolsLoad={onDevToolsLoad}
46-
devToolsLoaded={devToolsLoaded}
4737
providedFiles={providedFiles}
4838
lintErrors={lintErrors}
4939
lintExtensions={lintExtensions}
@@ -53,16 +43,11 @@ export const CustomPreset = memo(function CustomPreset({
5343
});
5444

5545
const SandboxShell = memo(function SandboxShell({
56-
showDevTools,
57-
devToolsLoaded,
5846
providedFiles,
5947
lintErrors,
6048
lintExtensions,
6149
isExpandable,
6250
}: {
63-
showDevTools: boolean;
64-
devToolsLoaded: boolean;
65-
onDevToolsLoad: () => void;
6651
providedFiles: Array<string>;
6752
lintErrors: Array<any>;
6853
lintExtensions: Array<any>;
@@ -81,7 +66,6 @@ const SandboxShell = memo(function SandboxShell({
8166
<NavigationBar providedFiles={providedFiles} />
8267
<SandpackLayout
8368
className={cn(
84-
showDevTools && devToolsLoaded && 'sp-layout-devtools',
8569
!(isExpandable || isExpanded) && 'rounded-b-lg overflow-hidden',
8670
isExpanded && 'sp-layout-expanded'
8771
)}>
@@ -123,11 +107,6 @@ const SandboxShell = memo(function SandboxShell({
123107
</button>
124108
)}
125109
</SandpackLayout>
126-
127-
{/* {showDevTools && (
128-
// @ts-ignore TODO(@danilowoz): support devtools
129-
<SandpackReactDevTools onLoadModule={onDevToolsLoad} />
130-
)} */}
131110
</div>
132111
</>
133112
);

src/components/MDX/Sandpack/DownloadButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import {useSyncExternalStore} from 'react';
6-
import {useSandpack} from '@codesandbox/sandpack-react';
6+
import {useSandpack} from '@codesandbox/sandpack-react/unstyled';
77
import {IconDownload} from '../../Icon/IconDownload';
88
export interface DownloadButtonProps {}
99

src/components/MDX/Sandpack/LoadingOverlay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
LoadingOverlayState,
55
OpenInCodeSandboxButton,
66
useSandpack,
7-
} from '@codesandbox/sandpack-react';
7+
} from '@codesandbox/sandpack-react/unstyled';
88
import {useEffect} from 'react';
99

1010
const FADE_ANIMATION_DURATION = 200;

src/components/MDX/Sandpack/NavigationBar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
FileTabs,
1616
useSandpack,
1717
useSandpackNavigation,
18-
} from '@codesandbox/sandpack-react';
18+
} from '@codesandbox/sandpack-react/unstyled';
1919
import {OpenInCodeSandboxButton} from './OpenInCodeSandboxButton';
2020
import {ResetButton} from './ResetButton';
2121
import {DownloadButton} from './DownloadButton';

src/components/MDX/Sandpack/OpenInCodeSandboxButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Facebook, Inc. and its affiliates.
33
*/
44

5-
import {UnstyledOpenInCodeSandboxButton} from '@codesandbox/sandpack-react';
5+
import {UnstyledOpenInCodeSandboxButton} from '@codesandbox/sandpack-react/unstyled';
66
import {IconNewPage} from '../../Icon/IconNewPage';
77

88
export const OpenInCodeSandboxButton = () => {

src/components/MDX/Sandpack/Preview.tsx

+2-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/* eslint-disable react-hooks/exhaustive-deps */
66
import {useRef, useState, useEffect, useMemo, useId} from 'react';
7-
import {useSandpack, SandpackStack} from '@codesandbox/sandpack-react';
7+
import {useSandpack, SandpackStack} from '@codesandbox/sandpack-react/unstyled';
88
import cn from 'classnames';
99
import {ErrorMessage} from './ErrorMessage';
1010
import {SandpackConsole} from './Console';
@@ -42,14 +42,7 @@ export function Preview({
4242
null
4343
);
4444

45-
let {
46-
error: rawError,
47-
registerBundler,
48-
unregisterBundler,
49-
errorScreenRegisteredRef,
50-
openInCSBRegisteredRef,
51-
loadingScreenRegisteredRef,
52-
} = sandpack;
45+
let {error: rawError, registerBundler, unregisterBundler} = sandpack;
5346

5447
if (
5548
rawError &&
@@ -88,12 +81,6 @@ export function Preview({
8881
const clientId = useId();
8982
const iframeRef = useRef<HTMLIFrameElement | null>(null);
9083

91-
// SandpackPreview immediately registers the custom screens/components so the bundler does not render any of them
92-
// TODO: why are we doing this during render?
93-
openInCSBRegisteredRef.current = true;
94-
errorScreenRegisteredRef.current = true;
95-
loadingScreenRegisteredRef.current = true;
96-
9784
const sandpackIdle = sandpack.status === 'idle';
9885

9986
useEffect(function createBundler() {

src/components/MDX/Sandpack/SandpackRoot.tsx

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Copyright (c) Facebook, Inc. and its affiliates.
33
*/
44

5-
import {Children, useState} from 'react';
5+
import {Children} from 'react';
66
import * as React from 'react';
7-
import {SandpackProvider} from '@codesandbox/sandpack-react';
7+
import {SandpackProvider} from '@codesandbox/sandpack-react/unstyled';
88
import {SandpackLogLevel} from '@codesandbox/sandpack-client';
99
import {CustomPreset} from './CustomPreset';
1010
import {createFileMap} from './createFileMap';
@@ -13,7 +13,6 @@ import {CustomTheme} from './Themes';
1313
type SandpackProps = {
1414
children: React.ReactNode;
1515
autorun?: boolean;
16-
showDevTools?: boolean;
1716
};
1817

1918
const sandboxStyle = `
@@ -67,8 +66,7 @@ ul {
6766
`.trim();
6867

6968
function SandpackRoot(props: SandpackProps) {
70-
let {children, autorun = true, showDevTools = false} = props;
71-
const [devToolsLoaded, setDevToolsLoaded] = useState(false);
69+
let {children, autorun = true} = props;
7270
const codeSnippets = Children.toArray(children) as React.ReactElement[];
7371
const files = createFileMap(codeSnippets);
7472

@@ -90,12 +88,7 @@ function SandpackRoot(props: SandpackProps) {
9088
bundlerURL: 'https://1e4ad8f7.sandpack-bundler-4bw.pages.dev',
9189
logLevel: SandpackLogLevel.None,
9290
}}>
93-
<CustomPreset
94-
showDevTools={showDevTools}
95-
onDevToolsLoad={() => setDevToolsLoaded(true)}
96-
devToolsLoaded={devToolsLoaded}
97-
providedFiles={Object.keys(files)}
98-
/>
91+
<CustomPreset providedFiles={Object.keys(files)} />
9992
</SandpackProvider>
10093
</div>
10194
);

src/components/MDX/Sandpack/createFileMap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Facebook, Inc. and its affiliates.
33
*/
44

5-
import type {SandpackFile} from '@codesandbox/sandpack-react';
5+
import type {SandpackFile} from '@codesandbox/sandpack-react/unstyled';
66

77
export const createFileMap = (codeSnippets: any) => {
88
return codeSnippets.reduce(

src/content/community/conferences.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ October 5 - 7, 2023. In-person in Goa, India (hybrid event) + Oct 3 2023 - remot
4646

4747
[Website](https://www.reactindia.io) - [Twitter](https://twitter.com/react_india) - [Facebook](https://www.facebook.com/ReactJSIndia) - [Youtube](https://www.youtube.com/channel/UCaFbHCBkPvVv1bWs_jwYt3w)
4848

49-
### React Brussels 2023 {/*react-brussels-2023*/}
49+
### React Brussels 2023 {/*react-brussels-2023*/}
5050
October 13th 2023. In-person in Brussels, Belgium + Remote (hybrid)
5151

5252
[Website](https://www.react.brussels/) - [Twitter](https://twitter.com/BrusselsReact)

src/content/reference/react/Component.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ If you define `UNSAFE_componentWillReceiveProps`, React will call it when the co
813813
#### Parameters {/*unsafe_componentwillreceiveprops-parameters*/}
814814
815815
- `nextProps`: The next props that the component is about to receive from its parent component. Compare `nextProps` to [`this.props`](#props) to determine what changed.
816-
- `nextContext`: The next props that the component is about to receive from the closest provider. Compare `nextContext` to [`this.context`](#context) to determine what changed. Only available if you specify [`static contextType`](#static-contexttype) (modern) or [`static contextTypes`](#static-contexttypes) (legacy).
816+
- `nextContext`: The next context that the component is about to receive from the closest provider. Compare `nextContext` to [`this.context`](#context) to determine what changed. Only available if you specify [`static contextType`](#static-contexttype) (modern) or [`static contextTypes`](#static-contexttypes) (legacy).
817817
818818
#### Returns {/*unsafe_componentwillreceiveprops-returns*/}
819819

src/content/reference/react/forwardRef.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export default function Form() {
423423

424424
return (
425425
<form>
426-
<MyInput label="Enter your name:" ref={ref} />
426+
<MyInput placeholder="Enter your name" ref={ref} />
427427
<button type="button" onClick={handleClick}>
428428
Edit
429429
</button>

src/content/reference/react/useImperativeHandle.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default function Form() {
124124

125125
return (
126126
<form>
127-
<MyInput label="Enter your name:" ref={ref} />
127+
<MyInput placeholder="Enter your name" ref={ref} />
128128
<button type="button" onClick={handleClick}>
129129
Edit
130130
</button>

src/styles/sandpack.css

+1-18
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ html.dark .sp-wrapper {
199199
background: var(--sp-colors-surface1);
200200
}
201201

202-
.sandpack .sp-code-editor .cm-editor,
203-
.sandpack .sp-code-editor .cm-editor .cm-gutters {
202+
.sandpack .sp-code-editor .cm-editor {
204203
background-color: transparent;
205204
}
206205

@@ -262,8 +261,6 @@ html.dark .sp-wrapper {
262261
}
263262

264263
.sp-code-editor .sp-cm .cm-scroller {
265-
overflow-x: hidden;
266-
overflow-y: auto;
267264
padding-top: 18px;
268265
}
269266

@@ -548,20 +545,6 @@ html.dark .sandpack--playground .sp-overlay {
548545
@apply text-secondary;
549546
}
550547

551-
/**
552-
* Integrations: React devtools inline
553-
*/
554-
.sandpack .sp-devtools {
555-
border-bottom-left-radius: 0.5rem;
556-
border-bottom-right-radius: 0.5rem;
557-
overflow: hidden;
558-
}
559-
560-
.sandpack .sp-wrapper .sp-layout-devtools {
561-
border-bottom-left-radius: 0;
562-
border-bottom-right-radius: 0;
563-
}
564-
565548
/**
566549
* Overwrite inline sty
567550
*/

src/utils/emptyShim.js

-6
This file was deleted.

0 commit comments

Comments
 (0)