( prev: ContextNode<any>, next: ContextNode<any>, )
| 124 | } |
| 125 | |
| 126 | function popNextToCommonLevel( |
| 127 | prev: ContextNode<any>, |
| 128 | next: ContextNode<any>, |
| 129 | ): void { |
| 130 | const parentNext = next.parent; |
| 131 | |
| 132 | if (parentNext === null) { |
| 133 | throw new Error( |
| 134 | 'The depth must equal at least at zero before reaching the root. This is a bug in React.', |
| 135 | ); |
| 136 | } |
| 137 | |
| 138 | if (prev.depth === parentNext.depth) { |
| 139 | // We found the same level. Now we just need to find a shared ancestor. |
| 140 | popToNearestCommonAncestor(prev, parentNext); |
| 141 | } else { |
| 142 | // We must still be deeper. |
| 143 | popNextToCommonLevel(prev, parentNext); |
| 144 | } |
| 145 | pushNode(next); |
| 146 | } |
| 147 | |
| 148 | // Perform context switching to the new snapshot. |
| 149 | // To make it cheap to read many contexts, while not suspending, we make the switch eagerly by |
no test coverage detected