MCPcopy Index your code
hub / github.com/react/react / popToNearestCommonAncestor

Function popToNearestCommonAncestor

packages/react-server/src/ReactFizzNewContext.js:57–86  ·  view source on GitHub ↗
(
  prev: ContextNode<any>,
  next: ContextNode<any>,
)

Source from the content-addressed store, hash-verified

55}
56
57function popToNearestCommonAncestor(
58 prev: ContextNode<any>,
59 next: ContextNode<any>,
60): void {
61 if (prev === next) {
62 // We've found a shared ancestor. We don't need to pop nor reapply this one or anything above.
63 } else {
64 popNode(prev);
65 const parentPrev = prev.parent;
66 const parentNext = next.parent;
67 if (parentPrev === null) {
68 if (parentNext !== null) {
69 throw new Error(
70 'The stacks must reach the root at the same time. This is a bug in React.',
71 );
72 }
73 } else {
74 if (parentNext === null) {
75 throw new Error(
76 'The stacks must reach the root at the same time. This is a bug in React.',
77 );
78 }
79
80 popToNearestCommonAncestor(parentPrev, parentNext);
81 }
82
83 // On the way back, we push the new ones that weren't common.
84 pushNode(next);
85 }
86}
87
88function popAllPrevious(prev: ContextNode<any>): void {
89 popNode(prev);

Callers 3

popPreviousToCommonLevelFunction · 0.85
popNextToCommonLevelFunction · 0.85
switchContextFunction · 0.85

Calls 2

popNodeFunction · 0.85
pushNodeFunction · 0.85

Tested by

no test coverage detected