Skip to content

Commit ee8a829

Browse files
authored
Disallow /index.html in sandboxes (#7430)
1 parent 316230a commit ee8a829

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

src/components/MDX/Sandpack/SandpackRoot.tsx

+7
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ Then add these lines of code at the top of your main JavaScript file (it might b
5757

5858
<Sandpack>
5959

60-
```html index.html hidden
60+
```html public/index.html hidden
6161
<!DOCTYPE html>
6262
<html>
6363
<head><title>My app</title></head>
6464
<body>
6565
<!-- Your existing page content (in this example, it gets replaced) -->
66+
<div id="root"></div>
6667
</body>
6768
</html>
6869
```
@@ -119,7 +120,7 @@ This lets you find that HTML element with [`document.getElementById`](https://de
119120

120121
<Sandpack>
121122

122-
```html index.html
123+
```html public/index.html
123124
<!DOCTYPE html>
124125
<html>
125126
<head><title>My app</title></head>

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Usually, you only need to run this code once at startup. It will:
144144
145145
<Sandpack>
146146
147-
```html index.html
147+
```html public/index.html
148148
<!DOCTYPE html>
149149
<html>
150150
<head><title>My app</title></head>
@@ -375,7 +375,7 @@ You can use the `onUncaughtError` root option to display error dialogs:
375375
376376
<Sandpack>
377377
378-
```html index.html hidden
378+
```html public/index.html hidden
379379
<!DOCTYPE html>
380380
<html>
381381
<head>
@@ -606,7 +606,7 @@ You can use the `onCaughtError` root option to display error dialogs or filter k
606606
607607
<Sandpack>
608608
609-
```html index.html hidden
609+
```html public/index.html hidden
610610
<!DOCTYPE html>
611611
<html>
612612
<head>
@@ -885,7 +885,7 @@ You can use the `onRecoverableError` root option to display error dialogs:
885885
886886
<Sandpack>
887887
888-
```html index.html hidden
888+
```html public/index.html hidden
889889
<!DOCTYPE html>
890890
<html>
891891
<head>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ You can use the `onUncaughtError` root option to display error dialogs:
406406
407407
<Sandpack>
408408
409-
```html index.html hidden
409+
```html public/index.html hidden
410410
<!DOCTYPE html>
411411
<html>
412412
<head>
@@ -641,7 +641,7 @@ You can use the `onCaughtError` root option to display error dialogs or filter k
641641
642642
<Sandpack>
643643
644-
```html index.html hidden
644+
```html public/index.html hidden
645645
<!DOCTYPE html>
646646
<html>
647647
<head>
@@ -922,7 +922,7 @@ You can use the `onRecoverableError` root option to display error dialogs for hy
922922
923923
<Sandpack>
924924
925-
```html index.html hidden
925+
```html public/index.html hidden
926926
<!DOCTYPE html>
927927
<html>
928928
<head>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Portals can be useful if your React root is only part of a static or server-rend
252252
253253
<Sandpack>
254254
255-
```html index.html
255+
```html public/index.html
256256
<!DOCTYPE html>
257257
<html>
258258
<head><title>My app</title></head>

src/content/reference/react/useId.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ If you render multiple independent React applications on a single page, pass `id
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)