Skip to content

Commit b66648d

Browse files
Merge branch 'main' of https://github.com/reactjs/react.dev into sync-9aa84b19
2 parents 9e91ec7 + 9aa84b1 commit b66648d

16 files changed

+386
-18
lines changed

src/content/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ June 15, 2022 by [Andrew Clark](https://twitter.com/acdlite), [Dan Abramov](http
88

99
<Intro>
1010

11-
[React 18](https://reactjs.org/blog/2022/03/29/react-v18) was years in the making, and with it brought valuable lessons for the React team. Its release was the result of many years of research and exploring many paths. Some of those paths were successful; many more were dead-ends that led to new insights. One lesson we’ve learned is that it’s frustrating for the community to wait for new features without having insight into these paths that we’re exploring.
11+
[React 18](https://react.dev/blog/2022/03/29/react-v18) was years in the making, and with it brought valuable lessons for the React team. Its release was the result of many years of research and exploring many paths. Some of those paths were successful; many more were dead-ends that led to new insights. One lesson we’ve learned is that it’s frustrating for the community to wait for new features without having insight into these paths that we’re exploring.
1212

1313
</Intro>
1414

src/content/community/conferences.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ October 27th 2023. In-person in Verona, Italy and online (hybrid event)
6161

6262
[Website](https://2023.reactjsday.it/) - [Twitter](https://twitter.com/reactjsday) - [Facebook](https://www.facebook.com/GrUSP/) - [YouTube](https://www.youtube.com/c/grusp)
6363

64-
6564
### React Summit US 2023 {/*react-summit-us-2023*/}
6665
November 13 & 15, 2023. In-person in New York, US + remote first interactivity (hybrid event)
6766

@@ -72,6 +71,11 @@ December 8 & 12, 2023. In-person in Berlin, Germany + remote first interactivity
7271

7372
[Website](https://reactday.berlin) - [Twitter](https://twitter.com/reactdayberlin) - [Facebook](https://www.facebook.com/reactdayberlin/) - [Videos](https://portal.gitnation.org/events/react-day-berlin-2023)
7473

74+
### App.js Conf 2024 {/*appjs-conf-2024*/}
75+
May 22 - 24, 2024. In-person in Kraków, Poland + remote
76+
77+
[Website](https://appjs.co) - [Twitter](https://twitter.com/appjsconf)
78+
7579
### Render(ATL) 2024 🍑 {/*renderatl-2024-*/}
7680
June 12 - June 14, 2024. Atlanta, GA, USA
7781

src/content/learn/referencing-values-with-refs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ You also don't need to worry about [avoiding mutation](/learn/updating-objects-i
284284

285285
## Refs and the DOM {/*refs-and-the-dom*/}
286286

287-
You can point a ref to any value. However, the most common use case for a ref is to access a DOM element. For example, this is handy if you want to focus an input programmatically. When you pass a ref to a `ref` attribute in JSX, like `<div ref={myRef}>`, React will put the corresponding DOM element into `myRef.current`. You can read more about this in [Manipulating the DOM with Refs.](/learn/manipulating-the-dom-with-refs)
287+
You can point a ref to any value. However, the most common use case for a ref is to access a DOM element. For example, this is handy if you want to focus an input programmatically. When you pass a ref to a `ref` attribute in JSX, like `<div ref={myRef}>`, React will put the corresponding DOM element into `myRef.current`. Once the element is removed from the DOM, React will update `myRef.current` to be `null`. You can read more about this in [Manipulating the DOM with Refs.](/learn/manipulating-the-dom-with-refs)
288288

289289
<Recap>
290290

src/content/learn/rendering-lists.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ Here, `<Recipe {...recipe} key={recipe.id} />` is a syntax shortcut saying "pass
10861086

10871087
#### List with a separator {/*list-with-a-separator*/}
10881088

1089-
This example renders a famous haiku by Katsushika Hokusai, with each line wrapped in a `<p>` tag. Your job is to insert an `<hr />` separator between each paragraph. Your resulting structure should look like this:
1089+
This example renders a famous haiku by Tachibana Hokushi, with each line wrapped in a `<p>` tag. Your job is to insert an `<hr />` separator between each paragraph. Your resulting structure should look like this:
10901090

10911091
```js
10921092
<article>

src/content/learn/start-a-new-react-project.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ If you want to build a new app or a new website fully with React, we recommend p
2121
**[Next.js](https://nextjs.org/) is a full-stack React framework.** It's versatile and lets you create React apps of any size--from a mostly static blog to a complex dynamic application. To create a new Next.js project, run in your terminal:
2222

2323
<TerminalBlock>
24-
npx create-next-app
24+
npx create-next-app@latest
2525
</TerminalBlock>
2626

2727
If you're new to Next.js, check out the [Next.js tutorial.](https://nextjs.org/learn/foundations/about-nextjs)
2828

29-
Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/deployment) to any Node.js or serverless hosting, or to your own server. [Fully static Next.js apps](https://nextjs.org/docs/advanced-features/static-html-export) can be deployed to any static hosting.
29+
Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/app/building-your-application/deploying) to any Node.js or serverless hosting, or to your own server. Next.js also supports a [static export](https://nextjs.org/docs/pages/building-your-application/deploying/static-exports) which doesn't require a server.
3030

3131
### Remix {/*remix*/}
3232

@@ -89,14 +89,9 @@ These features are getting closer to being production-ready every day, and we've
8989

9090
### Next.js (App Router) {/*nextjs-app-router*/}
9191

92-
**[Next.js's App Router](https://beta.nextjs.org/docs/getting-started) is a redesign of the Next.js APIs aiming to fulfill the React team’s full-stack architecture vision.** It lets you fetch data in asynchronous components that run on the server or even during the build.
92+
**[Next.js's App Router](https://nextjs.org/docs) is a redesign of the Next.js APIs aiming to fulfill the React team’s full-stack architecture vision.** It lets you fetch data in asynchronous components that run on the server or even during the build.
9393

94-
Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/deployment) to any Node.js or serverless hosting, or to your own server. Next.js also supports [static export](https://beta.nextjs.org/docs/configuring/static-export) which doesn't require a server.
95-
<Pitfall>
96-
97-
Next.js's App Router is **currently in beta and is not yet recommended for production** (as of Mar 2023). To experiment with it in an existing Next.js project, [follow this incremental migration guide](https://beta.nextjs.org/docs/upgrade-guide#migrating-from-pages-to-app).
98-
99-
</Pitfall>
94+
Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/app/building-your-application/deploying) to any Node.js or serverless hosting, or to your own server. Next.js also supports [static export](https://nextjs.org/docs/app/building-your-application/deploying/static-exports) which doesn't require a server.
10095

10196
<DeepDive>
10297

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,13 @@ export default function Game() {
20732073
}
20742074
```
20752075
2076-
You can see what your code should look like below. Note that you should see an error in the developer tools console that says: ``Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `Game`.`` You'll fix this error in the next section.
2076+
You can see what your code should look like below. Note that you should see an error in the developer tools console that says:
2077+
2078+
<ConsoleBlock level="warning">
2079+
Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of &#96;Game&#96;.
2080+
</ConsoleBlock>
2081+
2082+
You'll fix this error in the next section.
20772083
20782084
<Sandpack>
20792085

src/content/reference/react-dom/server/renderToPipeableStream.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ Streaming does not need to wait for React itself to load in the browser, or for
288288
289289
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
290290
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
291+
- Reading the value of a Promise with [`use`](/reference/react/use)
291292
292293
Suspense **does not** detect when data is fetched inside an Effect or event handler.
293294

src/content/reference/react-dom/server/renderToReadableStream.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Streaming does not need to wait for React itself to load in the browser, or for
287287
288288
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
289289
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
290+
- Reading the value of a Promise with [`use`](/reference/react/use)
290291
291292
Suspense **does not** detect when data is fetched inside an Effect or event handler.
292293

src/content/reference/react/Profiler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function onRender(id, phase, actualDuration, baseDuration, startTime, commitTime
5858
* `actualDuration`: The number of milliseconds spent rendering the `<Profiler>` and its descendants for the current update. This indicates how well the subtree makes use of memoization (e.g. [`memo`](/reference/react/memo) and [`useMemo`](/reference/react/useMemo)). Ideally this value should decrease significantly after the initial mount as many of the descendants will only need to re-render if their specific props change.
5959
* `baseDuration`: The number of milliseconds estimating how much time it would take to re-render the entire `<Profiler>` subtree without any optimizations. It is calculated by summing up the most recent render durations of each component in the tree. This value estimates a worst-case cost of rendering (e.g. the initial mount or a tree with no memoization). Compare `actualDuration` against it to see if memoization is working.
6060
* `startTime`: A numeric timestamp for when React began rendering the current update.
61-
* `endTime`: A numeric timestamp for when React committed the current update. This value is shared between all profilers in a commit, enabling them to be grouped if desirable.
61+
* `commitTime`: A numeric timestamp for when React committed the current update. This value is shared between all profilers in a commit, enabling them to be grouped if desirable.
6262

6363
---
6464

src/content/reference/react/Suspense.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ async function getAlbums() {
254254

255255
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
256256
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
257+
- Reading the value of a Promise with [`use`](/reference/react/use)
257258

258259
Suspense **does not** detect when data is fetched inside an Effect or event handler.
259260

src/content/reference/react/cache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ See prior mentioned pitfalls
414414
415415
If none of the above apply, it may be a problem with how React checks if something exists in cache.
416416
417-
If your arguments are not [primatives](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) (ex. objects, functions, arrays), ensure you're passing the same object reference.
417+
If your arguments are not [primitives](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) (ex. objects, functions, arrays), ensure you're passing the same object reference.
418418
419419
When calling a memoized function, React will look up the input arguments to see if a result is already cached. React will use shallow equality of the arguments to determine if there is a cache hit.
420420
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
title: experimental_taintObjectReference
3+
---
4+
5+
<Wip>
6+
7+
**This API is experimental and is not available in a stable version of React yet.**
8+
9+
You can try it by upgrading React packages to the most recent experimental version:
10+
11+
- `react@experimental`
12+
- `react-dom@experimental`
13+
- `eslint-plugin-react-hooks@experimental`
14+
15+
Experimental versions of React may contain bugs. Don't use them in production.
16+
17+
This API is only available inside React Server Components.
18+
19+
</Wip>
20+
21+
22+
<Intro>
23+
24+
`taintObjectReference` lets you prevent a specific object instance from being passed to a Client Component like a `user` object.
25+
26+
```js
27+
experimental_taintObjectReference(message, object);
28+
```
29+
30+
To prevent passing a key, hash or token, see [`taintUniqueValue`](/reference/react/experimental_taintUniqueValue).
31+
32+
</Intro>
33+
34+
<InlineToc />
35+
36+
---
37+
38+
## Reference {/*reference*/}
39+
40+
### `taintObjectReference(message, object)` {/*taintobjectreference*/}
41+
42+
Call `taintObjectReference` with an object to register it with React as something that should not be allowed to be passed to the Client as is:
43+
44+
```js
45+
import {experimental_taintObjectReference} from 'react';
46+
47+
experimental_taintObjectReference(
48+
'Do not pass ALL environment variables to the client.',
49+
process.env
50+
);
51+
```
52+
53+
[See more examples below.](#usage)
54+
55+
#### Parameters {/*parameters*/}
56+
57+
* `message`: The message you want to display if the object gets passed to a Client Component. This message will be displayed as a part of the Error that will be thrown if the object gets passed to a Client Component.
58+
59+
* `object`: The object to be tainted. Functions and class instances can be passed to `taintObjectReference` as `object`. Functions and classes are already blocked from being passed to Client Components but the React's default error message will be replaced by what you defined in `message`. When a specific instance of a Typed Array is passed to `taintObjectReference` as `object`, any other copies of the Typed Array will not be tainted.
60+
61+
#### Returns {/*returns*/}
62+
63+
`experimental_taintObjectReference` returns `undefined`.
64+
65+
#### Caveats {/*caveats*/}
66+
67+
- Recreating or cloning a tainted object creates a new untained object which main contain sensetive data. For example, if you have a tainted `user` object, `const userInfo = {name: user.name, ssn: user.ssn}` or `{...user}` will create new objects which are not tainted. `taintObjectReference` only protects against simple mistakes when the object is passed through to a Client Component unchanged.
68+
69+
<Pitfall>
70+
71+
**Do not rely on just tainting for security.** Tainting an object doesn't prevent leaking of every possible derived value. For example, the clone of a tainted object will create a new untained object. Using data from a tainted object (e.g. `{secret: taintedObj.secret}`) will create a new value or object that is not tainted. Tainting is a layer of protection, a secure app will have multiple layers of protection, well designed APIs, and isolation patterns.
72+
73+
</Pitfall>
74+
75+
---
76+
77+
## Usage {/*usage*/}
78+
79+
### Prevent user data from unintentionally reaching the client {/*prevent-user-data-from-unintentionally-reaching-the-client*/}
80+
81+
A Client Component should never accept objects that carry sensitive data. Ideally, the data fetching functions should not expose data that the current user should not have access to. Sometimes mistakes happen during refactoring. To protect against this mistakes happening down the line we can "taint" the user object in our data API.
82+
83+
```js
84+
import {experimental_taintObjectReference} from 'react';
85+
86+
export async function getUser(id) {
87+
const user = await db`SELECT * FROM users WHERE id = ${id}`;
88+
experimental_taintObjectReference(
89+
'Do not pass the entire user object to the client. ' +
90+
'Instead, pick off the specific properties you need for this use case.',
91+
user,
92+
);
93+
return user;
94+
}
95+
```
96+
97+
Now whenever anyone tries to pass this object to a Client Component, an error will be thrown with the passed in error message instead.
98+
99+
<DeepDive>
100+
101+
#### Protecting against leaks in data fetching {/*protecting-against-leaks-in-data-fetching*/}
102+
103+
If you're running a Server Components environment that has access to sensitive data, you have to be careful not to pass objects straight through:
104+
105+
```js
106+
// api.js
107+
export async function getUser(id) {
108+
const user = await db`SELECT * FROM users WHERE id = ${id}`;
109+
return user;
110+
}
111+
```
112+
113+
```js
114+
import { getUser } from 'api.js';
115+
import { InfoCard } from 'components.js';
116+
117+
export async function Profile(props) {
118+
const user = await getUser(props.userId);
119+
// DO NOT DO THIS
120+
return <InfoCard user={user} />;
121+
}
122+
```
123+
124+
```js
125+
// components.js
126+
"use client";
127+
128+
export async function InfoCard({ user }) {
129+
return <div>{user.name}</div>;
130+
}
131+
```
132+
133+
Ideally, the `getUser` should not expose data that the current user should not have access to. To prevent passing the `user` object to a Client Component down the line we can "taint" the user object:
134+
135+
136+
```js
137+
// api.js
138+
import {experimental_taintObjectReference} from 'react';
139+
140+
export async function getUser(id) {
141+
const user = await db`SELECT * FROM users WHERE id = ${id}`;
142+
experimental_taintObjectReference(
143+
'Do not pass the entire user object to the client. ' +
144+
'Instead, pick off the specific properties you need for this use case.',
145+
user,
146+
);
147+
return user;
148+
}
149+
```
150+
151+
Now if anyone tries to pass the `user` object to a Client Component, an error will be thrown with the passed in error message.
152+
153+
</DeepDive>

0 commit comments

Comments
 (0)