Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with react.dev @ 315cb7a3 #934

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d3a5f8a
Capitalize word "Fragment" (#6425)
Huxpro Nov 14, 2023
4f9e9a5
Capitalize word "Canary" (#6427)
Huxpro Nov 14, 2023
aa0c547
Fix: incorrect sample code in documentation related to Server action …
nonoakij Nov 21, 2023
6570e6c
Update useSyncExternalStore.md
sophiebits Nov 23, 2023
943e3ce
Captailize "Strict Mode" (#6426)
Huxpro Nov 30, 2023
b1c4b4e
useId add server rendering usage and server api add options (#6457)
2239559319 Dec 5, 2023
4226fbf
Edits to useId doc (#6464)
gaearon Dec 5, 2023
b9bf666
Oops
gaearon Dec 5, 2023
ae4be84
Fix Next JS link (#6467)
budmc29 Dec 6, 2023
af54fc8
Link to the new Next.js tutorial instead (#6468)
AhmedBaset Dec 6, 2023
bec75ca
Update useSyncExternalStore.md: tweak link
sophiebits Dec 13, 2023
e98c393
fix(sandpack-template): use custom react sandpack template (#6484)
danilowoz Dec 13, 2023
01e80fd
Add React India 2024 conference (#6481)
ehteshamdev0 Dec 15, 2023
e3c25d1
data: add react mumbai meetup (#6396)
ehteshamdev0 Dec 15, 2023
bb65ace
Fix #6487 specify which `Sandpack` files go into a `src` directory (#…
geeseyj Dec 15, 2023
d0a50e8
fix sandpack ts (#6498)
harish-sethuraman Dec 16, 2023
303ecae
Update startTransition.md (#6431)
prajwalkulkarni Dec 16, 2023
9ce4afe
Improve documentation for __html (#6499)
Daniel15 Dec 20, 2023
3bf64e5
Fix diagram alt text in Your UI as a Tree page (#6507)
alinkedd Dec 21, 2023
3009d76
Fix error throw and for useTransition demo (#6510)
lunaleaps Dec 21, 2023
bbb08a5
Add Turkish to deployed languages (#6449)
alioguzhan Dec 21, 2023
fc32af8
Text Display error in Go full-stack with a framework (#6483)
nepalivai Jan 5, 2024
7a28cf6
Fix missing function keyword (#6527)
AhmedBaset Jan 5, 2024
315cb7a
fix wrong quotes around inline codes (#6523)
2wheeh Jan 7, 2024
9eb9c77
merging all conflicts
react-translations-bot Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions plugins/remark-smartypants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*!
* Based on 'silvenon/remark-smartypants'
* https://github.com/silvenon/remark-smartypants/pull/80
*/

const visit = require('unist-util-visit');
const retext = require('retext');
const smartypants = require('retext-smartypants');
Expand All @@ -9,12 +14,48 @@ function check(parent) {
}

module.exports = function (options) {
const processor = retext().use(smartypants, options);
const processor = retext().use(smartypants, {
...options,
// Do not replace ellipses, dashes, backticks because they change string
// length, and we couldn't guarantee right splice of text in second visit of
// tree
ellipses: false,
dashes: false,
backticks: false,
});

const processor2 = retext().use(smartypants, {
...options,
// Do not replace quotes because they are already replaced in the first
// processor
quotes: false,
});

function transformer(tree) {
visit(tree, 'text', (node, index, parent) => {
if (check(parent)) node.value = String(processor.processSync(node.value));
let allText = '';
let startIndex = 0;
const textOrInlineCodeNodes = [];

visit(tree, ['text', 'inlineCode'], (node, _, parent) => {
if (check(parent)) {
if (node.type === 'text') allText += node.value;
// for the case when inlineCode contains just one part of quote: `foo'bar`
else allText += 'A'.repeat(node.value.length);
textOrInlineCodeNodes.push(node);
}
});

// Concat all text into one string, to properly replace quotes around non-"text" nodes
allText = String(processor.processSync(allText));

for (const node of textOrInlineCodeNodes) {
const endIndex = startIndex + node.value.length;
if (node.type === 'text') {
const processedText = allText.slice(startIndex, endIndex);
node.value = String(processor2.processSync(processedText));
}
startIndex = endIndex;
}
}

return transformer;
Expand Down
14 changes: 11 additions & 3 deletions src/components/Layout/HomeContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ function ConferenceLayout({conf, children}) {
navigate(e.target.value);
});
}}
className="appearance-none pe-8 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
className="appearance-none pe-8 ps-2 bg-transparent text-primary-dark text-2xl font-bold mb-0.5"
style={{
backgroundSize: '4px 4px, 4px 4px',
backgroundRepeat: 'no-repeat',
Expand All @@ -1508,8 +1508,16 @@ function ConferenceLayout({conf, children}) {
backgroundImage:
'linear-gradient(45deg,transparent 50%,currentColor 50%),linear-gradient(135deg,currentColor 50%,transparent 50%)',
}}>
<option value="react-conf-2021">React Conf 2021</option>
<option value="react-conf-2019">React Conf 2019</option>
<option
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
value="react-conf-2021">
React Conf 2021
</option>
<option
className="bg-wash dark:bg-wash-dark text-primary dark:text-primary-dark"
value="react-conf-2019">
React Conf 2019
</option>
</select>
</Cover>
<div className="px-4 pb-4" key={conf.id}>
Expand Down
7 changes: 3 additions & 4 deletions src/components/MDX/Sandpack/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {useSyncExternalStore} from 'react';
import {useSandpack} from '@codesandbox/sandpack-react/unstyled';
import {IconDownload} from '../../Icon/IconDownload';
import {AppJSPath, StylesCSSPath, SUPPORTED_FILES} from './createFileMap';
export interface DownloadButtonProps {}

let supportsImportMap = false;
Expand Down Expand Up @@ -32,8 +33,6 @@ function useSupportsImportMap() {
return useSyncExternalStore(subscribe, getCurrentValue, getServerSnapshot);
}

const SUPPORTED_FILES = ['/App.js', '/styles.css'];

export function DownloadButton({
providedFiles,
}: {
Expand All @@ -49,8 +48,8 @@ export function DownloadButton({
}

const downloadHTML = () => {
const css = sandpack.files['/styles.css']?.code ?? '';
const code = sandpack.files['/App.js']?.code ?? '';
const css = sandpack.files[StylesCSSPath]?.code ?? '';
const code = sandpack.files[AppJSPath]?.code ?? '';
const blob = new Blob([
`<!DOCTYPE html>
<html>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MDX/Sandpack/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function Preview({

// When throwing a new Error in Sandpack - we want to disable the dev error dialog
// to show the Error Boundary fallback
if (rawError && rawError.message.includes(`throw Error('Example error')`)) {
if (rawError && rawError.message.includes('Example Error:')) {
rawError = null;
}

Expand Down
13 changes: 8 additions & 5 deletions src/components/MDX/Sandpack/SandpackRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SandpackLogLevel} from '@codesandbox/sandpack-client';
import {CustomPreset} from './CustomPreset';
import {createFileMap} from './createFileMap';
import {CustomTheme} from './Themes';
import {template} from './template';

type SandpackProps = {
children: React.ReactNode;
Expand Down Expand Up @@ -70,17 +71,19 @@ function SandpackRoot(props: SandpackProps) {
const codeSnippets = Children.toArray(children) as React.ReactElement[];
const files = createFileMap(codeSnippets);

files['/styles.css'] = {
code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'),
hidden: !files['/styles.css']?.visible,
files['/src/styles.css'] = {
code: [sandboxStyle, files['/src/styles.css']?.code ?? ''].join('\n\n'),
hidden: !files['/src/styles.css']?.visible,
};

return (
<div className="sandpack sandpack--playground w-full my-8" dir="ltr">
<SandpackProvider
template="react"
files={files}
files={{...template, ...files}}
theme={CustomTheme}
customSetup={{
environment: 'create-react-app',
}}
options={{
autorun,
initMode: 'user-visible',
Expand Down
9 changes: 7 additions & 2 deletions src/components/MDX/Sandpack/createFileMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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

export const AppJSPath = `/src/App.js`;
export const StylesCSSPath = `/src/styles.css`;
export const SUPPORTED_FILES = [AppJSPath, StylesCSSPath];

export const createFileMap = (codeSnippets: any) => {
return codeSnippets.reduce(
(result: Record<string, SandpackFile>, codeSnippet: React.ReactElement) => {
Expand All @@ -26,15 +30,16 @@ export const createFileMap = (codeSnippets: any) => {
}
} else {
if (props.className === 'language-js') {
filePath = '/App.js';
filePath = AppJSPath;
} else if (props.className === 'language-css') {
filePath = '/styles.css';
filePath = StylesCSSPath;
} else {
throw new Error(
`Code block is missing a filename: ${props.children}`
);
}
}

if (result[filePath]) {
throw new Error(
`File ${filePath} was defined multiple times. Each file snippet should have a unique path name`
Expand Down
4 changes: 2 additions & 2 deletions src/components/MDX/Sandpack/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import {lazy, memo, Children, Suspense} from 'react';
import {createFileMap} from './createFileMap';
import {AppJSPath, createFileMap} from './createFileMap';

const SandpackRoot = lazy(() => import('./SandpackRoot'));

Expand Down Expand Up @@ -57,7 +57,7 @@ export default memo(function SandpackWrapper(props: any): any {
);
let activeCode;
if (!activeCodeSnippet.length) {
activeCode = codeSnippet['/App.js'].code;
activeCode = codeSnippet[AppJSPath].code;
} else {
activeCode = codeSnippet[activeCodeSnippet[0]].code;
}
Expand Down
54 changes: 54 additions & 0 deletions src/components/MDX/Sandpack/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const template = {
'/src/index.js': {
hidden: true,
code: `import React, { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./styles.css";

import App from "./App";

const root = createRoot(document.getElementById("root"));
root.render(
<StrictMode>
<App />
</StrictMode>
);`,
},
'/package.json': {
hidden: true,
code: JSON.stringify(
{
name: 'react.dev',
version: '0.0.0',
main: '/src/index.js',
scripts: {
start: 'react-scripts start',
build: 'react-scripts build',
test: 'react-scripts test --env=jsdom',
eject: 'react-scripts eject',
},
dependencies: {
react: '^18.0.0',
'react-dom': '^18.0.0',
'react-scripts': '^5.0.0',
},
},
null,
2
),
},
'/public/index.html': {
hidden: true,
code: `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root"></div>
</body>
</html>`,
},
};
1 change: 1 addition & 0 deletions src/components/Seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const deployedTranslations = [
'es',
'fr',
'ja',
'tr',
// We'll add more languages when they have enough content.
// Please DO NOT edit this list without a discussion in the reactjs/react.dev repo.
// It must be the same between all translations.
Expand Down
7 changes: 3 additions & 4 deletions src/content/blog/2023/03/16/introducing-react-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If you like to learn by doing, we recommend checking out the [Tic-Tac-Toe Tutori

<Sandpack>

```js App.js
```js src/App.js
import { useState } from 'react';

function Square({ value, onSquareClick }) {
Expand Down Expand Up @@ -175,7 +175,7 @@ function calculateWinner(squares) {
}
```

```css styles.css
```css src/styles.css
* {
box-sizing: border-box;
}
Expand Down Expand Up @@ -428,7 +428,7 @@ export default function PackingList() {

Note that you must write `importance > 0 && ...` rather than `importance && ...` so that if the `importance` is `0`, `0` isn't rendered as the result!

In this solution, two separate conditions are used to insert a space between then name and the importance label. Alternatively, you could use a fragment with a leading space: `importance > 0 && <> <i>...</i></>` or add a space immediately inside the `<i>`: `importance > 0 && <i> ...</i>`.
In this solution, two separate conditions are used to insert a space between then name and the importance label. Alternatively, you could use a Fragment with a leading space: `importance > 0 && <> <i>...</i></>` or add a space immediately inside the `<i>`: `importance > 0 && <i> ...</i>`.

</Solution>

Expand Down Expand Up @@ -643,4 +643,3 @@ On the development front, thanks to [Jared Palmer](https://twitter.com/jaredpalm
Huge thanks to the folks who volunteered their time to participate in the alpha and beta testing program. Your enthusiasm and invaluable feedback helped us shape these docs. A special shout out to our beta tester, [Debbie O'Brien](https://twitter.com/debs_obrien), who gave a talk about her experience using the React docs at React Conf 2021.

Finally, thanks to the React community for being the inspiration behind this effort. You are the reason we do this, and we hope that the new docs will help you use React to build any user interface that you want.

Loading
Loading