Skip to content

Commit 294a975

Browse files
committed
Restore currentRenderN instead of resetting it
1 parent 14309c7 commit 294a975

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

packages/react-reconciler/src/ReactFiberNewContext.new.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ import {
4848

4949
const valueCursor: StackCursor<mixed> = createCursor(null);
5050

51+
let rendererCursorDEV: StackCursor<Object | null>;
52+
if (__DEV__) {
53+
rendererCursorDEV = createCursor(null);
54+
}
55+
let renderer2CursorDEV: StackCursor<Object | null>;
56+
if (__DEV__) {
57+
renderer2CursorDEV = createCursor(null);
58+
}
59+
5160
let rendererSigil;
5261
if (__DEV__) {
5362
// Use this to detect multiple renderers using the same context
@@ -93,6 +102,8 @@ export function pushProvider<T>(
93102

94103
context._currentValue = nextValue;
95104
if (__DEV__) {
105+
push(rendererCursorDEV, context._currentRenderer, providerFiber);
106+
96107
if (
97108
context._currentRenderer !== undefined &&
98109
context._currentRenderer !== null &&
@@ -110,6 +121,8 @@ export function pushProvider<T>(
110121

111122
context._currentValue2 = nextValue;
112123
if (__DEV__) {
124+
push(renderer2CursorDEV, context._currentRenderer2, providerFiber);
125+
113126
if (
114127
context._currentRenderer2 !== undefined &&
115128
context._currentRenderer2 !== null &&
@@ -130,18 +143,24 @@ export function popProvider(
130143
providerFiber: Fiber,
131144
): void {
132145
const currentValue = valueCursor.current;
133-
pop(valueCursor, providerFiber);
146+
134147
if (isPrimaryRenderer) {
135148
context._currentValue = currentValue;
136149
if (__DEV__) {
137-
context._currentRenderer = null;
150+
const currentRenderer = rendererCursorDEV.current;
151+
pop(rendererCursorDEV, providerFiber);
152+
context._currentRenderer = currentRenderer;
138153
}
139154
} else {
140155
context._currentValue2 = currentValue;
141156
if (__DEV__) {
142-
context._currentRenderer2 = null;
157+
const currentRenderer2 = renderer2CursorDEV.current;
158+
pop(renderer2CursorDEV, providerFiber);
159+
context._currentRenderer2 = currentRenderer2;
143160
}
144161
}
162+
163+
pop(valueCursor, providerFiber);
145164
}
146165

147166
export function scheduleContextWorkOnParentPath(

packages/react-reconciler/src/ReactFiberNewContext.old.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ import {
4848

4949
const valueCursor: StackCursor<mixed> = createCursor(null);
5050

51+
let rendererCursorDEV: StackCursor<mixed>;
52+
if (__DEV__) {
53+
rendererCursorDEV = createCursor(null);
54+
}
55+
5156
let rendererSigil;
5257
if (__DEV__) {
5358
// Use this to detect multiple renderers using the same context
@@ -93,6 +98,8 @@ export function pushProvider<T>(
9398

9499
context._currentValue = nextValue;
95100
if (__DEV__) {
101+
push(rendererCursorDEV, context._currentRenderer, providerFiber)
102+
96103
if (
97104
context._currentRenderer !== undefined &&
98105
context._currentRenderer !== null &&
@@ -110,6 +117,8 @@ export function pushProvider<T>(
110117

111118
context._currentValue2 = nextValue;
112119
if (__DEV__) {
120+
push(rendererCursorDEV, context._currentRenderer2, providerFiber)
121+
113122
if (
114123
context._currentRenderer2 !== undefined &&
115124
context._currentRenderer2 !== null &&
@@ -134,12 +143,16 @@ export function popProvider(
134143
if (isPrimaryRenderer) {
135144
context._currentValue = currentValue;
136145
if (__DEV__) {
137-
context._currentRenderer = null;
146+
const currentRenderer = rendererCursorDEV.current
147+
pop(rendererCursorDEV, providerFiber);
148+
context._currentRenderer = currentRenderer;
138149
}
139150
} else {
140151
context._currentValue2 = currentValue;
141152
if (__DEV__) {
142-
context._currentRenderer2 = null;
153+
const currentRenderer2 = rendererCursorDEV.current
154+
pop(rendererCursorDEV, providerFiber);
155+
context._currentRenderer2 = currentRenderer2;
143156
}
144157
}
145158
}

0 commit comments

Comments
 (0)