Skip to content

Commit

Permalink
Restore currentRenderN instead of resetting it
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 19, 2022
1 parent 5388c3d commit 42f964f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
25 changes: 22 additions & 3 deletions packages/react-reconciler/src/ReactFiberNewContext.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols

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

let rendererCursorDEV: StackCursor<Object | null>;
if (__DEV__) {
rendererCursorDEV = createCursor(null);
}
let renderer2CursorDEV: StackCursor<Object | null>;
if (__DEV__) {
renderer2CursorDEV = createCursor(null);
}

let rendererSigil;
if (__DEV__) {
// Use this to detect multiple renderers using the same context
Expand Down Expand Up @@ -95,6 +104,8 @@ export function pushProvider<T>(

context._currentValue = nextValue;
if (__DEV__) {
push(rendererCursorDEV, context._currentRenderer, providerFiber);

if (
context._currentRenderer !== undefined &&
context._currentRenderer !== null &&
Expand All @@ -112,6 +123,8 @@ export function pushProvider<T>(

context._currentValue2 = nextValue;
if (__DEV__) {
push(renderer2CursorDEV, context._currentRenderer2, providerFiber);

if (
context._currentRenderer2 !== undefined &&
context._currentRenderer2 !== null &&
Expand All @@ -132,7 +145,7 @@ export function popProvider(
providerFiber: Fiber,
): void {
const currentValue = valueCursor.current;
pop(valueCursor, providerFiber);

if (isPrimaryRenderer) {
if (
enableServerContext &&
Expand All @@ -143,7 +156,9 @@ export function popProvider(
context._currentValue = currentValue;
}
if (__DEV__) {
context._currentRenderer = null;
const currentRenderer = rendererCursorDEV.current;
pop(rendererCursorDEV, providerFiber);
context._currentRenderer = currentRenderer;
}
} else {
if (
Expand All @@ -155,9 +170,13 @@ export function popProvider(
context._currentValue2 = currentValue;
}
if (__DEV__) {
context._currentRenderer2 = null;
const currentRenderer2 = renderer2CursorDEV.current;
pop(renderer2CursorDEV, providerFiber);
context._currentRenderer2 = currentRenderer2;
}
}

pop(valueCursor, providerFiber);
}

export function scheduleContextWorkOnParentPath(
Expand Down
25 changes: 22 additions & 3 deletions packages/react-reconciler/src/ReactFiberNewContext.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols

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

let rendererCursorDEV: StackCursor<Object | null>;
if (__DEV__) {
rendererCursorDEV = createCursor(null);
}
let renderer2CursorDEV: StackCursor<Object | null>;
if (__DEV__) {
renderer2CursorDEV = createCursor(null);
}

let rendererSigil;
if (__DEV__) {
// Use this to detect multiple renderers using the same context
Expand Down Expand Up @@ -95,6 +104,8 @@ export function pushProvider<T>(

context._currentValue = nextValue;
if (__DEV__) {
push(rendererCursorDEV, context._currentRenderer, providerFiber);

if (
context._currentRenderer !== undefined &&
context._currentRenderer !== null &&
Expand All @@ -112,6 +123,8 @@ export function pushProvider<T>(

context._currentValue2 = nextValue;
if (__DEV__) {
push(renderer2CursorDEV, context._currentRenderer2, providerFiber);

if (
context._currentRenderer2 !== undefined &&
context._currentRenderer2 !== null &&
Expand All @@ -132,7 +145,7 @@ export function popProvider(
providerFiber: Fiber,
): void {
const currentValue = valueCursor.current;
pop(valueCursor, providerFiber);

if (isPrimaryRenderer) {
if (
enableServerContext &&
Expand All @@ -143,7 +156,9 @@ export function popProvider(
context._currentValue = currentValue;
}
if (__DEV__) {
context._currentRenderer = null;
const currentRenderer = rendererCursorDEV.current;
pop(rendererCursorDEV, providerFiber);
context._currentRenderer = currentRenderer;
}
} else {
if (
Expand All @@ -155,9 +170,13 @@ export function popProvider(
context._currentValue2 = currentValue;
}
if (__DEV__) {
context._currentRenderer2 = null;
const currentRenderer2 = renderer2CursorDEV.current;
pop(renderer2CursorDEV, providerFiber);
context._currentRenderer2 = currentRenderer2;
}
}

pop(valueCursor, providerFiber);
}

export function scheduleContextWorkOnParentPath(
Expand Down

0 comments on commit 42f964f

Please sign in to comment.