Skip to content

Commit 5ca24f5

Browse files
eps1lonlumirlumir
authored andcommitted
Disallow /index.html in sandboxes (#7430)
1 parent b3594f0 commit 5ca24f5

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

src/components/MDX/Sandpack/SandpackRoot.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ function SandpackRoot(props: SandpackProps) {
7171
const codeSnippets = Children.toArray(children) as React.ReactElement[];
7272
const files = createFileMap(codeSnippets);
7373

74+
if ('/index.html' in files) {
75+
throw new Error(
76+
'You cannot use `index.html` file in sandboxes. ' +
77+
'Only `public/index.html` is respected by Sandpack and CodeSandbox (where forks are created).'
78+
);
79+
}
80+
7481
files['/src/styles.css'] = {
7582
code: [sandboxStyle, files['/src/styles.css']?.code ?? ''].join('\n\n'),
7683
hidden: !files['/src/styles.css']?.visible,

src/content/learn/add-react-to-an-existing-project.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ npm install react react-dom
5858

5959
<Sandpack>
6060

61-
```html index.html hidden
61+
```html public/index.html hidden
6262
<!DOCTYPE html>
6363
<html>
6464
<head><title>My app</title></head>
6565
<body>
66-
<!-- 기존 페이지 컨텐츠 (이 예시에서는 이 부분이 대체됩니다)-->
66+
<!-- Your existing page content (in this example, it gets replaced) -->
67+
<div id="root"></div>
6768
</body>
6869
</html>
6970
```
@@ -121,7 +122,7 @@ root.render(<h1>Hello, world</h1>);
121122

122123
<Sandpack>
123124

124-
```html index.html
125+
```html public/index.html
125126
<!DOCTYPE html>
126127
<html>
127128
<head><title>My app</title></head>

src/content/reference/react-dom/client/createRoot.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ root.render(<App />);
142142
143143
<Sandpack>
144144
145-
```html index.html
145+
```html public/index.html
146146
<!DOCTYPE html>
147147
<html>
148148
<head><title>My app</title></head>
@@ -372,7 +372,7 @@ You can use the `onUncaughtError` root option to display error dialogs:
372372
373373
<Sandpack>
374374
375-
```html index.html hidden
375+
```html public/index.html hidden
376376
<!DOCTYPE html>
377377
<html>
378378
<head>
@@ -603,7 +603,7 @@ You can use the `onCaughtError` root option to display error dialogs or filter k
603603
604604
<Sandpack>
605605
606-
```html index.html hidden
606+
```html public/index.html hidden
607607
<!DOCTYPE html>
608608
<html>
609609
<head>
@@ -882,7 +882,7 @@ You can use the `onRecoverableError` root option to display error dialogs:
882882
883883
<Sandpack>
884884
885-
```html index.html hidden
885+
```html public/index.html hidden
886886
<!DOCTYPE html>
887887
<html>
888888
<head>

src/content/reference/react-dom/client/hydrateRoot.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ root.render(<App />);
401401
402402
<Sandpack>
403403
404-
```html index.html hidden
404+
```html public/index.html hidden
405405
<!DOCTYPE html>
406406
<html>
407407
<head>
@@ -634,7 +634,7 @@ root.render(<App />);
634634
635635
<Sandpack>
636636
637-
```html index.html hidden
637+
```html public/index.html hidden
638638
<!DOCTYPE html>
639639
<html>
640640
<head>
@@ -914,7 +914,7 @@ Hydration 불일치에 대한 대화 상자를 표시하려면 `onRecoverableErr
914914
915915
<Sandpack>
916916
917-
```html index.html hidden
917+
```html public/index.html hidden
918918
<!DOCTYPE html>
919919
<html>
920920
<head>

src/content/reference/react-dom/createPortal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Portal은 React 루트가 React로 빌드되지 않은 정적 또는 서버 렌
251251
252252
<Sandpack>
253253
254-
```html index.html
254+
```html public/index.html
255255
<!DOCTYPE html>
256256
<html>
257257
<head><title>My app</title></head>

src/content/reference/react/useId.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ input { margin: 5px; }
226226
227227
<Sandpack>
228228
229-
```html index.html
229+
```html public/index.html
230230
<!DOCTYPE html>
231231
<html>
232232
<head><title>My app</title></head>

0 commit comments

Comments
 (0)