Commit 2c59194 1 parent 00aab36 commit 2c59194 Copy full SHA for 2c59194
File tree 3 files changed +18
-1
lines changed
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class JobProvider extends Component {
7
7
children : PropTypes . node . isRequired ,
8
8
jobContext : PropTypes . shape ( {
9
9
getNextId : PropTypes . func . isRequired ,
10
+ resetIds : PropTypes . func . isRequired ,
10
11
register : PropTypes . func . isRequired ,
11
12
get : PropTypes . func . isRequired ,
12
13
getState : PropTypes . func . isRequired ,
@@ -33,6 +34,17 @@ class JobProvider extends Component {
33
34
} ) . isRequired ,
34
35
} ;
35
36
37
+ constructor ( props , context ) {
38
+ super ( props , context )
39
+
40
+ // This is a workaround because each element instance of a job needs its
41
+ // own ids. So between the bootstrapping and the render we need to reset
42
+ // the id counter to ensure the ids will match.
43
+ if ( props . jobContext ) {
44
+ props . jobContext . resetIds ( )
45
+ }
46
+ }
47
+
36
48
componentWillMount ( ) {
37
49
this . jobContext = this . props . jobContext || createJobContext ( )
38
50
this . rehydrateState = this . props . rehydrateState
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ export default function createJobContext() {
6
6
idPointer += 1
7
7
return idPointer
8
8
} ,
9
+ resetIds : ( ) => {
10
+ idPointer = 0
11
+ } ,
9
12
register : ( jobID , result ) => {
10
13
jobs [ jobID ] = result
11
14
} ,
Original file line number Diff line number Diff line change @@ -46,7 +46,9 @@ export default function withJob(config) {
46
46
constructor ( props , context ) {
47
47
super ( props , context )
48
48
49
- if ( context . jobs && ! id ) {
49
+ // Each instance needs it's own id as that is how we expect work to
50
+ // be executed. It is not shared between element instances.
51
+ if ( context . jobs ) {
50
52
id = context . jobs . getNextId ( )
51
53
}
52
54
}
You can’t perform that action at this time.
0 commit comments