Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,13 @@ function _connect<
// Now that all that's done, we can finally try to actually render the child component.
// We memoize the elements for the rendered child component as an optimization.
const renderedWrappedComponent = React.useMemo(() => {
const effectiveProps = { ...actualChildProps }
if (forwardRef) {
effectiveProps.ref = reactReduxForwardedRef
}
return (
// @ts-ignore
<WrappedComponent
{...actualChildProps}
ref={reactReduxForwardedRef}
/>
<WrappedComponent {...effectiveProps} />
)
}, [reactReduxForwardedRef, WrappedComponent, actualChildProps])

Expand Down
27 changes: 27 additions & 0 deletions test/components/connect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,33 @@ describe('React', () => {

expect(tester.getByTestId('a')).toHaveTextContent('42')
})

it('should not override a ref prop when forwardRef is not enabled', () => {
type RootStateType = {}
const store = createStore(() => ({}))
type RefReceiverPropsType = {}
const RefReceiver = React.forwardRef<
HTMLSpanElement,
RefReceiverPropsType
>((props: RefReceiverPropsType, ref) => <span ref={ref} />)
type RefReceiverNoDispatchType = null
const decorator = connect<
RefReceiverPropsType,
RefReceiverNoDispatchType,
RefReceiverPropsType,
RootStateType
>(null, null, null, {
forwardRef: IS_REACT_18,
})
const DecoratedRefReceiver = decorator(RefReceiver)
const testRef = React.createRef<HTMLSpanElement>()
rtl.render(
<ProviderMock store={store}>
<DecoratedRefReceiver ref={testRef} />
</ProviderMock>,
)
expect(testRef.current).toBeInstanceOf(HTMLSpanElement)
})
})

describe('Factory functions for mapState/mapDispatch', () => {
Expand Down
Loading