MCPcopy
hub / github.com/facebook/react / updateHostComponent

Function updateHostComponent

packages/react-reconciler/src/ReactFiberBeginWork.js:1931–1997  ·  view source on GitHub ↗
(
  current: Fiber | null,
  workInProgress: Fiber,
  renderLanes: Lanes,
)

Source from the content-addressed store, hash-verified

1929}
1930
1931function updateHostComponent(
1932 current: Fiber | null,
1933 workInProgress: Fiber,
1934 renderLanes: Lanes,
1935) {
1936 if (current === null) {
1937 tryToClaimNextHydratableInstance(workInProgress);
1938 }
1939
1940 pushHostContext(workInProgress);
1941
1942 const type = workInProgress.type;
1943 const nextProps = workInProgress.pendingProps;
1944 const prevProps = current !== null ? current.memoizedProps : null;
1945
1946 let nextChildren = nextProps.children;
1947 const isDirectTextChild = shouldSetTextContent(type, nextProps);
1948
1949 if (isDirectTextChild) {
1950 // We special case a direct text child of a host node. This is a common
1951 // case. We won't handle it as a reified child. We will instead handle
1952 // this in the host environment that also has access to this prop. That
1953 // avoids allocating another HostText fiber and traversing it.
1954 nextChildren = null;
1955 } else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
1956 // If we're switching from a direct text child to a normal child, or to
1957 // empty, we need to schedule the text content to be reset.
1958 workInProgress.flags |= ContentReset;
1959 }
1960
1961 const memoizedState = workInProgress.memoizedState;
1962 if (memoizedState !== null) {
1963 // This fiber has been upgraded to a stateful component. The only way
1964 // happens currently is for form actions. We use hooks to track the
1965 // pending and error state of the form.
1966 //
1967 // Once a fiber is upgraded to be stateful, it remains stateful for the
1968 // rest of its lifetime.
1969 const newState = renderTransitionAwareHostComponentWithHooks(
1970 current,
1971 workInProgress,
1972 renderLanes,
1973 );
1974
1975 // If the transition state changed, propagate the change to all the
1976 // descendents. We use Context as an implementation detail for this.
1977 //
1978 // This is intentionally set here instead of pushHostContext because
1979 // pushHostContext gets called before we process the state hook, to avoid
1980 // a state mismatch in the event that something suspends.
1981 //
1982 // NOTE: This assumes that there cannot be nested transition providers,
1983 // because the only renderer that implements this feature is React DOM,
1984 // and forms cannot be nested. If we did support nested providers, then
1985 // we would need to push a context value even for host fibers that
1986 // haven't been upgraded yet.
1987 if (isPrimaryRenderer) {
1988 HostTransitionContext._currentValue = newState;

Callers 1

beginWorkFunction · 0.70

Calls 5

pushHostContextFunction · 0.90
shouldSetTextContentFunction · 0.90
markRefFunction · 0.85
reconcileChildrenFunction · 0.85

Tested by

no test coverage detected