Skip to content

Commit

Permalink
Fix cloneElement using string ref w no owner
Browse files Browse the repository at this point in the history
  • Loading branch information
josephsavona committed Apr 9, 2024
1 parent 7f93cb4 commit 9529872
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/react/src/__tests__/ReactElementClone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ describe('ReactElementClone', () => {
) {
expect(clone.ref).toBe(element.ref);
expect(clone.props).toEqual({foo: 'ef'});
} else if (
gate(flags => flags.enableRefAsProp && !flags.disableStringRefs)
) {
expect(clone.ref).toBe(element.ref);
expect(clone.props).toEqual({foo: 'ef'});
} else {
// Not going to bother testing every possible combination.
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,11 @@ export function cloneElement(element, config, children) {
if (!enableRefAsProp) {
// Silently steal the ref from the parent.
ref = config.ref;
owner = ReactSharedInternals.owner;
if (!disableStringRefs) {
ref = coerceStringRef(ref, owner, element.type);
}
}
owner = ReactSharedInternals.owner;
}
if (hasValidKey(config)) {
if (__DEV__) {
Expand Down

0 comments on commit 9529872

Please sign in to comment.