-
Notifications
You must be signed in to change notification settings - Fork 3
V18 2 0 with memory fixes #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
59e67b6
14fc45b
420c6ed
c90e906
b83b7f1
7a0e553
0c257b7
1a5f4df
886470e
4aa3196
4c90ad0
f093109
8072a50
61864a8
07c5260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,60 @@ | ||
# [React](https://reactjs.org/) · [](https://github.com/facebook/react/blob/main/LICENSE) [](https://www.npmjs.com/package/react) [](https://circleci.com/gh/facebook/react) [](https://reactjs.org/docs/how-to-contribute.html#your-first-pull-request) | ||
# `react-dom` | ||
|
||
React is a JavaScript library for building user interfaces. | ||
|
||
* **Declarative:** React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable, simpler to understand, and easier to debug. | ||
* **Component-Based:** Build encapsulated components that manage their state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep the state out of the DOM. | ||
* **Learn Once, Write Anywhere:** We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using [React Native](https://reactnative.dev/). | ||
|
||
[Learn how to use React in your project](https://reactjs.org/docs/getting-started.html). | ||
This package serves as the entry point to the DOM and server renderers for React. It is intended to be paired with the generic React package, which is shipped as `react` to npm. | ||
|
||
## Installation | ||
|
||
React has been designed for gradual adoption from the start, and **you can use as little or as much React as you need**: | ||
|
||
* Use [Online Playgrounds](https://reactjs.org/docs/getting-started.html#online-playgrounds) to get a taste of React. | ||
* [Add React to a Website](https://reactjs.org/docs/add-react-to-a-website.html) as a `<script>` tag in one minute. | ||
* [Create a New React App](https://reactjs.org/docs/create-a-new-react-app.html) if you're looking for a powerful JavaScript toolchain. | ||
|
||
You can use React as a `<script>` tag from a [CDN](https://reactjs.org/docs/cdn-links.html), or as a `react` package on [npm](https://www.npmjs.com/package/react). | ||
|
||
## Documentation | ||
|
||
You can find the React documentation [on the website](https://reactjs.org/). | ||
|
||
Check out the [Getting Started](https://reactjs.org/docs/getting-started.html) page for a quick overview. | ||
|
||
The documentation is divided into several sections: | ||
|
||
* [Tutorial](https://reactjs.org/tutorial/tutorial.html) | ||
* [Main Concepts](https://reactjs.org/docs/hello-world.html) | ||
* [Advanced Guides](https://reactjs.org/docs/jsx-in-depth.html) | ||
* [API Reference](https://reactjs.org/docs/react-api.html) | ||
* [Where to Get Support](https://reactjs.org/community/support.html) | ||
* [Contributing Guide](https://reactjs.org/docs/how-to-contribute.html) | ||
|
||
You can improve it by sending pull requests to [this repository](https://github.com/reactjs/reactjs.org). | ||
```sh | ||
npm install react react-dom | ||
``` | ||
|
||
## Examples | ||
## Usage | ||
|
||
We have several examples [on the website](https://reactjs.org/). Here is the first one to get you started: | ||
### In the browser | ||
|
||
```jsx | ||
```js | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
function HelloMessage({ name }) { | ||
return <div>Hello {name}</div>; | ||
function App() { | ||
return <div>Hello World</div>; | ||
} | ||
|
||
const root = createRoot(document.getElementById('container')); | ||
root.render(<HelloMessage name="Taylor" />); | ||
const root = createRoot(document.getElementById('root')); | ||
root.render(<App />); | ||
``` | ||
|
||
This example will render "Hello Taylor" into a container on the page. | ||
|
||
You'll notice that we used an HTML-like syntax; [we call it JSX](https://reactjs.org/docs/introducing-jsx.html). JSX is not required to use React, but it makes code more readable and writing it feels like writing HTML. If you're using React as a `<script>` tag, read [this section](https://reactjs.org/docs/add-react-to-a-website.html#optional-try-react-with-jsx) on integrating JSX; otherwise, the [recommended JavaScript toolchains](https://reactjs.org/docs/create-a-new-react-app.html) handle it automatically. | ||
### On the server | ||
|
||
## Contributing | ||
```js | ||
import { renderToPipeableStream } from 'react-dom/server'; | ||
|
||
The main purpose of this repository is to continue evolving React core, making it faster and easier to use. Development of React happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React. | ||
function App() { | ||
return <div>Hello World</div>; | ||
} | ||
|
||
### [Code of Conduct](https://code.fb.com/codeofconduct) | ||
function handleRequest(res) { | ||
// ... in your server handler ... | ||
const stream = renderToPipeableStream(<App />, { | ||
onShellReady() { | ||
res.statusCode = 200; | ||
res.setHeader('Content-type', 'text/html'); | ||
stream.pipe(res); | ||
}, | ||
// ... | ||
}); | ||
} | ||
``` | ||
|
||
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read [the full text](https://code.fb.com/codeofconduct) so that you can understand what actions will and will not be tolerated. | ||
## API | ||
|
||
### [Contributing Guide](https://reactjs.org/docs/how-to-contribute.html) | ||
### `react-dom` | ||
|
||
Read our [contributing guide](https://reactjs.org/docs/how-to-contribute.html) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React. | ||
See https://reactjs.org/docs/react-dom.html | ||
|
||
### Good First Issues | ||
### `react-dom/client` | ||
|
||
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first issues](https://github.com/facebook/react/labels/good%20first%20issue) that contain bugs that have a relatively limited scope. This is a great place to get started. | ||
See https://reactjs.org/docs/react-dom-client.html | ||
|
||
### License | ||
### `react-dom/server` | ||
|
||
React is [MIT licensed](./LICENSE). | ||
See https://reactjs.org/docs/react-dom-server.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,4 +150,4 @@ | |
"resolutions": { | ||
"react-is": "npm:react-is" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,11 +47,35 @@ export function detachDeletedInstance(node: Instance): void { | |
// these fields are relevant. | ||
delete (node: any)[internalInstanceKey]; | ||
delete (node: any)[internalPropsKey]; | ||
delete (node: any)[internalContainerInstanceKey]; | ||
delete (node: any)[internalEventHandlersKey]; | ||
delete (node: any)[internalEventHandlerListenersKey]; | ||
delete (node: any)[internalEventHandlesSetKey]; | ||
} | ||
|
||
function _tagIsDetachable(tag: number): boolean { | ||
if (tag == null) { | ||
return false; | ||
} | ||
return tag === HostComponent || tag === HostText; | ||
} | ||
|
||
export function detatchFiberStateNode( | ||
fiberToDetach: Fiber, | ||
) { | ||
if (_tagIsDetachable(fiberToDetach.tag)) { | ||
const hostInstance: Instance = fiberToDetach.stateNode; | ||
if (hostInstance !== null) { | ||
detachDeletedInstance(hostInstance); | ||
} | ||
} | ||
fiberToDetach.stateNode = null; | ||
|
||
if (fiberToDetach.alternate !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding, |
||
detatchFiberStateNode(fiberToDetach.alternate) | ||
} | ||
} | ||
|
||
export function precacheFiberNode( | ||
hostInst: Fiber, | ||
node: Instance | TextInstance | SuspenseInstance | ReactScopeInstance, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,6 @@ import { | |
CacheComponent, | ||
TracingMarkerComponent, | ||
} from './ReactWorkTags'; | ||
import {detachDeletedInstance} from './ReactFiberHostConfig'; | ||
import { | ||
NoFlags, | ||
ContentReset, | ||
|
@@ -130,6 +129,7 @@ import { | |
prepareScopeUpdate, | ||
prepareForCommit, | ||
beforeActiveInstanceBlur, | ||
detatchFiberStateNode, | ||
} from './ReactFiberHostConfig'; | ||
import { | ||
captureCommitPhaseError, | ||
|
@@ -1335,6 +1335,12 @@ function detachFiberMutation(fiber: Fiber) { | |
} | ||
|
||
function detachFiberAfterEffects(fiber: Fiber) { | ||
// The `stateNode` is cyclical because on host nodes it points to the host | ||
// tree, which has its own pointers to children, parents, and siblings. | ||
// The other host nodes also point back to fibers, so we should detach that | ||
// one, too. | ||
detatchFiberStateNode(fiber); | ||
|
||
const alternate = fiber.alternate; | ||
if (alternate !== null) { | ||
fiber.alternate = null; | ||
|
@@ -1369,18 +1375,6 @@ function detachFiberAfterEffects(fiber: Fiber) { | |
fiber.deletions = null; | ||
fiber.sibling = null; | ||
|
||
// The `stateNode` is cyclical because on host nodes it points to the host | ||
// tree, which has its own pointers to children, parents, and siblings. | ||
// The other host nodes also point back to fibers, so we should detach that | ||
// one, too. | ||
if (fiber.tag === HostComponent) { | ||
const hostInstance: Instance = fiber.stateNode; | ||
if (hostInstance !== null) { | ||
detachDeletedInstance(hostInstance); | ||
} | ||
} | ||
fiber.stateNode = null; | ||
Comment on lines
-1376
to
-1382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. abstracting this to |
||
|
||
// I'm intentionally not clearing the `return` field in this level. We | ||
// already disconnect the `return` pointer at the root of the deleted | ||
// subtree (in `detachFiberMutation`). Besides, `return` by itself is not | ||
|
@@ -1736,7 +1730,7 @@ function commitDeletionEffectsOnFiber( | |
deletedFiber, | ||
); | ||
} | ||
return; | ||
break; | ||
} | ||
case DehydratedFragment: { | ||
if (enableSuspenseCallback) { | ||
|
@@ -1767,7 +1761,7 @@ function commitDeletionEffectsOnFiber( | |
} | ||
} | ||
} | ||
return; | ||
break; | ||
} | ||
case HostPortal: { | ||
if (supportsMutation) { | ||
|
@@ -1792,7 +1786,7 @@ function commitDeletionEffectsOnFiber( | |
deletedFiber, | ||
); | ||
} | ||
return; | ||
break; | ||
} | ||
case FunctionComponent: | ||
case ForwardRef: | ||
|
@@ -1856,7 +1850,7 @@ function commitDeletionEffectsOnFiber( | |
nearestMountedAncestor, | ||
deletedFiber, | ||
); | ||
return; | ||
break; | ||
} | ||
case ClassComponent: { | ||
if (!offscreenSubtreeWasHidden) { | ||
|
@@ -1875,7 +1869,7 @@ function commitDeletionEffectsOnFiber( | |
nearestMountedAncestor, | ||
deletedFiber, | ||
); | ||
return; | ||
break; | ||
} | ||
case ScopeComponent: { | ||
if (enableScopeAPI) { | ||
|
@@ -1886,7 +1880,7 @@ function commitDeletionEffectsOnFiber( | |
nearestMountedAncestor, | ||
deletedFiber, | ||
); | ||
return; | ||
break; | ||
} | ||
case OffscreenComponent: { | ||
if ( | ||
|
@@ -1927,9 +1921,11 @@ function commitDeletionEffectsOnFiber( | |
nearestMountedAncestor, | ||
deletedFiber, | ||
); | ||
return; | ||
break; | ||
} | ||
} | ||
// GC any references to this fibers state node. | ||
detatchFiberStateNode(deletedFiber); | ||
} | ||
function commitSuspenseCallback(finishedWork: Fiber) { | ||
// TODO: Move this to passive phase | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was something we also cleared out in the previous v17 fix, however its not needed imo. This is only set for the container root node (which I think means the root of react's tree). since v17, you can have multiple roots so react can run multiple versions, but I think we only have one root.