mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Disallow /index.html in sandboxes (#7430)
This commit is contained in:
committed by
GitHub
parent
316230adfc
commit
ee8a829f99
@@ -71,6 +71,13 @@ function SandpackRoot(props: SandpackProps) {
|
||||
const codeSnippets = Children.toArray(children) as React.ReactElement[];
|
||||
const files = createFileMap(codeSnippets);
|
||||
|
||||
if ('/index.html' in files) {
|
||||
throw new Error(
|
||||
'You cannot use `index.html` file in sandboxes. ' +
|
||||
'Only `public/index.html` is respected by Sandpack and CodeSandbox (where forks are created).'
|
||||
);
|
||||
}
|
||||
|
||||
files['/src/styles.css'] = {
|
||||
code: [sandboxStyle, files['/src/styles.css']?.code ?? ''].join('\n\n'),
|
||||
hidden: !files['/src/styles.css']?.visible,
|
||||
|
||||
@@ -57,12 +57,13 @@ Then add these lines of code at the top of your main JavaScript file (it might b
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>My app</title></head>
|
||||
<body>
|
||||
<!-- Your existing page content (in this example, it gets replaced) -->
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
@@ -119,7 +120,7 @@ This lets you find that HTML element with [`document.getElementById`](https://de
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html
|
||||
```html public/index.html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>My app</title></head>
|
||||
|
||||
@@ -144,7 +144,7 @@ Usually, you only need to run this code once at startup. It will:
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html
|
||||
```html public/index.html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>My app</title></head>
|
||||
@@ -375,7 +375,7 @@ You can use the `onUncaughtError` root option to display error dialogs:
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -606,7 +606,7 @@ You can use the `onCaughtError` root option to display error dialogs or filter k
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -885,7 +885,7 @@ You can use the `onRecoverableError` root option to display error dialogs:
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@@ -406,7 +406,7 @@ You can use the `onUncaughtError` root option to display error dialogs:
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -641,7 +641,7 @@ You can use the `onCaughtError` root option to display error dialogs or filter k
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -922,7 +922,7 @@ You can use the `onRecoverableError` root option to display error dialogs for hy
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html hidden
|
||||
```html public/index.html hidden
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@@ -252,7 +252,7 @@ Portals can be useful if your React root is only part of a static or server-rend
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html
|
||||
```html public/index.html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>My app</title></head>
|
||||
|
||||
@@ -226,7 +226,7 @@ If you render multiple independent React applications on a single page, pass `id
|
||||
|
||||
<Sandpack>
|
||||
|
||||
```html index.html
|
||||
```html public/index.html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>My app</title></head>
|
||||
|
||||
Reference in New Issue
Block a user