Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Nov 21, 2023
1 parent a25c5fb commit 881214d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/myreact-reconciler/src/dispatchContext/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const defaultGetContextFiber_New = (
renderDispatch: CustomRenderDispatch,
ContextObject?: ReturnType<typeof createContext> | null
) => {
if (fiber.parent && ContextObject) {
if (fiber?.parent && ContextObject) {
let parent = fiber.parent;
while (parent) {
if (include(parent.type, NODE_TYPE.__provider__)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const processComponentContextOnUpdate = (fiber: MyReactFiberNode) => {
const typedInstance = fiber.instance as MyReactComponent;

if (typedComponent.contextType) {
if (!typedInstance?._contextFiber || include(typedInstance._contextFiber.state, STATE_TYPE.__unmount__)) {
if (!typedInstance._contextFiber || include(typedInstance._contextFiber.state, STATE_TYPE.__unmount__)) {
const ProviderFiber = renderDispatch.resolveContextFiber(fiber, typedComponent.contextType);

const context = renderDispatch.resolveContextValue(ProviderFiber, typedComponent.contextType);
Expand Down

0 comments on commit 881214d

Please sign in to comment.