Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wire up Context Provider type
  • Loading branch information
sebmarkbage committed Apr 13, 2021
commit 0459b9b0834e35330429def10f9f62732fa52f7d
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFizzNewContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function pushProvider<T>(
return newNode;
}

export function popProvider<T>(context: ReactContext<T>): void {
export function popProvider<T>(context: ReactContext<T>): ContextSnapshot {
const prevSnapshot = currentActiveSnapshot;
invariant(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check this in prod?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It follows the principle that if it's getting checked by runtime type checks here anyway, it likely isn't a perf cost (other than the extra code). The prevSnapshot.context access after does that anyway.

prevSnapshot !== null,
Expand Down Expand Up @@ -263,7 +263,7 @@ export function popProvider<T>(context: ReactContext<T>): void {
context._currentRenderer2 = rendererSigil;
}
}
currentActiveSnapshot = prevSnapshot.parent;
return (currentActiveSnapshot = prevSnapshot.parent);
}

export function getActiveContext(): ContextSnapshot {
Expand Down
20 changes: 19 additions & 1 deletion packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import {
rootContextSnapshot,
switchContext,
getActiveContext,
pushProvider,
popProvider,
} from './ReactFizzNewContext';

import {
Expand Down Expand Up @@ -748,7 +750,23 @@ function renderContextProvider(
type: ReactProviderType<any>,
props: Object,
): void {
throw new Error('Not yet implemented element type.');
const context = type._context;
const value = props.value;
const children = props.children;
let prevSnapshot;
if (__DEV__) {
prevSnapshot = task.context;
}
task.context = pushProvider(context, value);
renderNodeDestructive(request, task, children);
task.context = popProvider(context);
if (__DEV__) {
if (prevSnapshot !== task.context) {
console.error(
'Popping the context provider did not return back to the original snapshot. This is a bug in React.',
);
}
}
}

function renderLazyComponent(
Expand Down