Skip to content

Commit 4bd97f6

Browse files
authored
Merge pull request #776 from reactjs/sync-bdc60c26
Sync with react.dev @ bdc60c2
2 parents 371ed8c + 6ca0d0b commit 4bd97f6

26 files changed

+257
-824
lines changed

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
SANDPACK_BARE_COMPONENTS=true

.env.production

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

patches/@lezer+javascript+0.15.2.patch

Lines changed: 0 additions & 345 deletions
This file was deleted.

src/components/MDX/CodeBlock/CodeBlock.tsx

Lines changed: 5 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 1 addition & 22 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 15 deletions
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

Lines changed: 4 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ October 5 - 7, 2023. In-person in Goa, India (hybrid event) + Oct 3 2023 - remot
4040

4141
[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)
4242

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

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

src/content/learn/tutorial-tic-tac-toe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ body {
22662266
<li>Alexa: 5 tasks left</li>
22672267
```
22682268
2269-
아마 task의 개수가 업데이트되었을 뿐만 아니라 Alexa와 Ben의 순서가 바뀌고 Claudia가 두 사람 사이에 추가되었다고 생각할 것입니다. 그러나 React는 컴퓨터 프로그램이므로 우리가 의도한 바가 무엇인지 알지 못합니다. 그러므로 리스트의 항목에 _key_ 프로퍼티를 지정하여 각 리스트의 항목이 다른 항목과 다르다는 것을 구별해 주어야 합니다. 만약 데이터베이스에서 데이터를 불러와서 사용한다면 Alexa, Ben, Claudia의 데이터베이스 ID를 key로 사용할 수 있습니다.
2269+
아마 task의 개수가 업데이트 되었을 뿐만 아니라 Alexa와 Ben의 순서가 바뀌고 Claudia가 두 사람 사이에 추가되었다고 생각할 것입니다. 그러나 React는 컴퓨터 프로그램이므로 우리가 의도한 바가 무엇인지 알지 못합니다. 그러므로 리스트의 항목에 _key_ 프로퍼티를 지정하여 각 리스트의 항목이 다른 항목과 다르다는 것을 구별해 주어야 합니다. 만약 데이터베이스에서 데이터를 불러와서 사용한다면 Alexa, Ben, Claudia의 데이터베이스 ID를 key로 사용할 수 있습니다.
22702270
22712271
```js {1}
22722272
<li key={user.id}>

src/content/reference/react/forwardRef.md

Lines changed: 1 addition & 1 deletion
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/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ function TodoList({ todos, tab, theme }) {
108108
109109
## Resource Hooks {/*resource-hooks*/}
110110
111-
*Resources* can be accessed by a component without having them as part of their state. For example, a component can read a message from a Promise or read styling information from a context.
111+
컴포넌트는 *Resources*를 상태의 일부로 포함하지 않고도 접근할 수 있습니다. 예를 들어 컴포넌트는 Promise 로 부터 메세지를 읽거나 context 로 부터 styling 정보를 가져올 수 있습니다.
112+
resource 를 통해서 값을 읽으려면 다음 Hook 를 사용할 수 있습니다.
112113
113-
To read a value from a resource, use this Hook:
114114
115-
- [`use`](/reference/react/use) lets you read the value of a resource like a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or [context](/learn/passing-data-deeply-with-context).
115+
- [`use`](/reference/react/use) [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) 또는 [context](/learn/passing-data-deeply-with-context) 와 같은 리소스 값을 읽을 수 있습니다.
116116
117117
```js
118118
function MessageComponent({ messagePromise }) {

src/content/reference/react/lazy.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
3232

3333
#### 매개변수 {/*parameters*/}
3434

35-
* `load`: [Promise](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise) 또는 또 다른 *thenable* (`then` 메서드가 있는 Promise 유사 객체)을 반환하는 함수입니다. React는 반환된 컴포넌트를 처음 렌더링하려고 할 때까지 `load`를 호출하지 않을 것입니다. React는 먼저 `load`를 실행한 후 `load`가 이행될 때까지 기다렸다가 이행된 값을 호출한 다음, 확인된 값의 '.default'를 React 컴포넌트로 렌더링합니다. 반환된 Promise와 Promise의 이행된 값이 모두 캐시 되므로 React는 `load`를 두 번 이상 호출하지 않습니다. Promise가 거부하면 React는 가장 가까운 Error Boundary를 처리하기 위해 Error Boundary에 대한 거부 사유를 `throw` 할 것입니다.
35+
* `load`: [Promise](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise) 또는 또 다른 *thenable* (`then` 메서드가 있는 Promise 유사 객체)을 반환하는 함수입니다. React는 반환된 컴포넌트를 처음 렌더링하려고 할 때까지 `load`를 호출하지 않을 것입니다. React는 먼저 `load`를 실행한 후 `load`가 이행될 때까지 기다렸다가 이행된 값의 `.default`를 React 컴포넌트로 렌더링합니다. 반환된 Promise와 Promise의 이행된 값이 모두 캐시 되므로 React는 `load`를 두 번 이상 호출하지 않습니다. Promise가 거부하면 React는 가장 가까운 Error Boundary를 처리하기 위해 Error Boundary에 대한 거부 사유를 `throw` 할 것입니다.
3636

3737
#### 반환값 {/*returns*/}
3838

@@ -48,7 +48,7 @@ const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
4848

4949
#### 반환값 {/*load-returns*/}
5050

51-
[Promise](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise) 또는 다른 *thenable* (`then` 메서드가 있는 Promise 유사 객체)을 반환해야 합니다. 결국 '.default' 프로퍼티가 유효한 React 컴포넌트 유형(예: 함수)인 객체, [`memo`](/reference/react/memo) 또는 [`forwardRef`](/reference/react/forwardRef) 컴포넌트와 같은 유효한 React 컴포넌트 유형으로 이행해야 합니다.
51+
[Promise](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Promise) 또는 다른 *thenable* (`then` 메서드가 있는 Promise 유사 객체)을 반환해야 합니다. 결국 `.default` 프로퍼티가 함수, [`memo`](/reference/react/memo) 또는 [`forwardRef`](/reference/react/forwardRef) 컴포넌트와 같은 유효한 React 컴포넌트 유형인 객체로 해석되어야 합니다.
5252

5353
---
5454

@@ -70,7 +70,7 @@ import { lazy } from 'react';
7070
const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
7171
```
7272

73-
위의 코드는 [동적 `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)에 의존하므로 번들러 또는 프레임워크의 지원이 필요할 수 있습니다. 이 패턴을 사용하려면 import하려는 lazy 컴포넌트를 'default' 내보내기로 내보내야 합니다.
73+
위의 코드는 [동적 `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)에 의존하므로 번들러 또는 프레임워크의 지원이 필요할 수 있습니다. 이 패턴을 사용하려면 임포트하려는 lazy 컴포넌트가 `default` 내보내기로 내보내져 있어야 합니다.
7474

7575
이제 요청에 따라 컴포넌트의 코드가 로드되므로 로드하는 동안 표시할 항목도 지정해야 합니다. lazy 컴포넌트 또는 해당 부모 컴포넌트 중 하나를 [`<Suspense>`](/reference/react/Suspense) 바운더리로 감싸서 이 작업을 수행할 수 있습니다.
7676

src/content/reference/react/useImperativeHandle.md

Lines changed: 1 addition & 1 deletion
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>

0 commit comments

Comments
 (0)