( prev: ContextNode<any>, next: ContextNode<any>, )
| 55 | } |
| 56 | |
| 57 | function 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 | |
| 88 | function popAllPrevious(prev: ContextNode<any>): void { |
| 89 | popNode(prev); |
no test coverage detected