diff --git a/packages/myreact-reconciler/src/dispatchContext/feature.ts b/packages/myreact-reconciler/src/dispatchContext/feature.ts index 42f128bc..aaab7975 100644 --- a/packages/myreact-reconciler/src/dispatchContext/feature.ts +++ b/packages/myreact-reconciler/src/dispatchContext/feature.ts @@ -69,7 +69,7 @@ export const defaultGetContextFiber_New = ( renderDispatch: CustomRenderDispatch, ContextObject?: ReturnType | null ) => { - if (fiber.parent && ContextObject) { + if (fiber?.parent && ContextObject) { let parent = fiber.parent; while (parent) { if (include(parent.type, NODE_TYPE.__provider__)) { diff --git a/packages/myreact-reconciler/src/runtimeComponent/feature.ts b/packages/myreact-reconciler/src/runtimeComponent/feature.ts index c28cd38c..59ea3419 100644 --- a/packages/myreact-reconciler/src/runtimeComponent/feature.ts +++ b/packages/myreact-reconciler/src/runtimeComponent/feature.ts @@ -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);