Skip to content

Commit 2c59194

Browse files
committed
Fixes server rendering of jobs to respect work per element instance, not per component instance. Work is not shared.
1 parent 00aab36 commit 2c59194

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/JobProvider.js

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class JobProvider extends Component {
77
children: PropTypes.node.isRequired,
88
jobContext: PropTypes.shape({
99
getNextId: PropTypes.func.isRequired,
10+
resetIds: PropTypes.func.isRequired,
1011
register: PropTypes.func.isRequired,
1112
get: PropTypes.func.isRequired,
1213
getState: PropTypes.func.isRequired,
@@ -33,6 +34,17 @@ class JobProvider extends Component {
3334
}).isRequired,
3435
};
3536

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+
3648
componentWillMount() {
3749
this.jobContext = this.props.jobContext || createJobContext()
3850
this.rehydrateState = this.props.rehydrateState

src/createJobContext.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export default function createJobContext() {
66
idPointer += 1
77
return idPointer
88
},
9+
resetIds: () => {
10+
idPointer = 0
11+
},
912
register: (jobID, result) => {
1013
jobs[jobID] = result
1114
},

src/withJob.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export default function withJob(config) {
4646
constructor(props, context) {
4747
super(props, context)
4848

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) {
5052
id = context.jobs.getNextId()
5153
}
5254
}

0 commit comments

Comments
 (0)