diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index de2bfc362..ab8a7d4fe 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -3,5 +3,5 @@ contact_links: url: https://github.com/react/react/issues/new/choose about: This issue tracker is not for bugs in React. Please file React issues here. - name: 🤔 Questions and Help - url: https://reactjs.org/community/support.html + url: https://react.dev/community about: This issue tracker is not for support questions. Please refer to the React community's help and discussion forums. diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 83e7f2e8a..1620c50f6 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -18,7 +18,7 @@ jobs: - name: Set up node uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' cache: yarn cache-dependency-path: yarn.lock @@ -26,7 +26,7 @@ jobs: uses: actions/cache@v4 with: path: '**/node_modules' - key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: node_modules-24-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} - name: Install deps run: yarn install --frozen-lockfile diff --git a/.github/workflows/site_lint.yml b/.github/workflows/site_lint.yml index 81a04601c..ef43b2c8f 100644 --- a/.github/workflows/site_lint.yml +++ b/.github/workflows/site_lint.yml @@ -13,14 +13,14 @@ jobs: lint: runs-on: ubuntu-latest - name: Lint on node 20.x and ubuntu-latest + name: Lint on node 24.x and ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 20.x + - name: Use Node.js 24.x uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: 24.x cache: yarn cache-dependency-path: yarn.lock @@ -28,7 +28,7 @@ jobs: uses: actions/cache@v4 with: path: '**/node_modules' - key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: node_modules-24-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} - name: Install deps run: yarn install --frozen-lockfile diff --git a/CLAUDE.md b/CLAUDE.md index 3a081e6d5..3943097cc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,7 +4,7 @@ This file provides guidance to Claude Code when working with this repository. ## Project Overview -This is the React documentation website (react.dev), built with Next.js 15.1.11 and React 19. Documentation is written in MDX format. +This is the React documentation website (react.dev), built with Next.js 15.1.12 and React 19. Documentation is written in MDX format. ## Development Commands @@ -47,6 +47,6 @@ When editing files in `src/content/`, the appropriate skill will be auto-suggest For MDX components (DeepDive, Pitfall, Note, etc.), invoke `/docs-components`. For Sandpack code examples, invoke `/docs-sandpack`. -See `.claude/docs/react-docs-patterns.md` for comprehensive style guidelines. +See `.claude/skills/` for comprehensive style guidelines. Prettier is used for formatting (config in `.prettierrc`). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c7e5ec74..551bd4ba2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,41 +38,9 @@ Ignore this if you're specifically describing `createElement`. Ignore this if you're specifically writing about ES5. -#### Don't use ES6 features when equivalent ES5 features have no downsides. +#### Prefer readable syntax. -Remember that ES6 is still new to a lot of people. While we use it in many places (`const` / `let`, classes, arrow functions), if the equivalent ES5 code is just as straightforward and readable, consider using it. - -In particular, you should prefer named `function` declarations over `const myFunction = () => ...` arrows for top-level functions. However, you *should* use arrow functions where they provide a tangible improvement (such as preserving `this` context inside a component). Consider both sides of the tradeoff when deciding whether to use a new feature. - -#### Don't use features that aren't standardized yet. - -For example, **don't** write this: - -```js -class MyComponent extends React.Component { - state = {value: ''}; - handleChange = (e) => { - this.setState({value: e.target.value}); - }; -} -``` - -Instead, **do** write this: - -```js -class MyComponent extends React.Component { - constructor(props) { - super(props); - this.handleChange = this.handleChange.bind(this); - this.state = {value: ''}; - } - handleChange(e) { - this.setState({value: e.target.value}); - } -} -``` - -Ignore this rule if you're specifically describing an experimental proposal. Make sure to mention its experimental nature in the code and in the surrounding text. +Choose syntax that makes each example easier to follow. Prefer named `function` declarations over `const myFunction = () => ...` arrows for top-level functions. Use arrow functions when they make callbacks easier to read. In class components, arrow functions can also preserve the component's `this` value. ### Style diff --git a/README.md b/README.md index 157475ab2..a1a683af8 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,19 @@ This repo contains the source code and documentation powering [sr.react.dev](htt ### Prerequisites 1. Git -1. Node: any version starting with v16.8.0 or greater -1. Yarn: See [Yarn website for installation instructions](https://yarnpkg.com/lang/en/docs/install/) +1. Node: v24 or greater +1. Yarn Classic: See [Yarn website for installation instructions](https://classic.yarnpkg.com/en/docs/install/) 1. A fork of the repo (for any contributions) 1. A clone of the [sr.react.dev repo](https://github.com/reactjs/sr.react.dev) on your local machine ### Installation +<<<<<<< HEAD 1. `cd sr.react.dev` to go into the project root +======= +1. `cd react.dev` to go into the project root +2. `git remote add my-fork-name https://github.com/YOUR_USERNAME/react.dev.git` to add your fork as a remote. Replace `YOUR_USERNAME` with your GitHub username. You only need to do this once. +>>>>>>> 46a54e0592729712b7640308b53268e84fdc7c9f 3. `yarn` to install the website's npm dependencies ### Running locally @@ -39,8 +44,8 @@ The documentation is divided into several sections with a different tone and pur 1. Follow the ["Running locally"](#running-locally) instructions 1. Save the files and check in the browser 1. Changes to React components in `src` will hot-reload - 1. Changes to markdown files in `content` will hot-reload - 1. If working with plugins, you may need to remove the `.cache` directory and restart the server + 1. Changes to markdown files in `src/content` will hot-reload + 1. If working with plugins, you may need to remove the `node_modules/.cache/react-docs-mdx` directory and restart the server ### Test the change @@ -57,7 +62,11 @@ The documentation is divided into several sections with a different tone and pur ## Translation +<<<<<<< HEAD If you are interested in translating `sr.react.dev`, please see the current translation efforts [here](https://github.com/reactjs/sr.react.dev/issues/1). +======= +If you are interested in translating `react.dev`, please see the current translation efforts [here](https://react.dev/community/translations). +>>>>>>> 46a54e0592729712b7640308b53268e84fdc7c9f ## License Content submitted to [sr.react.dev](https://sr.react.dev/) is CC-BY-4.0 licensed, as found in the [LICENSE-DOCS.md](https://github.com/reactjs/sr.react.dev/blob/main/LICENSE-DOCS.md) file. diff --git a/package.json b/package.json index 20af6969d..6ca0c52d1 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "webpack-bundle-analyzer": "^4.5.0" }, "engines": { - "node": ">=16.8.0" + "node": ">=24" }, "nextBundleAnalysis": { "budget": null, diff --git a/src/content/reference/react-dom/components/form.md b/src/content/reference/react-dom/components/form.md index 459c27e0b..100d60f6d 100644 --- a/src/content/reference/react-dom/components/form.md +++ b/src/content/reference/react-dom/components/form.md @@ -103,6 +103,8 @@ When you pass a function to `action`, React: * Propagates any errors to the nearest Error Boundary. * Resets the form's uncontrolled fields when the function succeeds. To keep their values, see [Preserving form values after an Action](#preserve-form-values-after-an-action). +If you handle submission manually, you can [request the same reset behavior with `requestFormReset`](/reference/react-dom/requestFormReset#requesting-a-reset-in-a-custom-form-action). + Because the Action runs in a Transition, you can also use [`useActionState`](/reference/react/useActionState) to manage form state and [`useOptimistic`](/reference/react/useOptimistic) for optimistic UI. For [Server Functions](/reference/rsc/server-functions) and progressive enhancement, see [Handling form submission with a Server Function](#handle-form-submission-with-a-server-function). @@ -600,7 +602,7 @@ The examples above keep every submitted value by storing it before the reset. Yo * **Skip the reset with `onSubmit`.** Handle the submission in `onSubmit`, call `e.preventDefault()`, and run the Action inside [`startTransition`](/reference/react/useTransition). Because the form's `action` does not run, React does not reset the form. -* **Reset at a specific moment.** Call the form element's [`reset()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset) method to immediately reset uncontrolled fields to their default values. To schedule a reset as part of an Action or Transition, call [`requestFormReset`](/blog/2024/12/05/react-19#form-actions) from `react-dom` instead. +* **Reset at a specific moment.** Call the form element's [`reset()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset) method to immediately reset uncontrolled fields to their default values. To schedule a reset as part of an Action or Transition, call [`requestFormReset`](/reference/react-dom/requestFormReset) from `react-dom` instead. * **Reset the form and the component state together.** Change the [`key`](/learn/preserving-and-resetting-state#resetting-a-form-with-a-key) of the component that renders the form. React recreates the component and its DOM, which resets the fields and any local state. diff --git a/src/content/reference/react-dom/index.md b/src/content/reference/react-dom/index.md index 6ba5cdc93..1c0e03a2e 100644 --- a/src/content/reference/react-dom/index.md +++ b/src/content/reference/react-dom/index.md @@ -16,6 +16,7 @@ These APIs can be imported from your components. They are rarely used: * [`createPortal`](/reference/react-dom/createPortal) lets you render child components in a different part of the DOM tree. * [`flushSync`](/reference/react-dom/flushSync) lets you force React to flush a state update and update the DOM synchronously. +* [`requestFormReset`](/reference/react-dom/requestFormReset) lets you request a form reset when handling submissions with custom Actions or Transitions. ## Resource Preloading APIs {/*resource-preloading-apis*/} diff --git a/src/content/reference/react-dom/requestFormReset.md b/src/content/reference/react-dom/requestFormReset.md new file mode 100644 index 000000000..cd99a904a --- /dev/null +++ b/src/content/reference/react-dom/requestFormReset.md @@ -0,0 +1,89 @@ +--- +title: requestFormReset +--- + + + +`requestFormReset` lets you reset a React-managed form after an Action or Transition finishes. + +```js +requestFormReset(form) +``` + + + + + +--- + +## Reference {/*reference*/} + +### `requestFormReset(form)` {/*requestformreset*/} + +Call `requestFormReset` to request that a form resets after the current Action or Transition completes. + +```js +import { startTransition } from 'react'; +import { requestFormReset } from 'react-dom'; + +function handleSubmit(form) { + startTransition(async () => { + const formData = new FormData(form); + requestFormReset(form); + await save(formData); + }); +} +``` + +[See more examples below.](#usage) + +#### Parameters {/*parameters*/} + +* `form`: an [HTML form element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement) rendered by React. + +#### Returns {/*returns*/} + +`requestFormReset` returns nothing. + +#### Caveats {/*caveats*/} + +* Pass a form element that is rendered by React. Passing a non-form element, or a form not managed by React, throws an error. +* `requestFormReset` is intended for Actions and Transitions. If called outside an Action or Transition, React warns in development and performs a synchronous reset. +* `requestFormReset` is useful when you implement form submission logic yourself (for example with `onSubmit` + `startTransition`) and still want React's form reset behavior. +* This API requests a reset for uncontrolled form fields. For controlled fields, handle resets by updating state, such as in `onReset`. + +--- + +## Usage {/*usage*/} + +### Requesting a reset in a custom form Action {/*requesting-a-reset-in-a-custom-form-action*/} + +React [automatically resets uncontrolled fields after a successful `
` submission](/reference/react-dom/components/form#handle-form-submission-with-an-action-prop). When you implement submission manually, you can opt into the same behavior by calling `requestFormReset`. + +```js +import { startTransition } from 'react'; +import { requestFormReset } from 'react-dom'; + +function SearchForm() { + async function onSubmit(event) { + event.preventDefault(); + + const form = event.currentTarget; + const formData = new FormData(form); + + startTransition(async () => { + requestFormReset(form); + await submitSearch(formData); + }); + } + + return ( + + + +
+ ); +} +``` + +If your submission uses the built-in `
` behavior, you don't need to call `requestFormReset` manually. diff --git a/src/sidebarReference.json b/src/sidebarReference.json index d198122e6..988eab0cb 100644 --- a/src/sidebarReference.json +++ b/src/sidebarReference.json @@ -263,6 +263,10 @@ "title": "flushSync", "path": "/reference/react-dom/flushSync" }, + { + "title": "requestFormReset", + "path": "/reference/react-dom/requestFormReset" + }, { "title": "preconnect", "path": "/reference/react-dom/preconnect"