Skip to content

Commit

Permalink
Setup Wave 2 of Feature Flags for React Native (#28990)
Browse files Browse the repository at this point in the history
## Summary

Sets up dynamic feature flags for `disableStringRefs`, `enableFastJSX`,
and `enableRefAsProp` in React Native (at Meta).

## How did you test this change?

```
$ yarn test
$ yarn flow fabric
```

DiffTrain build for commit 9b13002.
  • Loading branch information
yungsters committed May 6, 2024
1 parent 9e5b8af commit 67879d1
Show file tree
Hide file tree
Showing 17 changed files with 1,927 additions and 1,306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3cde5a560aeab39ea15c34b2e5562835>>
* @generated SignedSource<<b49fe2332655e16fd76d120df3e46271>>
*/

'use strict';
Expand Down Expand Up @@ -5057,21 +5057,6 @@ function shallowEqual(objA, objB) {

var current = null;
var isRendering = false;
function getCurrentFiberOwnerNameInDevOrNull() {
{
if (current === null) {
return null;
}

var owner = current._debugOwner;

if (owner != null) {
return getComponentNameFromOwner(owner);
}
}

return null;
}

function getCurrentFiberStackInDev() {
{
Expand Down Expand Up @@ -5665,8 +5650,11 @@ function coerceRef(returnFiber, current, workInProgress, element) {
var ref;

{
// Old behavior.
ref = element.ref;
// TODO: This is a temporary, intermediate step. When enableRefAsProp is on,
// we should resolve the `ref` prop during the begin phase of the component
// it's attached to (HostComponent, ClassComponent, etc).
var refProp = element.props.ref;
ref = refProp !== undefined ? refProp : null;
} // TODO: If enableRefAsProp is on, we shouldn't use the `ref` field. We
// should always read the ref from the prop.

Expand Down Expand Up @@ -11472,6 +11460,19 @@ function resolveClassComponentProps(Component, baseProps, // Only resolve defaul
alreadyResolvedDefaultProps) {
var newProps = baseProps;

{
// Remove ref from the props object, if it exists.
if ('ref' in baseProps) {
newProps = {};

for (var propName in baseProps) {
if (propName !== 'ref') {
newProps[propName] = baseProps[propName];
}
}
}
} // Resolve default props.


var defaultProps = Component.defaultProps;

Expand Down Expand Up @@ -12076,7 +12077,6 @@ var didReceiveUpdate = false;
var didWarnAboutBadClass;
var didWarnAboutContextTypeOnFunctionComponent;
var didWarnAboutGetDerivedStateOnFunctionComponent;
var didWarnAboutFunctionRefs;
var didWarnAboutReassigningProps;
var didWarnAboutRevealOrder;
var didWarnAboutTailOptions;
Expand All @@ -12086,7 +12086,6 @@ var didWarnAboutDefaultPropsOnFunctionComponent;
didWarnAboutBadClass = {};
didWarnAboutContextTypeOnFunctionComponent = {};
didWarnAboutGetDerivedStateOnFunctionComponent = {};
didWarnAboutFunctionRefs = {};
didWarnAboutReassigningProps = false;
didWarnAboutRevealOrder = {};
didWarnAboutTailOptions = {};
Expand Down Expand Up @@ -12135,7 +12134,21 @@ function updateForwardRef(current, workInProgress, Component, nextProps, renderL
var ref = workInProgress.ref;
var propsWithoutRef;

{
if ('ref' in nextProps) {
// `ref` is just a prop now, but `forwardRef` expects it to not appear in
// the props object. This used to happen in the JSX runtime, but now we do
// it here.
propsWithoutRef = {};

for (var key in nextProps) {
// Since `ref` should only appear in props via the JSX transform, we can
// assume that this is a plain object. So we don't need a
// hasOwnProperty check.
if (key !== 'ref') {
propsWithoutRef[key] = nextProps[key];
}
}
} else {
propsWithoutRef = nextProps;
} // The rest is a fork of updateFunctionComponent

Expand Down Expand Up @@ -12567,19 +12580,6 @@ function markRef(current, workInProgress) {
}

if (current === null || current.ref !== ref) {
if (current !== null) {
var oldRef = current.ref;
var newRef = ref;

if (typeof oldRef === 'function' && typeof newRef === 'function' && typeof oldRef.__stringRef === 'string' && oldRef.__stringRef === newRef.__stringRef && oldRef.__stringRefType === newRef.__stringRefType && oldRef.__stringRefOwner === newRef.__stringRefOwner) {
// Although this is a different callback, it represents the same
// string ref. To avoid breaking old Meta code that relies on string
// refs only being attached once, reuse the old ref. This will
// prevent us from detaching and reattaching the ref on each update.
workInProgress.ref = oldRef;
return;
}
} // Schedule a Ref effect


workInProgress.flags |= Ref | RefStatic;
Expand Down Expand Up @@ -13064,24 +13064,6 @@ function validateFunctionComponentInDev(workInProgress, Component) {
}
}

if (workInProgress.ref !== null) {
var info = '';
var componentName = getComponentNameFromType(Component) || 'Unknown';
var ownerName = getCurrentFiberOwnerNameInDevOrNull();

if (ownerName) {
info += '\n\nCheck the render method of `' + ownerName + '`.';
}

var warningKey = componentName + '|' + (ownerName || '');

if (!didWarnAboutFunctionRefs[warningKey]) {
didWarnAboutFunctionRefs[warningKey] = true;

error('Function components cannot be given refs. ' + 'Attempts to access this ref will fail. ' + 'Did you mean to use React.forwardRef()?%s', info);
}
}

if (Component.defaultProps !== undefined) {
var _componentName = getComponentNameFromType(Component) || 'Unknown';

Expand Down Expand Up @@ -17259,7 +17241,9 @@ function commitAttachRef(finishedWork) {
{
// TODO: We should move these warnings to happen during the render
// phase (markRef).
if (!ref.hasOwnProperty('current')) {
if (typeof ref === 'string') {
error('String refs are no longer supported.');
} else if (!ref.hasOwnProperty('current')) {
error('Unexpected ref object provided for %s. ' + 'Use either a ref-setter function or React.createRef().', getComponentNameFromFiber(finishedWork));
}
} // $FlowFixMe[incompatible-use] unable to narrow type to the non-function case
Expand Down Expand Up @@ -23311,7 +23295,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}

var ReactVersion = '19.0.0-beta-860ea752';
var ReactVersion = '19.0.0-beta-7be9cfc9';

/*
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
Expand Down
Loading

0 comments on commit 67879d1

Please sign in to comment.