facebook/react
 Watch   
 Star   
 Fork   
2024-11-15 00:48:33
react

19.0.0 (December 5, 2024)

Below is a list of all new features, APIs, deprecations, and breaking changes. Read React 19 release post and React 19 upgrade guide for more information.

Note: To help make the upgrade to React 19 easier, we’ve published a react@18.3 release that is identical to 18.2 but adds warnings for deprecated APIs and other changes that are needed for React 19. We recommend upgrading to React 18.3.1 first to help identify any issues before upgrading to React 19.

New Features

React

  • Actions: startTransition can now accept async functions. Functions passed to startTransition are called “Actions”. A given Transition can include one or more Actions which update state in the background and update the UI with one commit. In addition to updating state, Actions can now perform side effects including async requests, and the Action will wait for the work to finish before finishing the Transition. This feature allows Transitions to include side effects like fetch() in the pending state, and provides support for error handling, and optimistic updates.
  • useActionState: is a new hook to order Actions inside of a Transition with access to the state of the action, and the pending state. It accepts a reducer that can call Actions, and the initial state used for first render. It also accepts an optional string that is used if the action is passed to a form action prop to support progressive enhancement in forms.
  • useOptimistic: is a new hook to update state while a Transition is in progress. It returns the state, and a set function that can be called inside a transition to “optimistically” update the state to expected final value immediately while the Transition completes in the background. When the transition finishes, the state is updated to the new value.
  • use: is a new API that allows reading resources in render. In React 19, use accepts a promise or Context. If provided a promise, use will suspend until a value is resolved. use can only be used in render but can be called conditionally.
  • ref as a prop: Refs can now be used as props, removing the need for forwardRef.
  • Suspense sibling pre-warming: When a component suspends, React will immediately commit the fallback of the nearest Suspense boundary, without waiting for the entire sibling tree to render. After the fallback commits, React will schedule another render for the suspended siblings to “pre-warm” lazy requests.

React DOM Client

  • <form> action prop: Form Actions allow you to manage forms automatically and integrate with useFormStatus. When a <form> action succeeds, React will automatically reset the form for uncontrolled components. The form can be reset manually with the new requestFormReset API.
  • <button> and <input> formAction prop: Actions can be passed to the formAction prop to configure form submission behavior. This allows using different Actions depending on the input.
  • useFormStatus: is a new hook that provides the status of the parent <form> action, as if the form was a Context provider. The hook returns the values: pending, data, method, and action.
  • Support for Document Metadata: We’ve added support for rendering document metadata tags in components natively. React will automatically hoist them into the <head> section of the document.
  • Support for Stylesheets: React 19 will ensure stylesheets are inserted into the <head> on the client before revealing the content of a Suspense boundary that depends on that stylesheet.
  • Support for async scripts: Async scripts can be rendered anywhere in the component tree and React will handle ordering and deduplication.
  • Support for preloading resources: React 19 ships with preinit, preload, prefetchDNS, and preconnect APIs to optimize initial page loads by moving discovery of additional resources like fonts out of stylesheet loading. They can also be used to prefetch resources used by an anticipated navigation.

React DOM Server

  • Added prerender and prerenderToNodeStream APIs for static site generation. They are designed to work with streaming environments like Node.js Streams and Web Streams. Unlike renderToString, they wait for data to load for HTML generation.

React Server Components

  • RSC features such as directives, server components, and server functions are now stable. This means libraries that ship with Server Components can now target React 19 as a peer dependency with a react-server export condition for use in frameworks that support the Full-stack React Architecture. The underlying APIs used to implement a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x. See docs for how to support React Server Components.

Deprecations

  • Deprecated: element.ref access: React 19 supports ref as a prop, so we’re deprecating element.ref in favor of element.props.ref. Accessing will result in a warning.
  • react-test-renderer: In React 19, react-test-renderer logs a deprecation warning and has switched to concurrent rendering for web usage. We recommend migrating your tests to @testinglibrary.com/docs/react-testing-library/intro/) or @testingesting-library.com/docs/react-native-testing-library/intro)

Breaking Changes

React 19 brings in a number of breaking changes, including the removals of long-deprecated APIs. We recommend first upgrading to 18.3.1, where we've added additional deprecation warnings. Check out the upgrade guide for more details and guidance on codemodding.

React

  • New JSX Transform is now required: We introduced a new JSX transform in 2020 to improve bundle size and use JSX without importing React. In React 19, we’re adding additional improvements like using ref as a prop and JSX speed improvements that require the new transform.
  • Errors in render are not re-thrown: Errors that are not caught by an Error Boundary are now reported to window.reportError. Errors that are caught by an Error Boundary are reported to console.error. We’ve introduced onUncaughtError and onCaughtError methods to createRoot and hydrateRoot to customize this error handling.
  • Removed: propTypes: Using propTypes will now be silently ignored. If required, we recommend migrating to TypeScript or another type-checking solution.
  • Removed: defaultProps for functions: ES6 default parameters can be used in place. Class components continue to support defaultProps since there is no ES6 alternative.
  • Removed: contextTypes and getChildContext: Legacy Context for class components has been removed in favor of the contextType API.
  • Removed: string refs: Any usage of string refs need to be migrated to ref callbacks.
  • Removed: Module pattern factories: A rarely used pattern that can be migrated to regular functions.
  • Removed: React.createFactory: Now that JSX is broadly supported, all createFactory usage can be migrated to JSX components.
  • Removed: react-test-renderer/shallow: This has been a re-export of react-shallow-renderer since React 18. If needed, you can continue to use the third-party package directly. We recommend using @testinglibrary.com/docs/react-testing-library/intro/) or @testingesting-library.com/docs/react-native-testing-library/intro) instead.

React DOM

  • Removed: react-dom/test-utils: We’ve moved act from react-dom/test-utils to react. All other utilities have been removed.
  • Removed: ReactDOM.render, ReactDOM.hydrate: These have been removed in favor of the concurrent equivalents: ReactDOM.createRoot and ReactDOM.hydrateRoot.
  • Removed: unmountComponentAtNode: Removed in favor of root.unmount().
  • Removed: ReactDOM.findDOMNode: You can replace ReactDOM.findDOMNode with DOM Refs.

Notable Changes

React

  • <Context> as a provider: You can now render <Context> as a provider instead of <Context.Provider>.
  • Cleanup functions for refs: When the component unmounts, React will call the cleanup function returned from the ref callback.
  • useDeferredValue initial value argument: When provided, useDeferredValue will return the initial value for the initial render of a component, then schedule a re-render in the background with the deferredValue returned.
  • Support for Custom Elements: React 19 now passes all tests on Custom Elements Everywhere.
  • StrictMode changes: useMemo and useCallback will now reuse the memoized results from the first render, during the second render. Additionally, StrictMode will now double-invoke ref callback functions on initial mount.
  • UMD builds removed: To load React 19 with a script tag, we recommend using an ESM-based CDN such as esm.sh.

React DOM

  • Diffs for hydration errors: In the case of a mismatch, React 19 logs a single error with a diff of the mismatched content.
  • Compatibility with third-party scripts and extensions: React will now force a client re-render to fix up any mismatched content caused by elements inserted by third-party JS.

TypeScript Changes

The most common changes can be codemodded with npx types-react-codemod@latest preset-19 ./path-to-your-react-ts-files.

  • Removed deprecated TypeScript types:
    • ReactChild (replacement: React.ReactElement | number | string)
    • ReactFragment (replacement: Iterable<React.ReactNode>)
    • ReactNodeArray (replacement: ReadonlyArray<React.ReactNode>)
    • ReactText (replacement: number | string)
    • VoidFunctionComponent (replacement: FunctionComponent)
    • VFC (replacement: FC)
    • Moved to prop-types: Requireable, ValidationMap, Validator, WeakValidationMap
    • Moved to create-react-class: ClassicComponentClass, ClassicComponent, ClassicElement, ComponentSpec, Mixin, ReactChildren, ReactHTML, ReactSVG, SFCFactory
  • Disallow implicit return in refs: refs can now accept cleanup functions. When you return something else, we can’t tell if you intentionally returned something not meant to clean up or returned the wrong value. Implicit returns of anything but functions will now error.
  • Require initial argument to useRef: The initial argument is now required to match useState, createContext etc
  • Refs are mutable by default: Ref objects returned from useRef() are now always mutable instead of sometimes being immutable. This feature was too confusing for users and conflicted with legit cases where refs were managed by React and manually written to.
  • Strict ReactElement typing: The props of React elements now default to unknown instead of any if the element is typed as ReactElement
  • JSX namespace in TypeScript: The global JSX namespace is removed to improve interoperability with other libraries using JSX. Instead, the JSX namespace is available from the React package: import { JSX } from 'react'
  • Better useReducer typings: Most useReducer usage should not require explicit type arguments.
    For example,
    -useReducer<React.Reducer<State, Action>>(reducer)  
    +useReducer(reducer)  
    or
    -useReducer<React.Reducer<State, Action>>(reducer)  
    +useReducer<State, [Action]>(reducer)

All Changes

React

  • Add support for async Actions (#26621, #26726, #28078, #28097, #29226, #29618, #29670, #26716 by @acdlite and @sebmarkbage)
  • Add useActionState() hook to update state based on the result of a Form Action (#27270, #27278, #27309, #27302, #27307, #27366, #27370, #27321, #27374, #27372, #27397, #27399, #27460, #28557, #27570, #27571, #28631, #28788, #29694, #29695, #29694, #29665, #28232, #28319 by @acdlite, @eps1lon, and @rickhanlonii)
  • Add use() API to read resources in render (#25084, #25202, #25207, #25214, #25226, #25247, #25539, #25538, #25537, #25543, #25561, #25620, #25615, #25922, #25641, #25634, #26232, #26536, #26739, #28233 by @acdlite, @MofeiZ, @sebmarkbage, @sophiebits, @eps1lon, and @hansottowirtz)
  • Add useOptimistic() hook to display mutated state optimistically during an async mutation (#26740, #26772, #27277, #27453, #27454, #27936 by @acdlite)
  • Added an initialValue argument to useDeferredValue() hook (#27500, #27509, #27512, #27888, #27550 by @acdlite)
  • Support refs as props, warn on element.ref access (#28348, #28464, #28731 by @acdlite)
  • Support Custom Elements (#22184, #26524, #26523, #27511, #24541 by @josepharhar, @sebmarkbage, @gnoff and @eps1lon)
  • Add ref cleanup function (#25686, #28883, #28910 by @sammy-SC), @jackpope, and @kassens)
  • Sibling pre-rendering replaced by sibling pre-warming (#26380, #26549, #30761, #30800, #30762, #30879, #30934, #30952, #31056, #31452 by @sammy-SC), @acdlite, @gnoff, @jackpope, @rickhanlonii)
  • Don’t rethrow errors at the root (#28627, #28641 by @sebmarkbage)
  • Batch sync discrete, continuous, and default lanes (#25700 by @tyao1)
  • Switch <Context> to mean <Context.Provider> (#28226 by @gaearon)
  • Changes to StrictMode
    • Handle info, group, and groupCollapsed in StrictMode logging (#25172 by @timneutkens)
    • Refs are now attached/detached/attached in StrictMode (#25049 by @sammy-SC)
    • Fix useSyncExternalStore() hydration in StrictMode (#26791 by @sophiebits)
    • Always trigger componentWillUnmount() in StrictMode (#26842 by @tyao1)
    • Restore double invoking useState() and useReducer() initializer functions in StrictMode (#28248 by @eps1lon)
    • Reuse memoized result from first pass (#25583 by @acdlite)
    • Fix useId() in StrictMode (#25713 by @gnoff)
    • Add component name to StrictMode error messages (#25718 by @sammy-SC)
  • Add support for rendering BigInt (#24580 by @eps1lon)
  • act() no longer checks shouldYield which can be inaccurate in test environments (#26317 by @acdlite)
  • Warn when keys are spread with props (#25697, #26080 by @sebmarkbage and @kassens)
  • Generate sourcemaps for production build artifacts (#26446 by @markerikson)
  • Improve stack diffing algorithm (#27132 by @KarimP)
  • Suspense throttling lowered from 500ms to 300ms (#26803 by @acdlite)
  • Lazily propagate context changes (#20890 by @acdlite and @gnoff)
  • Immediately rerender pinged fiber (#25074 by @acdlite)
  • Move update scheduling to microtask (#26512 by @acdlite)
  • Consistently apply throttled retries (#26611, #26802 by @acdlite)
  • Suspend Thenable/Lazy if it's used in React.Children (#28284 by @sebmarkbage)
  • Detect infinite update loops caused by render phase updates (#26625 by @acdlite)
  • Update conditional hooks warning (#29626 by @sophiebits)
  • Update error URLs to go to new docs (#27240 by @rickhanlonii)
  • Rename the react.element symbol to react.transitional.element (#28813 by @sebmarkbage)
  • Fix crash when suspending in shell during useSyncExternalStore() re-render (#27199 by @acdlite)
  • Fix incorrect “detected multiple renderers" error in tests (#22797 by @eps1lon)
  • Fix bug where effect cleanup may be called twice after bailout (#26561 by @acdlite)
  • Fix suspending in shell during discrete update (#25495 by @acdlite)
  • Fix memory leak after repeated setState bailouts (#25309 by @acdlite)
  • Fix useSyncExternalStore() dropped update when state is dispatched in render phase (#25578 by @pandaiolo)
  • Fix logging when rendering a lazy fragment (#30372 by @tomtom-sherman))
  • Remove string refs (#25383, #28322 by @eps1lon and @acdlite)
  • Remove Legacy Context (#30319 by @kassens)
  • Remove RefreshRuntime.findAffectedHostInstances (#30538 by @gaearon)
  • Remove client caching from cache() API (#27977, #28250 by @acdlite and @gnoff)
  • Remove propTypes (#28324, #28326 by @gaearon)
  • Remove defaultProps support, except for classes (#28733 by @acdlite)
  • Remove UMD builds (#28735 by @gnoff)
  • Remove delay for non-transition updates (#26597 by @acdlite)
  • Remove createFactory (#27798 by @kassens)

React DOM

React DOM Server

  • Stable release of React Server Components (Many, many PRs by @sebmarkbage, @acdlite, @gnoff, @sammy-SC, @gaearon, @sophiebits, @unstubbable, @lubieowoce)
  • Support Server Actions (#26124, #26632, #27459 by @sebmarkbage and @acdlite)
  • Changes to SSR
    • Add external runtime which bootstraps hydration on the client for binary transparency (#25437, #26169, #25499 by @MofeiZ and @acdlite)
    • Support subresource integrity for bootstrapScripts and bootstrapModules (#25104 by @gnoff)
    • Fix null bytes written at text chunk boundaries (#26228 by @sophiebits)
    • Fix logic around attribute serialization (#26526 by @gnoff)
    • Fix precomputed chunk cleared on Node 18 (#25645 by @feedthejim)
    • Optimize end tag chunks (#27522 by @yujunjung)
    • Gracefully handle suspending in DOM configs (#26768 by @sebmarkbage)
    • Check for nullish values on ReactCustomFormAction (#26770 by @sebmarkbage)
    • Preload bootstrapModules, bootstrapScripts, and update priority queue (#26754, #26753, #27190, #27189 by @gnoff)
    • Client render the nearest child or parent suspense boundary if replay errors or is aborted (#27386 by @sebmarkbage)
    • Don't bail out of flushing if we still have pending root tasks (#27385 by @sebmarkbage)
    • Ensure Resumable State is Serializable (#27388 by @sebmarkbage)
    • Remove extra render pass when reverting to client render (#26445 by @acdlite)
    • Fix unwinding context during selective hydration (#25876 by @tyao1)
    • Stop flowing and then abort if a stream is cancelled (#27405 by @sebmarkbage)
    • Pass cancellation reason to abort (#27536 by @sebmarkbage)
    • Add onHeaders entrypoint option (#27641, #27712 by @gnoff)
    • Escape <style> and <script> textContent to enable rendering inner content without dangerouslySetInnerHTML (#28870, #28871 by @gnoff)
    • Fallback to client replaying actions for Blob serialization (#28987 by @sebmarkbage)
    • Render Suspense fallback if boundary contains new stylesheet during sync update (#28965 by @gnoff)
    • Fix header length tracking (#30327 by @gnoff)
    • Use srcset to trigger load event on mount (#30351 by @gnoff)
    • Don't perform work when closing stream (#30497 by @gnoff)
    • Allow aborting during render (#30488, #30730 by @gnoff)
    • Start initial work immediately (#31079 by @gnoff)
    • A transition flowing into a dehydrated boundary no longer suspends when showing fallback (#27230 by @acdlite)
    • Fix selective hydration triggers false update loop error (#27439 by @acdlite)
    • Warn for Child Iterator of all types but allow Generator Components (#28853 by @sebmarkbage)
    • Include regular stack trace in serialized errors (#28684, #28738 by @sebmarkbage)
    • Aborting early no longer infinitely suspends (#24751 by @sebmarkbage)
    • Fix hydration warning suppression in text comparisons (#24784 by @gnoff)
    • Changes to error handling in SSR
      • Add diffs to hydration warnings (#28502, #28512 by @sebmarkbage)
      • Make Error creation lazy (#24728 by @sebmarkbage)
      • Remove recoverable error when a sync update flows into a dehydrated boundary (#25692 by @sebmarkbage)
      • Don't "fix up" mismatched text content with suppressedHydrationWarning (#26391 by @sebmarkbage)
      • Fix component stacks in errors (#27456 by @sebmarkbage)
      • Add component stacks to onError (#27761, #27850 by @gnoff and @sebmarkbage)
      • Throw hydration mismatch errors once (#28502 by @sebmarkbage)
  • Add Bun streaming server renderer (#25597 by @colinhacks)
  • Add nonce support to bootstrap scripts (#26738 by @danieltott)
  • Add crossorigin support to bootstrap scripts (#26844 by @HenriqueLimas)
  • Support nonce and fetchpriority in preload links (#26826 by @liuyenwei)
  • Add referrerPolicy to ReactDOM.preload() (#27096 by @styfle)
  • Add server condition for react/jsx-dev-runtime (#28921 by @himself65)
  • Export version (#29596 by @unstubbable)
  • Rename the secret export of Client and Server internals (#28786, #28789 by @sebmarkbage)
  • Remove layout effect warning on server (#26395 by @rickhanlonii)
  • Remove errorInfo.digest from onRecoverableError (#28222 by @gnoff)

ReactTestRenderer

  • Add deprecation error to react-test-renderer on web (#27903, #28904 by @jackpope and @acdlite)
  • Render with ConcurrentRoot on web (#28498 by @jackpope)
  • Remove react-test-renderer/shallow export (#25475, #28497 by @sebmarkbage and @jackpope)

React Reconciler

  • Enable suspending commits without blocking render (#26398, #26427 by @acdlite)
  • Remove prepareUpdate (#26583, #27409 by @sebmarkbage and @sophiebits)

React-Is

  • Enable tree shaking (#27701 by @markerikson)
  • Remove isConcurrentMode and isAsyncMode methods (#28224 by @gaearon)

useSyncExternalStore

  • Remove React internals access (#29868 by @phryneas)
  • Fix stale selectors keeping previous store references (#25969 by @jellevoost)
2024-10-11 21:20:25
react

eslint-plugin-react-hooks@5.0.0 (Oct 11, 2024)

This release only contains eslint-plugin-react-hooks. Notably, new violations and support for ESLint v9 were added.

eslint-plugin-react-hooks

  • New Violations: Component names now need to start with an uppercase letter instead of a non-lowercase letter. This means _Button or _component are no longer valid. (@kassens) in #25162
2024-04-27 00:17:57
react

18.3.1 (April 26, 2024)

  • Export act from react f1338f
2024-04-26 00:22:01
react

18.3.0 (April 25, 2024)

This release is identical to 18.2 but adds warnings for deprecated APIs and other changes that are needed for React 19.

Read the React 19 Upgrade Guide for more info.

React

  • Allow writing to this.refs to support string ref codemod 909071
  • Warn for deprecated findDOMNode outside StrictMode c3b283
  • Warn for deprecated test-utils methods d4ea75
  • Warn for deprecated Legacy Context outside StrictMode 415ee0
  • Warn for deprecated string refs outside StrictMode #25383
  • Warn for deprecated defaultProps for function components #25699
  • Warn when spreading key #25697
  • Warn when using act from test-utils d4ea75

React DOM

  • Warn for deprecated unmountComponentAtNode 8a015b
  • Warn for deprecated renderToStaticNodeStream #28874
2022-06-15 03:51:27
react

18.2.0 (June 14, 2022)

React DOM

  • Provide a component stack as a second argument to onRecoverableError. (@gnoff in #24591)
  • Fix hydrating into document causing a blank page on mismatch. (@gnoff in #24523)
  • Fix false positive hydration errors with Suspense. (@gnoff in #24480 and @acdlite in #24532)
  • Fix ignored setState in Safari when adding an iframe. (@gaearon in #24459)

React DOM Server

  • Pass information about server errors to the client. (@salazarm and @gnoff) in #24551 and (@gnoff in #24591
  • Allow to provide a reason when aborting the HTML stream. (@gnoff in #24680)
  • Eliminate extraneous text separators in the HTML where possible. (@gnoff in #24630)
  • Disallow complex children inside <title> elements to match the browser constraints. (@gnoff in #24679)
  • Fix buffering in some worker environments by explicitly setting highWaterMark to 0. (@jplhomer in #24641)

Server Components (Experimental)

  • Add support for useId() inside Server Components. (@gnoff) in #24172
2022-04-27 05:13:49
react

18.1.0 (April 26, 2022)

18.1.0 (April 26, 2022)

React DOM

  • Fix the false positive warning about react-dom/client when using UMD bundle. (@alireza-molaee in #24274)
  • Fix suppressHydrationWarning to work in production too. (@gaearon in #24271)
  • Fix componentWillUnmount firing twice inside of Suspense. (@acdlite in #24308)
  • Fix some transition updates being ignored. (@acdlite in #24353)
  • Fix useDeferredValue causing an infinite loop when passed an unmemoized value. (@acdlite in #24247)
  • Fix throttling of revealing Suspense fallbacks. (@sunderls in #24253)
  • Fix a missing warning about a setState loop in useEffect. (@gaearon in #24298)
  • Fix a spurious hydration error. (@gnoff in #24404)
  • Warn when calling setState in useInsertionEffect. (@gaearon in #24295)
  • Ensure the reason for hydration errors is always displayed. (@gaearon in #24276)

React DOM Server

  • Fix escaping for the bootstrapScriptContent contents. (@gnoff in #24385)
  • Significantly improve performance of renderToPipeableStream. (@gnoff in #24291)

ESLint Plugin: React Hooks

  • Fix false positive errors with a large number of branches. (@scyron6 in #24287)
  • Don't consider a known dependency stable when the variable is reassigned. (@afzalsayed96 in #24343)

Use Subscription

  • Replace the implementation with the use-sync-external-store shim. (@gaearon in #24289)
2022-03-30 01:17:00
react

18.0.0 (March 29, 2022)

Below is a list of all new features, APIs, deprecations, and breaking changes. Read React 18 release post and React 18 upgrade guide for more information.

New Features

React

  • useId is a new hook for generating unique IDs on both the client and server, while avoiding hydration mismatches. It is primarily useful for component libraries integrating with accessibility APIs that require unique IDs. This solves an issue that already exists in React 17 and below, but it’s even more important in React 18 because of how the new streaming server renderer delivers HTML out-of-order.
  • startTransition and useTransition let you mark some state updates as not urgent. Other state updates are considered urgent by default. React will allow urgent state updates (for example, updating a text input) to interrupt non-urgent state updates (for example, rendering a list of search results).
  • useDeferredValue lets you defer re-rendering a non-urgent part of the tree. It is similar to debouncing, but has a few advantages compared to it. There is no fixed time delay, so React will attempt the deferred render right after the first render is reflected on the screen. The deferred render is interruptible and doesn't block user input.
  • useSyncExternalStore is a new hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. It removes the need for useEffect when implementing subscriptions to external data sources, and is recommended for any library that integrates with state external to React.
  • useInsertionEffect is a new hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you’ve already built a CSS-in-JS library we don’t expect you to ever use this. This hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout.

React DOM Client

These new APIs are now exported from react-dom/client:

  • createRoot: New method to create a root to render or unmount. Use it instead of ReactDOM.render. New features in React 18 don't work without it.
  • hydrateRoot: New method to hydrate a server rendered application. Use it instead of ReactDOM.hydrate in conjunction with the new React DOM Server APIs. New features in React 18 don't work without it.

Both createRoot and hydrateRoot accept a new option called onRecoverableError in case you want to be notified when React recovers from errors during rendering or hydration for logging. By default, React will use reportError, or console.error in the older browsers.

React DOM Server

These new APIs are now exported from react-dom/server and have full support for streaming Suspense on the server:

  • renderToPipeableStream: for streaming in Node environments.
  • renderToReadableStream: for modern edge runtime environments, such as Deno and Cloudflare workers.

The existing renderToString method keeps working but is discouraged.

Deprecations

  • react-dom: ReactDOM.render has been deprecated. Using it will warn and run your app in React 17 mode.
  • react-dom: ReactDOM.hydrate has been deprecated. Using it will warn and run your app in React 17 mode.
  • react-dom: ReactDOM.unmountComponentAtNode has been deprecated.
  • react-dom: ReactDOM.renderSubtreeIntoContainer has been deprecated.
  • react-dom/server: ReactDOMServer.renderToNodeStream has been deprecated.

Breaking Changes

React

  • Automatic batching: This release introduces a performance improvement that changes to the way React batches updates to do more batching automatically. See Automatic batching for fewer renders in React 18 for more info. In the rare case that you need to opt out, wrap the state update in flushSync.
  • Stricter Strict Mode: In the future, React will provide a feature that lets components preserve state between unmounts. To prepare for it, React 18 introduces a new development-only check to Strict Mode. React will automatically unmount and remount every component, whenever a component mounts for the first time, restoring the previous state on the second mount. If this breaks your app, consider removing Strict Mode until you can fix the components to be resilient to remounting with existing state.
  • Consistent useEffect timing: React now always synchronously flushes effect functions if the update was triggered during a discrete user input event such as a click or a keydown event. Previously, the behavior wasn't always predictable or consistent.
  • Stricter hydration errors: Hydration mismatches due to missing or extra text content are now treated like errors instead of warnings. React will no longer attempt to "patch up" individual nodes by inserting or deleting a node on the client in an attempt to match the server markup, and will revert to client rendering up to the closest <Suspense> boundary in the tree. This ensures the hydrated tree is consistent and avoids potential privacy and security holes that can be caused by hydration mismatches.
  • Layout Effects with Suspense: When a tree re-suspends and reverts to a fallback, React will now clean up layout effects, and then re-create them when the content inside the boundary is shown again. This fixes an issue which prevented component libraries from correctly measuring layout when used with Suspense.
  • New JS Environment Requirements: React now depends on modern browsers features including Promise, Symbol, and Object.assign. If you support older browsers and devices such as Internet Explorer which do not provide modern browser features natively or have non-compliant implementations, consider including a global polyfill in your bundled application.

Notable Changes

React

  • Components can now render undefined: React no longer throws if you return undefined from a component. This makes the allowed component return values consistent with values that are allowed in the middle of a component tree. We suggest to use a linter to prevent mistakes like forgetting a return statement before JSX.
  • In tests, act warnings are now opt-in: If you're running end-to-end tests, the act warnings are unnecessary. We've introduced an opt-in mechanism so you can enable them only for unit tests where they are useful and beneficial.
  • No warning about setState on unmounted components: Previously, React warned about memory leaks when you call setState on an unmounted component. This warning was added for subscriptions, but people primarily run into it in scenarios where setting state is fine, and workarounds make the code worse. We've removed this warning.
  • No suppression of console logs: When you use Strict Mode, React renders each component twice to help you find unexpected side effects. In React 17, we've suppressed console logs for one of the two renders to make the logs easier to read. In response to community feedback about this being confusing, we've removed the suppression. Instead, if you have React DevTools installed, the second log's renders will be displayed in grey, and there will be an option (off by default) to suppress them completely.
  • Improved memory usage: React now cleans up more internal fields on unmount, making the impact from unfixed memory leaks that may exist in your application code less severe.

React DOM Server

  • renderToString: Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <Suspense> boundary and then retry rendering the same content on the client. It is still recommended that you switch to a streaming API like renderToPipeableStream or renderToReadableStream instead.
  • renderToStaticMarkup: Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <Suspense> boundary and retry rendering on the client.

All Changes

React

React DOM

React DOM Server

React DOM Test Utils

  • Throw when act is used in production. (#21686 by @acdlite)
  • Support disabling spurious act warnings with global.IS_REACT_ACT_ENVIRONMENT. (#22561 by @acdlite)
  • Expand act warning to cover all APIs that might schedule React work. (#22607 by @acdlite)
  • Make act batch updates. (#21797 by @acdlite)
  • Remove warning for dangling passive effects. (#22609 by @acdlite)

React Refresh

Server Components (Experimental)

Artifacts

2020-10-22 20:23:27
react

17.0.1 (October 14, 2020)

React DOM

2020-10-21 04:33:44
react

17.0.0 (October 20, 2020)

Today, we are releasing React 17!

Learn more about React 17 and how to update to it on the official React blog.

React

React DOM

  • Delegate events to roots instead of document. (@trueadm in #18195 and others)
  • Clean up all effects before running any next effects. (@bvaughn in #17947)
  • Run useEffect cleanup functions asynchronously. (@bvaughn in #17925)
  • Use browser focusin and focusout for onFocus and onBlur. (@trueadm in #19186)
  • Make all Capture events use the browser capture phase. (@trueadm in #19221)
  • Don't emulate bubbling of the onScroll event. (@gaearon in #19464)
  • Throw if forwardRef or memo component returns undefined. (@gaearon in #19550)
  • Remove event pooling. (@trueadm in #18969)
  • Stop exposing internals that won’t be needed by React Native Web. (@necolas in #18483)
  • Attach all known event listeners when the root mounts. (@gaearon in #19659)
  • Disable console in the second render pass of DEV mode double render. (@sebmarkbage in #18547)
  • Deprecate the undocumented and misleading ReactTestUtils.SimulateNative API. (@gaearon in #13407)
  • Rename private field names used in the internals. (@gaearon in #18377)
  • Don't call User Timing API in development. (@gaearon in #18417)
  • Disable console during the repeated render in Strict Mode. (@sebmarkbage in #18547)
  • In Strict Mode, double-render components without Hooks too. (@eps1lon in #18430)
  • Allow calling ReactDOM.flushSync during lifecycle methods (but warn). (@sebmarkbage in #18759)
  • Add the code property to the keyboard event objects. (@bl00mber in #18287)
  • Add the disableRemotePlayback property for video elements. (@tombrowndev in #18619)
  • Add the enterKeyHint property for input elements. (@eps1lon in #18634)
  • Warn when no value is provided to <Context.Provider>. (@charlie1404 in #19054)
  • Warn when memo or forwardRef components return undefined. (@bvaughn in #19550)
  • Improve the error message for invalid updates. (@JoviDeCroock in #18316)
  • Exclude forwardRef and memo from stack frames. (@sebmarkbage in #18559)
  • Improve the error message when switching between controlled and uncontrolled inputs. (@vcarl in #17070)
  • Keep onTouchStart, onTouchMove, and onWheel passive. (@gaearon in #19654)
  • Fix setState hanging in development inside a closed iframe. (@gaearon in #19220)
  • Fix rendering bailout for lazy components with defaultProps. (@jddxf in #18539)
  • Fix a false positive warning when dangerouslySetInnerHTML is undefined. (@eps1lon in #18676)
  • Fix Test Utils with non-standard require implementation. (@just-boris in #18632)
  • Fix onBeforeInput reporting an incorrect event.type. (@eps1lon in #19561)
  • Fix event.relatedTarget reported as undefined in Firefox. (@claytercek in #19607)
  • Fix "unspecified error" in IE11. (@hemakshis in #19664)
  • Fix rendering into a shadow root. (@Jack-Works in #15894)
  • Fix movementX/Y polyfill with capture events. (@gaearon in #19672)
  • Use delegation for onSubmit and onReset events. (@gaearon in #19333)
  • Improve memory usage. (@trueadm in #18970)

React DOM Server

  • Make useCallback behavior consistent with useMemo for the server renderer. (@alexmckenley in #18783)
  • Fix state leaking when a function component throws. (@pmaccart in #19212)

React Test Renderer

Concurrent Mode (Experimental)

Artifacts