mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
d9c1dbd617
* Enable Yarn workspaces for packages/* * Move src/isomorphic/* into packages/react/src/* * Create index.js stubs for all packages in packages/* This makes the test pass again, but breaks the build because npm/ folders aren't used yet. I'm not sure if we'll keep this structure--I'll just keep working and fix the build after it settles down. * Put FB entry point for react-dom into packages/* * Move src/renderers/testing/* into packages/react-test-renderer/src/* Note that this is currently broken because Jest ignores node_modules, and so Yarn linking makes Jest skip React source when transforming. * Remove src/node_modules It is now unnecessary. Some tests fail though. * Add a hacky workaround for Jest/Workspaces issue Jest sees node_modules and thinks it's third party code. This is a hacky way to teach Jest to still transform anything in node_modules/react* if it resolves outside of node_modules (such as to our packages/*) folder. I'm not very happy with this and we should revisit. * Add a fake react-native package * Move src/renderers/art/* into packages/react-art/src/* * Move src/renderers/noop/* into packages/react-noop-renderer/src/* * Move src/renderers/dom/* into packages/react-dom/src/* * Move src/renderers/shared/fiber/* into packages/react-reconciler/src/* * Move DOM/reconciler tests I previously forgot to move * Move src/renderers/native-*/* into packages/react-native-*/src/* * Move shared code into packages/shared It's not super clear how to organize this properly yet. * Add back files that somehow got lost * Fix the build * Prettier * Add missing license headers * Fix an issue that caused mocks to get included into build * Update other references to src/ * Re-run Prettier * Fix lint * Fix weird Flow violation I didn't change this file but Flow started complaining. Caleb said this annotation was unnecessarily using $Abstract though so I removed it. * Update sizes * Fix stats script * Fix packaging fixtures Use file: instead of NODE_PATH since NODE_PATH. NODE_PATH trick only worked because we had no react/react-dom in root node_modules, but now we do. file: dependency only works as I expect in Yarn, so I moved the packaging fixtures to use Yarn and committed lockfiles. Verified that the page shows up. * Fix art fixture * Fix reconciler fixture * Fix SSR fixture * Rename native packages
114 lines
4.1 KiB
JavaScript
114 lines
4.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @providesModule findNodeHandle
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var ReactInstanceMap = require('ReactInstanceMap');
|
|
var ReactNativeFiberRenderer = require('ReactNativeFiberRenderer');
|
|
var {ReactCurrentOwner} = require('ReactGlobalSharedState');
|
|
var getComponentName = require('getComponentName');
|
|
var invariant = require('fbjs/lib/invariant');
|
|
|
|
if (__DEV__) {
|
|
var warning = require('fbjs/lib/warning');
|
|
}
|
|
|
|
import type {Fiber} from 'ReactFiber';
|
|
|
|
/**
|
|
* ReactNative vs ReactWeb
|
|
* -----------------------
|
|
* React treats some pieces of data opaquely. This means that the information
|
|
* is first class (it can be passed around), but cannot be inspected. This
|
|
* allows us to build infrastructure that reasons about resources, without
|
|
* making assumptions about the nature of those resources, and this allows that
|
|
* infra to be shared across multiple platforms, where the resources are very
|
|
* different. General infra (such as `ReactMultiChild`) reasons opaquely about
|
|
* the data, but platform specific code (such as `ReactNativeBaseComponent`) can
|
|
* make assumptions about the data.
|
|
*
|
|
*
|
|
* `rootNodeID`, uniquely identifies a position in the generated native view
|
|
* tree. Many layers of composite components (created with `React.createClass`)
|
|
* can all share the same `rootNodeID`.
|
|
*
|
|
* `nodeHandle`: A sufficiently unambiguous way to refer to a lower level
|
|
* resource (dom node, native view etc). The `rootNodeID` is sufficient for web
|
|
* `nodeHandle`s, because the position in a tree is always enough to uniquely
|
|
* identify a DOM node (we never have nodes in some bank outside of the
|
|
* document). The same would be true for `ReactNative`, but we must maintain a
|
|
* mapping that we can send efficiently serializable
|
|
* strings across native boundaries.
|
|
*
|
|
* Opaque name TodaysWebReact FutureWebWorkerReact ReactNative
|
|
* ----------------------------------------------------------------------------
|
|
* nodeHandle N/A rootNodeID tag
|
|
*/
|
|
|
|
// TODO (bvaughn) Rename the findNodeHandle module to something more descriptive
|
|
// eg findInternalHostInstance. This will reduce the likelihood of someone
|
|
// accidentally deep-requiring this version.
|
|
function findNodeHandle(componentOrHandle: any): any {
|
|
if (__DEV__) {
|
|
var owner = ReactCurrentOwner.current;
|
|
if (owner !== null && owner.stateNode !== null) {
|
|
warning(
|
|
owner.stateNode._warnedAboutRefsInRender,
|
|
'%s is accessing findNodeHandle inside its render(). ' +
|
|
'render() should be a pure function of props and state. It should ' +
|
|
'never access something that requires stale data from the previous ' +
|
|
'render, such as refs. Move this logic to componentDidMount and ' +
|
|
'componentDidUpdate instead.',
|
|
getComponentName(owner) || 'A component',
|
|
);
|
|
|
|
owner.stateNode._warnedAboutRefsInRender = true;
|
|
}
|
|
}
|
|
if (componentOrHandle == null) {
|
|
return null;
|
|
}
|
|
if (typeof componentOrHandle === 'number') {
|
|
// Already a node handle
|
|
return componentOrHandle;
|
|
}
|
|
|
|
var component = componentOrHandle;
|
|
|
|
// TODO (balpert): Wrap iOS native components in a composite wrapper, then
|
|
// ReactInstanceMap.get here will always succeed for mounted components
|
|
var internalInstance: Fiber = ReactInstanceMap.get(component);
|
|
if (internalInstance) {
|
|
return ReactNativeFiberRenderer.findHostInstance(internalInstance);
|
|
} else {
|
|
if (component) {
|
|
return component;
|
|
} else {
|
|
invariant(
|
|
// Native
|
|
(typeof component === 'object' && '_nativeTag' in component) ||
|
|
// Composite
|
|
(component.render != null && typeof component.render === 'function'),
|
|
'findNodeHandle(...): Argument is not a component ' +
|
|
'(type: %s, keys: %s)',
|
|
typeof component,
|
|
Object.keys(component),
|
|
);
|
|
invariant(
|
|
false,
|
|
'findNodeHandle(...): Unable to find node handle for unmounted ' +
|
|
'component.',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = findNodeHandle;
|