MCPcopy Create free account
hub / github.com/reactjs/react-rails / remountFiber

Function remountFiber

lib/assets/react-source/development/react.js:22048–22103  ·  view source on GitHub ↗
(current, oldWorkInProgress, newWorkInProgress)

Source from the content-addressed store, hash-verified

22046 }
22047
22048 function remountFiber(current, oldWorkInProgress, newWorkInProgress) {
22049 {
22050 var returnFiber = oldWorkInProgress.return;
22051
22052 if (returnFiber === null) {
22053 throw new Error('Cannot swap the root fiber.');
22054 } // Disconnect from the old current.
22055 // It will get deleted.
22056
22057
22058 current.alternate = null;
22059 oldWorkInProgress.alternate = null; // Connect to the new tree.
22060
22061 newWorkInProgress.index = oldWorkInProgress.index;
22062 newWorkInProgress.sibling = oldWorkInProgress.sibling;
22063 newWorkInProgress.return = oldWorkInProgress.return;
22064 newWorkInProgress.ref = oldWorkInProgress.ref; // Replace the child/sibling pointers above it.
22065
22066 if (oldWorkInProgress === returnFiber.child) {
22067 returnFiber.child = newWorkInProgress;
22068 } else {
22069 var prevSibling = returnFiber.child;
22070
22071 if (prevSibling === null) {
22072 throw new Error('Expected parent to have a child.');
22073 }
22074
22075 while (prevSibling.sibling !== oldWorkInProgress) {
22076 prevSibling = prevSibling.sibling;
22077
22078 if (prevSibling === null) {
22079 throw new Error('Expected to find the previous sibling.');
22080 }
22081 }
22082
22083 prevSibling.sibling = newWorkInProgress;
22084 } // Delete the old fiber and place the new one.
22085 // Since the old fiber is disconnected, we have to schedule it manually.
22086
22087
22088 var last = returnFiber.lastEffect;
22089
22090 if (last !== null) {
22091 last.nextEffect = current;
22092 returnFiber.lastEffect = current;
22093 } else {
22094 returnFiber.firstEffect = returnFiber.lastEffect = current;
22095 }
22096
22097 current.nextEffect = null;
22098 current.effectTag = Deletion;
22099 newWorkInProgress.effectTag |= Placement; // Restart work from the new fiber.
22100
22101 return newWorkInProgress;
22102 }
22103 }
22104
22105 function beginWork(current, workInProgress, renderExpirationTime) {

Callers 1

beginWorkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected