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

Function createWorkInProgress

packages/react-reconciler/src/ReactFiber.js:325–436  ·  view source on GitHub ↗
(current: Fiber, pendingProps: any)

Source from the content-addressed store, hash-verified

323
324// This is used to create an alternate fiber to do work on.
325export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
326 let workInProgress = current.alternate;
327 if (workInProgress === null) {
328 // We use a double buffering pooling technique because we know that we'll
329 // only ever need at most two versions of a tree. We pool the "other" unused
330 // node that we're free to reuse. This is lazily created to avoid allocating
331 // extra objects for things that are never updated. It also allow us to
332 // reclaim the extra memory if needed.
333 workInProgress = createFiber(
334 current.tag,
335 pendingProps,
336 current.key,
337 current.mode,
338 );
339 workInProgress.elementType = current.elementType;
340 workInProgress.type = current.type;
341 workInProgress.stateNode = current.stateNode;
342
343 if (__DEV__) {
344 // DEV-only fields
345
346 workInProgress._debugOwner = current._debugOwner;
347 workInProgress._debugStack = current._debugStack;
348 workInProgress._debugTask = current._debugTask;
349 workInProgress._debugHookTypes = current._debugHookTypes;
350 }
351
352 workInProgress.alternate = current;
353 current.alternate = workInProgress;
354 } else {
355 workInProgress.pendingProps = pendingProps;
356 // Needed because Blocks store data on type.
357 workInProgress.type = current.type;
358
359 // We already have an alternate.
360 // Reset the effect tag.
361 workInProgress.flags = NoFlags;
362
363 // The effects are no longer valid.
364 workInProgress.subtreeFlags = NoFlags;
365 workInProgress.deletions = null;
366
367 if (enableProfilerTimer) {
368 // We intentionally reset, rather than copy, actualDuration & actualStartTime.
369 // This prevents time from endlessly accumulating in new commits.
370 // This has the downside of resetting values for different priority renders,
371 // But works for yielding (the common case) and should support resuming.
372 workInProgress.actualDuration = -0;
373 workInProgress.actualStartTime = -1.1;
374 }
375 }
376
377 // Reset all effects except static ones.
378 // Static effects are not specific to a render.
379 workInProgress.flags = current.flags & StaticMask;
380 workInProgress.childLanes = current.childLanes;
381 workInProgress.lanes = current.lanes;
382

Callers 6

updateMemoComponentFunction · 0.90
prepareFreshStackFunction · 0.90
useFiberFunction · 0.90
cloneChildFibersFunction · 0.90

Tested by

no test coverage detected