Skip to content

Commit 9a7dacc

Browse files
authored
Revert "fix timing issue in component updates due to consecutive dispatches (#1263)"
This reverts commit d162625.
1 parent d162625 commit 9a7dacc

File tree

2 files changed

+1
-54
lines changed

2 files changed

+1
-54
lines changed

src/components/connectAdvanced.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ export default function connectAdvanced(
253253
const lastChildProps = useRef()
254254
const lastWrapperProps = useRef(wrapperProps)
255255
const childPropsFromStoreUpdate = useRef()
256-
const renderIsScheduled = useRef(false)
257256

258257
const actualChildProps = usePureOnlyMemo(() => {
259258
// Tricky logic here:
@@ -283,7 +282,6 @@ export default function connectAdvanced(
283282
// We want to capture the wrapper props and child props we used for later comparisons
284283
lastWrapperProps.current = wrapperProps
285284
lastChildProps.current = actualChildProps
286-
renderIsScheduled.current = false
287285

288286
// If the render was from a store update, clear out that reference and cascade the subscriber update
289287
if (childPropsFromStoreUpdate.current) {
@@ -330,17 +328,14 @@ export default function connectAdvanced(
330328

331329
// If the child props haven't changed, nothing to do here - cascade the subscription update
332330
if (newChildProps === lastChildProps.current) {
333-
if (!renderIsScheduled.current) {
334-
notifyNestedSubs()
335-
}
331+
notifyNestedSubs()
336332
} else {
337333
// Save references to the new child props. Note that we track the "child props from store update"
338334
// as a ref instead of a useState/useReducer because we need a way to determine if that value has
339335
// been processed. If this went into useState/useReducer, we couldn't clear out the value without
340336
// forcing another re-render, which we don't want.
341337
lastChildProps.current = newChildProps
342338
childPropsFromStoreUpdate.current = newChildProps
343-
renderIsScheduled.current = true
344339

345340
// If the child props _did_ change (or we caught an error), this wrapper component needs to re-render
346341
forceComponentUpdateDispatch({

test/components/connect.spec.js

-48
Original file line numberDiff line numberDiff line change
@@ -3182,54 +3182,6 @@ describe('React', () => {
31823182

31833183
expect(reduxCountPassedToMapState).toEqual(3)
31843184
})
3185-
3186-
it('should ensure top-down updates for consecutive batched updates', () => {
3187-
const INC = 'INC'
3188-
const reducer = (c = 0, { type }) => (type === INC ? c + 1 : c)
3189-
const store = createStore(reducer)
3190-
3191-
let executionOrder = []
3192-
let expectedExecutionOrder = [
3193-
'parent map',
3194-
'parent render',
3195-
'child map',
3196-
'child render'
3197-
]
3198-
3199-
const ChildImpl = () => {
3200-
executionOrder.push('child render')
3201-
return <div>child</div>
3202-
}
3203-
3204-
const Child = connect(state => {
3205-
executionOrder.push('child map')
3206-
return { state }
3207-
})(ChildImpl)
3208-
3209-
const ParentImpl = () => {
3210-
executionOrder.push('parent render')
3211-
return <Child />
3212-
}
3213-
3214-
const Parent = connect(state => {
3215-
executionOrder.push('parent map')
3216-
return { state }
3217-
})(ParentImpl)
3218-
3219-
rtl.render(
3220-
<ProviderMock store={store}>
3221-
<Parent />
3222-
</ProviderMock>
3223-
)
3224-
3225-
executionOrder = []
3226-
rtl.act(() => {
3227-
store.dispatch({ type: INC })
3228-
store.dispatch({ type: '' })
3229-
})
3230-
3231-
expect(executionOrder).toEqual(expectedExecutionOrder)
3232-
})
32333185
})
32343186

32353187
it("should enforce top-down updates to ensure a deleted child's mapState doesn't throw errors", () => {

0 commit comments

Comments
 (0)