From a475c94bf9565a3d74dc35465e7519d18e13845b Mon Sep 17 00:00:00 2001 From: Josh Story Date: Fri, 5 Apr 2024 12:22:06 -0700 Subject: [PATCH] Try shorter property name to get inlining --- .../src/client/ReactDOMUpdatePriority.js | 17 +++++++++++------ .../react-dom/src/ReactDOMSharedInternals.js | 8 ++------ packages/shared/ReactVersion.js | 16 +--------------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.js b/packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.js index a1ac296a1a642..a0c4273bec604 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.js +++ b/packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.js @@ -16,19 +16,24 @@ import { } from 'react-reconciler/src/ReactEventPriorities'; import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; -const ReactDOMCurrentUpdatePriority = - ReactDOMSharedInternals.ReactDOMCurrentUpdatePriority; -export function setCurrentUpdatePriority(newPriority: EventPriority): void { - ReactDOMCurrentUpdatePriority.current = newPriority; +export function setCurrentUpdatePriority( + newPriority: EventPriority, + // Closure will consistently not inline this function when it has arity 1 + // however when it has arity 2 even if the second arg is omitted at every + // callsite it seems to inline it even when the internal length of the function + // is much longer. I hope this is consistent enough to rely on across builds + IntentionallyUnusedArgument?: empty, +): void { + ReactDOMSharedInternals.up = newPriority; } export function getCurrentUpdatePriority(): EventPriority { - return ReactDOMCurrentUpdatePriority.current; + return ReactDOMSharedInternals.up; } export function resolveUpdatePriority(): EventPriority { - const updatePriority = ReactDOMCurrentUpdatePriority.current; + const updatePriority = ReactDOMSharedInternals.up; if (updatePriority !== NoEventPriority) { return updatePriority; } diff --git a/packages/react-dom/src/ReactDOMSharedInternals.js b/packages/react-dom/src/ReactDOMSharedInternals.js index 02f5c7cde78fe..f2dd23c26660f 100644 --- a/packages/react-dom/src/ReactDOMSharedInternals.js +++ b/packages/react-dom/src/ReactDOMSharedInternals.js @@ -23,9 +23,7 @@ type InternalsType = { | (( componentOrElement: React$Component, ) => null | Element | Text), - ReactDOMCurrentUpdatePriority: { - current: EventPriority, - }, + up /* currentUpdatePriority */: EventPriority, }; function noop() {} @@ -47,9 +45,7 @@ const Internals: InternalsType = { current: DefaultDispatcher, }, findDOMNode: null, - ReactDOMCurrentUpdatePriority: { - current: NoEventPriority, - }, + up /* currentUpdatePriority */: NoEventPriority, }; export default Internals; diff --git a/packages/shared/ReactVersion.js b/packages/shared/ReactVersion.js index 13dd40e747e0d..446e5880c0c97 100644 --- a/packages/shared/ReactVersion.js +++ b/packages/shared/ReactVersion.js @@ -1,15 +1 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// TODO: this is special because it gets imported during build. -// -// It exists as a placeholder so that DevTools can support work tag changes between releases. -// When we next publish a release, update the matching TODO in backend/renderer.js -// TODO: This module is used both by the release scripts and to expose a version -// at runtime. We should instead inject the version number as part of the build -// process, and use the ReactVersions.js module as the single source of truth. -export default '19.0.0'; +export default '19.0.0-PLACEHOLDER';