Skip to content

Commit

Permalink
Fix use of stale props in Fabric events
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Mar 16, 2023
1 parent e4606c1 commit cf729bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getNodeFromInstance(fiber: Fiber): PublicInstance {
}

function getFiberCurrentPropsFromNode(instance: Instance): Props {
return instance.currentProps;
return instance.propsRef.current;
}

export {
Expand Down
14 changes: 9 additions & 5 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export type Instance = {
node: Node,
nativeTag: number,
viewConfig: ViewConfig,
currentProps: Props,
propsRef: {
current: Props,
},
// Reference to the React handle (the fiber)
internalInstanceHandle: Object,
// Exposed through refs.
Expand Down Expand Up @@ -150,7 +152,9 @@ export function createInstance(
node: node,
nativeTag: tag,
viewConfig,
currentProps: props,
propsRef: {
current: props,
},
internalInstanceHandle,
publicInstance: component,
};
Expand Down Expand Up @@ -254,7 +258,7 @@ export function prepareUpdate(
// TODO: If the event handlers have changed, we need to update the current props
// in the commit phase but there is no host config hook to do it yet.
// So instead we hack it by updating it in the render phase.
instance.currentProps = newProps;
instance.propsRef.current = newProps;
return updatePayload;
}

Expand Down Expand Up @@ -335,7 +339,7 @@ export function cloneInstance(
node: clone,
nativeTag: instance.nativeTag,
viewConfig: instance.viewConfig,
currentProps: instance.currentProps,
propsRef: instance.propsRef,
internalInstanceHandle: instance.internalInstanceHandle,
publicInstance: instance.publicInstance,
};
Expand All @@ -357,7 +361,7 @@ export function cloneHiddenInstance(
node: cloneNodeWithNewProps(node, updatePayload),
nativeTag: instance.nativeTag,
viewConfig: instance.viewConfig,
currentProps: instance.currentProps,
propsRef: instance.propsRef,
internalInstanceHandle: instance.internalInstanceHandle,
publicInstance: instance.publicInstance,
};
Expand Down

0 comments on commit cf729bf

Please sign in to comment.