A declarative, efficient, and flexible JavaScript library for building user interfaces. reactjs.org
Go to file
Sebastian Markbåge 65b5aae010
[Fizz] Add vt- prefix attributes to annotate <ViewTransition> in HTML (#33206)
Stacked on #33194 and #33200.

When Suspense boundaries reveal during streaming, the Fizz runtime will
be responsible for animating the reveal if necessary (not in this PR).
However, for the future runtime to know what to do it needs to know
about the `<ViewTransition>` configuration to apply.

Ofc, these are virtual nodes that disappear from the HTML. We could
model them as comments like we do with other virtual nodes like Suspense
and Activity. However, that doesn't let us target them with
querySelector and CSS (for no-JS transitions). We also don't have to
model every ViewTransition since not every combination can happen using
only the server runtime. So instead this collapses `<ViewTransition>`
and applies the configuration to the inner DOM nodes.

```js
<ViewTransition name="hi">
  <div />
  <div />
</ViewTransition>
```

Becomes:

```html
<div vt-name="hi" vt-update="auto"></div>
<div vt-name="hi_1" vt-update="auto"></div>
```

I use `vt-` prefix as opposed to `data-` to keep these virtual
attributes away from user specific ones but we're effectively claiming
this namespace.

There are four triggers `vt-update`, `vt-enter`, `vt-exit` and
`vt-share`. The server resolves which ones might apply to this DOM node.
The value represents the class name (after resolving
view-transition-type mappings) or `"auto"` if no specific class name is
needed but this is still a trigger.

The value can also be `"none"`. This is different from missing because
for example an `vt-update="none"` will block mutations inside it from
triggering the boundary where as a missing `vt-update` would bubble up
to be handled by a parent.

`vt-name` is technically only necessary when `vt-share` is specified to
find a pair. However, since an explicit name can also be used to target
specific CSS selectors, we include it even for other cases.

We want to exclude as many of these annotations as possible.

`vt-enter` can only affect the first DOM node inside a Suspense
boundary's content since the reveal would cause it to enter but nothing
deeper inside. Similarly `vt-exit` can only affect the first DOM node
inside a fallback. So for every other case we can exclude them. (For
future MPA ViewTransitions of the whole document it might also be
something we annotate to children inside the `<body>` as well.) Ideally
we'd only include `vt-enter` for Suspense boundaries that actually
flushed a fallback but since we prepare all that content earlier it's
hard to know.

`vt-share` can be anywhere inside an fallback or content. Technically we
don't have to include it outside the root most Suspense boundary or for
boundaries that are inlined into the root shell. However, this is tricky
to detect. It would also not be correct for future MPA ViewTransitions
because in that case the shared scenario can affect anything in the two
documents so it needs to be in every node everywhere which is
effectively what we do. If a `share` class is specified but it has no
explicit name, we can exclude it since it can't match anything.

`vt-update` is only necessary if something below or a sibling might
update like a Suspense boundary. However, since we don't know when
rendering a segment if it'll later asynchronously add a Suspense
boundary later we have to assume that anywhere might have a child. So
these are always included. We collapse to use the inner most one when
directly nested though since that's the one that ends up winning.

There are some weird edge cases that can't be fully modeled by the lack
of virtual nodes.
2025-05-15 01:04:10 -04:00
.codesandbox Build react-server-dom-webpack for codesandbox (#32990) 2025-04-22 22:20:21 +02:00
.github [eslint-plugin-react-hooks] move eslint plugin once again (#33110) 2025-05-02 18:14:56 -04:00
compiler Delete stray file (#33199) 2025-05-14 11:27:36 -04:00
fixtures [Fiber] Trigger default indicator for isomorphic async actions with no root associated (#33190) 2025-05-13 16:10:28 -04:00
packages [Fizz] Add vt- prefix attributes to annotate <ViewTransition> in HTML (#33206) 2025-05-15 01:04:10 -04:00
scripts Implement Navigation API backed default indicator for DOM renderer (#33162) 2025-05-13 16:00:38 -04:00
.editorconfig Remove trim_trailing_whitespace from editorconfig (#31413) 2024-11-04 15:30:02 -05:00
.eslintignore Fix ESLint and Prettier configs for React Compiler (#29073) 2024-05-15 14:02:57 -07:00
.eslintrc.js Implement Navigation API backed default indicator for DOM renderer (#33162) 2025-05-13 16:00:38 -04:00
.git-blame-ignore-revs Add run prettier commit to .git-blame-ignore-revs 2024-07-18 17:42:45 -04:00
.gitattributes .gitattributes to ensure LF line endings when we should 2014-01-17 16:25:53 -08:00
.gitignore [forgive] Init (#31918) 2025-02-25 12:19:11 -05:00
.mailmap updates mailmap entries (#19824) 2020-09-12 13:05:52 -04:00
.nvmrc Upgrade node.js to 20 LTS (#32855) 2025-04-14 12:52:02 -04:00
.prettierignore [prettier] Ignore compiler/target (#31168) 2024-10-10 10:53:27 -04:00
.prettierrc.js [BE] switch to hermes parser for prettier (#30421) 2024-07-22 19:16:13 -04:00
.watchmanconfig .watchmanconfig must be valid json (#16118) 2019-07-11 19:01:02 -07:00
babel.config-react-compiler.js feat(eslint-plugin-react-hooks): merge rule from eslint-plugin-react-compiler into react-hooks plugin (#32416) 2025-03-12 21:43:06 -04:00
babel.config-ts.js Update babel configs used in jest (#32588) 2025-03-12 19:07:39 -04:00
babel.config.js Partially revert #32588 (#32621) 2025-03-15 15:21:57 -04:00
CHANGELOG.md Update 19.1 changelog to remove confusing owner stack sentance 2025-03-28 14:55:28 -07:00
CODE_OF_CONDUCT.md revert last grammatical edit (#25067) 2022-08-10 20:14:31 +01:00
CONTRIBUTING.md Fix: Updated link in CONTRIBUTING (#25381) 2022-10-03 10:29:57 -04:00
dangerfile.js Fix typo in dangerfile.js which results in an unreachable code path… (#32277) 2025-01-31 01:44:02 -05:00
LICENSE [Codemod] Update copyright header to Meta (#25315) 2022-10-18 11:19:24 -04:00
MAINTAINERS Update MAINTAINERS (#32238) 2025-01-27 13:40:45 -06:00
package.json Build react-server-dom-webpack for codesandbox (#32990) 2025-04-22 22:20:21 +02:00
react.code-workspace created a vscode workspace file for the repo (#29830) 2024-06-13 16:23:42 +01:00
ReactVersions.js [eprh] Bump stable version (#32978) 2025-04-21 14:36:13 -04:00
README.md [ez] Remove circleci badge from readme 2024-07-29 13:26:14 -04:00
SECURITY.md Create SECURITY.md (#15784) 2020-01-09 14:07:41 -08:00
yarn.lock Update @playwright/test (#32917) 2025-04-15 12:52:43 -04:00

React · GitHub license npm version (Runtime) Build and Test (Compiler) TypeScript PRs Welcome

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 own 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.

Learn how to use React in your project.

Installation

React has been designed for gradual adoption from the start, and you can use as little or as much React as you need:

Documentation

You can find the React documentation on the website.

Check out the Getting Started page for a quick overview.

The documentation is divided into several sections:

You can improve it by sending pull requests to this repository.

Examples

We have several examples on the website. Here is the first one to get you started:

import { createRoot } from 'react-dom/client';

function HelloMessage({ name }) {
  return <div>Hello {name}</div>;
}

const root = createRoot(document.getElementById('container'));
root.render(<HelloMessage name="Taylor" />);

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. JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML.

Contributing

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.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React.

Good First Issues

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started.

License

React is MIT licensed.