@@ -12,7 +12,7 @@ import {
12
12
import { getLabwareNamesByModuleId } from '../ui/modules/selectors'
13
13
import type { ComputeRobotStateTimelineSuccessAction } from '../file-data/actions'
14
14
import type { Middleware } from 'redux'
15
- import type { BaseState } from '../types'
15
+ import type { Action , BaseState } from '../types'
16
16
import type { GenerateRobotStateTimelineArgs } from './generateRobotStateTimeline'
17
17
import type { SubstepsArgsNoTimeline , WorkerResponse } from './types'
18
18
@@ -51,7 +51,10 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
51
51
let prevSubstepsArgs : SubstepsArgsNoTimeline | null = null
52
52
let prevSuccessAction : ComputeRobotStateTimelineSuccessAction | null = null
53
53
54
- const timelineNeedsRecompute = ( state : BaseState ) : boolean => {
54
+ const timelineNeedsRecompute = (
55
+ state : BaseState ,
56
+ actionType : string
57
+ ) : boolean => {
55
58
const nextSelectorResults = getTimelineArgs ( state )
56
59
57
60
if ( prevTimelineArgs === null ) {
@@ -63,10 +66,13 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
63
66
const needsRecompute = hasChanged ( nextSelectorResults , prevTimelineArgs )
64
67
// update memoized values
65
68
prevTimelineArgs = nextSelectorResults
66
- return needsRecompute
69
+ return needsRecompute || actionType === 'LOAD_FILE'
67
70
}
68
71
69
- const substepsNeedsRecompute = ( state : BaseState ) : boolean => {
72
+ const substepsNeedsRecompute = (
73
+ state : BaseState ,
74
+ actionType : string
75
+ ) : boolean => {
70
76
if ( prevSubstepsArgs === null ) {
71
77
// initial call, must populate memoized value
72
78
prevSubstepsArgs = getSubstepsArgs ( state )
@@ -80,18 +86,20 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
80
86
)
81
87
prevSubstepsArgs = nextSubstepSelectorResults // update memoized value
82
88
83
- return needsRecompute
89
+ return needsRecompute || actionType === 'LOAD_FILE'
84
90
}
85
91
86
- return ( { getState, dispatch } ) => next => action => {
92
+ return ( { getState, dispatch } ) => next => ( action : Action ) => {
87
93
// call the next dispatch method in the middleware chain
88
94
const returnValue = next ( action )
89
95
const nextState = getState ( )
90
96
const shouldRecomputeTimeline = timelineNeedsRecompute (
91
- nextState as BaseState
97
+ nextState as BaseState ,
98
+ action . type
92
99
)
93
100
const shouldRecomputeSubsteps = substepsNeedsRecompute (
94
- nextState as BaseState
101
+ nextState as BaseState ,
102
+ action . type
95
103
)
96
104
97
105
// TODO: how to stop re-assigning this event handler every middleware call? We need
0 commit comments