Skip to content

Commit

Permalink
Merge pull request #1221 from eps1lon/fix/lazy-ref
Browse files Browse the repository at this point in the history
fix: Allow refs on lazy components
  • Loading branch information
theKashey authored Apr 5, 2019
2 parents df8eb13 + 1351f2d commit cd9a760
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/reconciler/fiberUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ export const updateLazy = (target, type) => {
const C = resolveType(m.default)
// chunks has been updated - new hot loader process is taking a place
enterHotUpdate()
if (!React.forwardRef) {
return {
default: props => (
<AppContainer>
<C {...props} />
</AppContainer>
),
}
}
return {
default: props => (
default: React.forwardRef((props, ref) => (
<AppContainer>
<C {...props} />
<C {...props} ref={ref} />
</AppContainer>
),
)),
}
})
target[lazyConstructor].isPatchedByReactHotLoader = true
Expand Down
4 changes: 3 additions & 1 deletion test/AppContainer.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,10 @@ describe(`AppContainer (dev)`, () => {
RHL.register(MountSpy, 'Pure', 'test.js')
RHL.register(Lazy, 'Lazy', 'test.js')

const ref = jest.fn()
class App extends Component {
render() {
return <Lazy />
return <Lazy ref={ref} />
}
}

Expand All @@ -927,6 +928,7 @@ describe(`AppContainer (dev)`, () => {
await Promise.resolve(1)

expect(spy).not.toHaveBeenCalled()
expect(ref).toHaveBeenCalledTimes(1)

expect(wrapper.root.findByProps({ children: 'I am old' })).toBeDefined()

Expand Down

0 comments on commit cd9a760

Please sign in to comment.