react:The library for web and native user interfaces.

The library for web and native user interfaces.

分支862Tags168
文件最后提交记录最后更新时间
[repo] init claude config (#35617) ## Overview Adds a claude setup that works with the nested /compiler setup. The constraints are: - when working in the root repo, don't use the compiler configs (easy) - when working in the compiler/ don't use the parent contigs (hard) The first one is easy: there's a claude.md and .claude directory in /compiler that is only loaded when you start a session from /compuler. The second one is hard, because if you start a session from /compiler, the parent claude files and skills are loaded. I was able to deny the permissions to the parent skills in settings.json, but the descriptions are still loaded into context and I don't think that's avoidable. To keep the parent claude file out of context, I created a hook hack: I moved all the non-compiler claude file context to instructions.md and added a SessionStart hook to cat the file into context if the cwd isn't the /compiler. Works well, but won't show it as part of the `/context` slash command. ## Skills I also added a number of skills specific to the React repo: | Skill | Description | |-------|-------------| | `/extract-errors` | `yarn extract-errors` | | `/feature-flags` | how feature flags work and `@gate` | | `/fix` | linc and prettier | | `/flags` | `yarn flags` | | `/flow` | `yarn flow <variant>` | | `/test` | `yarn test-*` | | `/verify` | `run all the lints/tests/flow to verify` | ### Example: Flow | before | after | |-----|-----| | <img width="1076" height="442" alt="flow-before" src="https://github.com/user-attachments/assets/73eec143-d0af-4771-b501-c9dc29cc09ac" /> | <img width="1076" height="273" alt="flow-after" src="https://github.com/user-attachments/assets/292d33af-1d98-4252-9c08-744b33e88b86" /> | ### Example: Tests | before | after | |-----|-----| | <img width="1048" height="607" alt="test-before" src="https://github.com/user-attachments/assets/aa558ccf-2cee-4d22-b1f1-e4221c5a59dd" /> | <img width="1075" height="359" alt="test-after" src="https://github.com/user-attachments/assets/eb795392-6f46-403f-b9bb-8851ed790165" /> |4 个月前
Update Code Sandbox CI to Node 20 to Match .nvmrc (#34329) ## Summary Update the CodeSandbox CI configuration to use Node 20 instead of Node 18, so that it matches the Node version specified in .nvmrc. This ensures consistency between local development environments and CI builds, reducing the risk of version-related build issues. Closes #34328 ## How did you test this change? - Verified that .nvmrc specifies Node 20 and .codesandbox/ci.json is updated accordingly. - Locally switched to Node 20 using nvm use 20 and successfully ran build scripts for all packages: `react`, `react-dom`, `react-server-dom-webpack`, and `scheduler`. - Confirmed there are no Node 20–specific build errors or warnings locally. - CI on the feature branch will now run with Node 20, and all builds are expected to succeed.8 个月前
[ci] Create artifact attestations for builds on backport branches (#36558)1 天前
[compiler] Don't emit spurious `import { c as _c }` for discarded functions (#36500) ## What Codegen registers `_c` (the memo cache import) as a side effect whenever a function compiles with memo slots. The registration persists on `ProgramContext.imports` even if the function is later discarded (`'use no forget'`, `'use no memo'`, lint mode, validation errors). If other applied functions in the file compile to 0 memo slots, the stale `import { c as _c } from "react/compiler-runtime";` leaks into the output. ## Fix In `applyCompiledFunctions`, drop the memo cache import if no applied function uses memo slots. If `react/compiler-runtime` has no remaining specifiers, drop the module entry too so we don't emit a bare `import "react/compiler-runtime";`. ## Reproducer `use-no-forget-multiple-with-eslint-suppression.js`: ```js import {useRef} from 'react'; const useControllableState = options => {}; function NoopComponent() {} function Component() { 'use no forget'; const ref = useRef(null); // eslint-disable-next-line react-hooks/rules-of-hooks ref.current = 'bad'; return <button ref={ref} />; } ``` `NoopComponent` applies with 0 memo slots. `Component` is opted out, but codegen already registered `_c` for it. Before: ```js import { c as _c } from "react/compiler-runtime"; import { useRef } from "react"; ``` After: ```js import { useRef } from "react"; ``` ## Prior art TS counterpart to the Rust port's fix in 7e26eb89fc3264a34a9f03a68ac7a870d9f74b51. That commit also added `no-cache-slots-no-import.js`, which codifies the "no memo slots, no import" rule. ## Test plan - `yarn snap`: 1719/1719 passing - Snapshot for `use-no-forget-multiple-with-eslint-suppression` loses its spurious `_c` import - `no-cache-slots-no-import` still passes8 天前
[Flight] Avoid main-thread stalls from large debug strings (#36570)14 小时前
[FlightReply] Type hardening and performance improvements (#36425) Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>23 天前
[Flight] Avoid main-thread stalls from large debug strings (#36570)14 小时前
[Flight] Fix stranded row content under Node stream backpressure (#36516) The Flight Server emits Text and TypedArray rows as two chunks: a header that gives the row's id, type, and content length, followed by the content itself. These two chunks were pushed into `completedRegularChunks` (and `completedDebugChunks` in DEV) as separate items, so when the destination signaled backpressure between them, the flush would write the header and then break out before reaching the content. The content chunk was left stranded at the head of the queue. Async work running while the destination was paused appended new rows to `completedImportChunks` / `completedHintChunks`, and the next drain flushed those queues first — splicing the newly-arrived bytes into the position the Flight Client expects to read as the original row's content. From there the Flight Client read rows from the wrong byte offsets and the model failed to deserialize. This only surfaced on the Node stream path. `createFakeWritableFromReadableStreamController`, used by `renderToReadableStream`, always returns `true` from `write()`, so the flush loop never saw backpressure. The fix pushes a `NEXT_TWO_CHUNKS_ARE_ATOMIC` sentinel ahead of each `headerChunk` / `contentChunk` pair in `completedRegularChunks` and `completedDebugChunks`. The flush loops detect the sentinel and write the two chunks that follow it together before re-checking backpressure, so backpressure can still break between rows but never within one. ### Alternatives considered - **Pushing the pair as a `[headerChunk, contentChunk]` tuple.** Simpler but allocates an array per row. The required `isArray` branch in the flush hot path is likely comparable with the symbol check. This also violates the opaque `Chunk` type boundary. - **Concatenating header and content into one chunk.** Bad for memory — typed-array content can be large. - **Storing atomic groups in a separate queue.** Conceptually wrong and risks breaking reference-ordering assumptions between rows. - **Ignoring backpressure until the regulars queue is empty.** Defeats the point of backpressure. - **Wrapping the tuple behind a host-config API** (`writeAdjacentChunks` / `isAdjacentChunks` / `chunksToAdjacentChunks` / `getAdjacentChunksLength`). Keeps the implementation opaque but adds four exports per host config. Also has the tuple overhead. - **Begin/end sentinels for variable-length atomic groups.** Not needed — only Text and TypedArray rows use this pattern, and both are pairs.2 天前
Remove trim_trailing_whitespace from editorconfig (#31413) This setting breaks `toMatchInlineSnapshot` by removing whitespace in snapshots.1 年前
Update Flow to 0.263 (#34269) This update was a bit more involved. - `React$Component` was removed, I replaced it with Flow component types. - Flow removed shipping the standard library. This adds the environment libraries back from `flow-typed` which seemed to have changed slightly (probably got more precise and less `any`s). Suppresses some new type errors.9 个月前
[FlightReply] Type hardening and performance improvements (#36425) Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>23 天前
Add run prettier commit to .git-blame-ignore-revs ghstack-source-id: a10c3b3d6412873023747d6f253f8793fa689b60 Pull Request resolved: https://github.com/facebook/react/pull/303911 年前
.gitattributes to ensure LF line endings when we should 12 年前
[Fizz] prevent reentrant finishedTask from calling completeAll multiple times (#36287) It is possible for the fallback tasks from a Suspense boundary to trigger an early `completeAll` call which is later repeated due to `finishedTask` reentrancy. For node.js in particular this might be problematic since we invoke a callback on each `completeAll` call but in general it just isn't the right semantics since the call is running slightly earlier than the completion of the last `finishedTask` invocation. This change ensures that any reentrant `finishedTask` calls (due to soft aborting fallback tasks) omit the `completeAll` call by temporarily incrementing the total pending tasks.1 个月前
updates mailmap entries (#19824) 5 年前
Upgrade node.js to 20 LTS (#32855) Try to upgrade our node version. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32855). * #32861 * #32860 * #32859 * __->__ #328551 年前
[prettier] Ignore compiler/target (#31168) Add missing directory to prettierignore. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31168). * #31167 * #31166 * #31165 * #31164 * #31148 * __->__ #311681 年前
[scripts] Switch back to flow parser for prettier (#33414) Prettier 3.3 (which we're on) should support modern flow features according to https://prettier.io/blog/2024/06/01/3.3.011 个月前
.watchmanconfig must be valid json (#16118) faceworldproblems?6 年前
Update changelog with latest releases (#35279) 5 个月前
[repo] init claude config (#35617) ## Overview Adds a claude setup that works with the nested /compiler setup. The constraints are: - when working in the root repo, don't use the compiler configs (easy) - when working in the compiler/ don't use the parent contigs (hard) The first one is easy: there's a claude.md and .claude directory in /compiler that is only loaded when you start a session from /compuler. The second one is hard, because if you start a session from /compiler, the parent claude files and skills are loaded. I was able to deny the permissions to the parent skills in settings.json, but the descriptions are still loaded into context and I don't think that's avoidable. To keep the parent claude file out of context, I created a hook hack: I moved all the non-compiler claude file context to instructions.md and added a SessionStart hook to cat the file into context if the cwd isn't the /compiler. Works well, but won't show it as part of the `/context` slash command. ## Skills I also added a number of skills specific to the React repo: | Skill | Description | |-------|-------------| | `/extract-errors` | `yarn extract-errors` | | `/feature-flags` | how feature flags work and `@gate` | | `/fix` | linc and prettier | | `/flags` | `yarn flags` | | `/flow` | `yarn flow <variant>` | | `/test` | `yarn test-*` | | `/verify` | `run all the lints/tests/flow to verify` | ### Example: Flow | before | after | |-----|-----| | <img width="1076" height="442" alt="flow-before" src="https://github.com/user-attachments/assets/73eec143-d0af-4771-b501-c9dc29cc09ac" /> | <img width="1076" height="273" alt="flow-after" src="https://github.com/user-attachments/assets/292d33af-1d98-4252-9c08-744b33e88b86" /> | ### Example: Tests | before | after | |-----|-----| | <img width="1048" height="607" alt="test-before" src="https://github.com/user-attachments/assets/aa558ccf-2cee-4d22-b1f1-e4221c5a59dd" /> | <img width="1075" height="359" alt="test-after" src="https://github.com/user-attachments/assets/eb795392-6f46-403f-b9bb-8851ed790165" /> |4 个月前
revert last grammatical edit (#25067) on line 29, #24798 edited (others') to (other's); however, the subject here is plural (e.g. "others in the community"), thus (others') is grammatically correct3 年前
Fix: Updated link in CONTRIBUTING (#25381) 3 年前
[Codemod] Update copyright header to Meta (#25315) * Facebook -> Meta in copyright rg --files | xargs sed -i 's#Copyright (c) Facebook, Inc. and its affiliates.#Copyright (c) Meta Platforms, Inc. and affiliates.#g' * Manual tweaks3 年前
Update MAINTAINERS (#34534) 8 个月前
[ez] Remove circleci badge from readme CircleCI is no longer in use in this repo: a6b5ed01ae98a18507cb92d8e932a8ca321602e6 ghstack-source-id: b6234f11d143d2c65832e17ccf180b255dc23c9d Pull Request resolved: https://github.com/facebook/react/pull/305021 年前
[eprh] Update changelog for 7.1.1 (#36308)1 个月前
Create SECURITY.md (#15784) Adds SECURITY.md as mentioned in #15722.6 年前
feat(eslint-plugin-react-hooks): merge rule from eslint-plugin-react-compiler into `react-hooks` plugin (#32416) This change merges the `react-compiler` rule from `eslint-plugin-react-compiler` into the `eslint-plugin-react-hooks` plugin. In order to do the move in a way that keeps commit history with the moved files, but also no remove them from their origin until a future cleanup change can be done, I did the `git mv` first, and then recreated the files that were moved in their original places, as a separate commit. Unfortunately GH shows the moved files as new instead of the ones that are truly new. But in the IDE and `git blame`, commit history is intact with the moved files. Since this change adds new dependencies, and one of those dependencies has a higher `engines` declaration for `node` than what the plugin currently has, this is technically a breaking change and will have to go out as part of a major release. ### Related Changes - https://github.com/facebook/react/pull/32458 --------- Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>1 年前
[compiler] Aggregate error reporting, separate eslint rules (#34176) NOTE: this is a merged version of @mofeiZ's original PR along with my edits per offline discussion. The description is updated to reflect the latest approach. The key problem we're trying to solve with this PR is to allow developers more control over the compiler's various validations. The idea is to have a number of rules targeting a specific category of issues, such as enforcing immutability of props/state/etc or disallowing access to refs during render. We don't want to have to run the compiler again for every single rule, though, so @mofeiZ added an LRU cache that caches the full compilation output of N most recent files. The first rule to run on a given file will cause it to get cached, and then subsequent rules can pull from the cache, with each rule filtering down to its specific category of errors. For the categories, I went through and assigned a category roughly 1:1 to existing validations, and then used my judgement on some places that felt distinct enough to warrant a separate error. Every error in the compiler now has to supply both a severity (for legacy reasons) and a category (for ESLint). Each category corresponds 1:1 to a ESLint rule definition, so that the set of rules is automatically populated based on the defined categories. Categories include a flag for whether they should be in the recommended set or not. Note that as with the original version of this PR, only eslint-plugin-react-compiler is changed. We still have to update the main lint rule. ## Test Plan * Created a sample project using ESLint v9 and verified that the plugin can be configured correctly and detects errors * Edited `fixtures/eslint-v9` and introduced errors, verified that the w latest config changes in that fixture it correctly detects the errors * In the sample project, confirmed that the LRU caching is correctly caching compiler output, ie compiling files just once. Co-authored-by: Mofei Zhang <feifei0@meta.com>9 个月前
Stop transpiling computed property names (#36542)3 天前
Fix typo in dangerfile.js which results in an unreachable code path… (#32277) ## Summary Fix typo in dangerfile.js which results in an unreachable code path which ought to be hit when there is no matching base artifact during DangerCI automated code review. See: https://github.com/facebook/react/blob/221f3002caa2314cba0a62950da6fb92b453d1d0/dangerfile.js#L73 Compare: https://github.com/facebook/react/blob/221f3002caa2314cba0a62950da6fb92b453d1d0/dangerfile.js#L171 And the case which should hit this code path: https://github.com/facebook/react/blob/221f3002caa2314cba0a62950da6fb92b453d1d0/dangerfile.js#L160 Given the above context, the condition `Number === Infinity` is clearly meant to be `decimal === Infinity`, which it will be if the `catch` statement triggers when there is no matching base artifact. Without this fix, the primitive value `Infinity` is passed to `percentFormatter.format(decimal)`, resulting in the string `'+∞%'`. With this fix, the resulting string will be the intended `'New file'`. ## [Resolves issue 32278](https://github.com/facebook/react/issues/32278)1 年前
Update Flow to 0.263 (#34269) This update was a bit more involved. - `React$Component` was removed, I replaced it with Flow component types. - Flow removed shipping the standard library. This adds the environment libraries back from `flow-typed` which seemed to have changed slightly (probably got more precise and less `any`s). Suppresses some new type errors.9 个月前
Stop transpiling computed property names (#36542)3 天前
created a vscode workspace file for the repo (#29830) ### Summary Similarly to what has been done on the `react-native` repo in https://github.com/facebook/react-native/pull/43851, this PR adds a `react.code-workspace` workspace file when using VSCode. This disables the built-in TypeScript Language Service for `.js`, `.ts`, and `.json` files, recommends extensions, enables `formatOnSave`, excludes certain files in search, and configures Flow language support. ### Motivation This is a DevX benefit for **React contributors** using open source VS Code. Without this, it takes quite a long time to set up the environment in vscode to work well. For me the following two points took around an hour each to figure out, but for others it may take even more (screenshots can be found below): * Search with "files to include" was searching in ignored files (compiled/generated) * Configure language validation and prettier both in "packages" that use flow and in the "compiler" folder that uses typescript. ### Recommended extensions NOTE: The recommended extensions list is currently minimal — happy to extend this now or in future, but let's aim to keep these conservative at the moment. * Flow — language support * EditorConfig — formatting based on `.editorconfig`, all file types * Prettier — formatting for JS* files * ESLint — linter for JS* files ### Why `react.code-workspace`? `.code-workspace` files have slight extra behaviours over a `.vscode/` directory: * Allows user to opt-in or skip. * Allows double-click launching from file managers. * Allows base folder (and any subfolders in future) to be opened with local file tree scope (useful in fbsource!) * (Minor point) Single config file over multiple files. https://code.visualstudio.com/docs/editor/workspaces ### Test plan Against a new un-configured copy of Visual Studio Code Insiders. **Without workspace config** ❌ .js files raise errors by default (built-in TypeScript language service) ❌ When using the Flow VS Code extension, the wrong version (global) of Flow is used. <img width="978" alt="Screenshot 2024-06-10 at 16 03 59" src="https://github.com/facebook/react/assets/5188459/17e19ba4-bac2-48ea-9b35-6b4b6242bcc1"> ❌ Searching in excluded files when the "include" field is specified <img width="502" alt="Screenshot 2024-06-10 at 15 41 24" src="https://github.com/facebook/react/assets/5188459/00248755-7905-41bc-b303-498ddba82108"> **With workspace config** ✅ Built-in TypeScript Language Service is disabled for .js files, but still enabled for .ts[x] files ![Screen Recording 2024-06-13 at 12 21 24](https://github.com/facebook/react/assets/5188459/6048218c-f316-44cd-8771-d2d0e848991d) ✅ Flow language support is configured correctly against flow version in package.json <img width="993" alt="Screenshot 2024-06-10 at 16 03 44" src="https://github.com/facebook/react/assets/5188459/b54e143c-a013-4e73-8995-3af7b5a03e36"> ✅ Does not search in excluded files when the "include" field is specified <img width="555" alt="Screenshot 2024-06-10 at 15 39 18" src="https://github.com/facebook/react/assets/5188459/dd3e5344-84fb-4b5d-8689-4c8bd28168e0"> ✅ Workspace config is suggested when folder is opened in VS Code ![image](https://github.com/facebook/react/assets/5188459/7434261f-1057-4954-9885-b057a10684ad) ✅ Dialog is shown on workspace launch with recommended VS Code extensions <img width="580" alt="Screenshot 2024-06-10 at 15 40 52" src="https://github.com/facebook/react/assets/5188459/c6406fb6-92a0-47f1-8497-4ffe899bb6a9">1 年前
[FlightReply] Don't drop FormData entries in `decodeReplyFromBusboy` (#36468) Fixes a regression from #36425 where referenced `FormData` entries can be dropped by `decodeReplyFromBusboy` when files are interleaved with text fields in the payload. `decodeReplyFromBusboy` queues text fields that arrive while a file is being streamed and flushes them after the last file's `'end'`, working around busboy emitting `'end'` deferred relative to subsequent `'field'` events. With multiple files interleaved with text, this loses the relative order of the affected text entries. The reorder was a long-standing but invisible issue — entries came back in the wrong order but were all present — until #36425 tightened how referenced FormData entries are collected from the backing store to rely on them being contiguous. With that assumption violated, referenced FormDatas can now come back with some entries dropped. The pattern is most easily surfaced through `useActionState` actions that return the submitted `FormData` as part of their state. This replaces the tail-flush with a linked list of pending files. Text fields that arrive while a file is in flight are queued on the tail file's `queuedFields`; fields that arrive when the list is empty resolve immediately. `flush()` walks from the head, resolving each completed file followed by its queued fields, and stops at the first file that hasn't ended yet. The backing FormData now matches the payload's order, restoring the contiguity assumption (and fixing the long-standing reorder as a side effect). The same change is applied to all five copies in `react-server-dom-{webpack,turbopack,parcel,esm,unbundled}`. Two new tests cover the multi-file interleave. fixes vercel/next.js#9382215 天前

React ·

GitHub 许可证

npm 版本

(运行时)构建与测试

(编译器)TypeScript

欢迎提交 PR

React 是一个用于构建用户界面的 JavaScript 库。

  • 声明式编程: React 让创建交互式 UI 变得轻松。为应用中的每个状态设计简单视图,当数据变化时,React 会高效地更新和渲染正确的组件。声明式的视图使得你的代码更可预测,更容易理解,并简化调试。
  • 基于组件: 构建封装良好、管理自身状态的组件,然后组合它们来构建复杂的 UI。由于组件逻辑用 JavaScript 而不是模板编写,你可以轻松在应用中传递丰富数据,并使状态远离 DOM。
  • 一次学习,处处编写: 我们不对技术栈的其他部分做假设,因此你可以在不重写现有代码的情况下使用 React 开发新功能。React 还能在服务器端使用 Node.js 渲染,并通过 React Native 驱动移动应用。

了解如何在项目中使用 React

安装

从一开始,React 就设计为渐进式采用,你可以按需选择使用 React 的多少

文档

React 的文档可在官方网站上找到

查看入门页面以获取快速概览。

文档分为几个部分:

你可以通过向这个仓库发送拉取请求来改进它。

示例

我们在网站上提供了多个示例,以下是一个入门示例:

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" />);

此示例将在页面上的容器内渲染“Hello Taylor”。

你会注意到我们使用了类似 HTML 的语法;我们称之为JSX。虽然使用 JSX 不是必需的,但它让代码更加易读,编写起来就像是在编写 HTML。

贡献

此仓库的主要目的是继续发展 React 核心,使其更快、更易于使用。React 的开发在 GitHub 上公开进行,我们非常感激社区贡献错误修复和改进。阅读下面的内容了解如何参与改善 React。

行为准则

Facebook 已采纳一份行为准则,我们期待项目参与者遵守。请阅读全文,以便了解哪些行为被接受和不被接受。

贡献指南

阅读我们的贡献指南,以了解我们的开发流程,以及如何提出错误修复和改进提案,还有如何构建和测试 React 的更改。

适合初学者的问题

为了帮助你入手并熟悉我们的贡献流程,我们列出了一系列适合初学者的问题,这些问题包含了范围相对有限的错误。这是开始贡献的好地方。

许可证

React 采用MIT许可

项目介绍

The library for web and native user interfaces.

定制我的领域
6.63 K245.32 K51.13 K访问 GitHub

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新

语言类型

JavaScript68.13%
TypeScript27.4%
TSX1.53%
HTML1.46%
CSS1.14%