Skip to content

Commit d5db814

Browse files
fix(overmind-react): fix last component tracking
1 parent 1202533 commit d5db814

File tree

1 file changed

+30
-16
lines changed
  • packages/node_modules/overmind-react/src

1 file changed

+30
-16
lines changed

packages/node_modules/overmind-react/src/index.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export const createHook = <Config extends Configuration>(
9494
},
9595
[]
9696
)
97+
98+
useLayoutEffect(() => tree.stopTracking())
9799
} else {
98100
const [componentInstanceId] = useState<any>(
99101
() => currentComponentInstanceId++
@@ -110,6 +112,8 @@ export const createHook = <Config extends Configuration>(
110112
})
111113
})
112114

115+
useLayoutEffect(() => tree.stopTracking())
116+
113117
useEffect(() => {
114118
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
115119
componentId: component.__componentId,
@@ -158,9 +162,10 @@ export const createConnect = <A extends Overmind<Configuration>>(
158162
if (isClassComponent) {
159163
const originalRender = component.prototype.render
160164
component.prototype.render = function() {
161-
this.props.overmind &&
162-
this.props.overmind.tree.track(this.props.overmind.onUpdate)
163-
return originalRender.call(this)
165+
return this.props.overmind.tree.trackScope(
166+
() => originalRender.call(this),
167+
this.props.overmind.onUpdate
168+
)
164169
}
165170
}
166171

@@ -206,12 +211,17 @@ export const createConnect = <A extends Overmind<Configuration>>(
206211
} as any)
207212
}
208213

209-
this.tree.track(this.onUpdate)
210-
211-
return createElement(component, {
212-
...this.props,
213-
overmind: this.state.overmind,
214-
} as any)
214+
return createElement(
215+
(...args) =>
216+
this.tree.trackScope(
217+
() => (component as any)(...args),
218+
this.onUpdate
219+
),
220+
{
221+
...this.props,
222+
overmind: this.state.overmind,
223+
} as any
224+
)
215225
}
216226
}
217227

@@ -282,13 +292,17 @@ export const createConnect = <A extends Overmind<Configuration>>(
282292
overmind: this.state.overmind,
283293
} as any)
284294
}
285-
286-
this.tree.track(this.onUpdate)
287-
288-
return createElement(component, {
289-
...this.props,
290-
overmind: this.state.overmind,
291-
} as any)
295+
return createElement(
296+
(...args) =>
297+
this.tree.trackScope(
298+
() => (component as any)(...args),
299+
this.onUpdate
300+
),
301+
{
302+
...this.props,
303+
overmind: this.state.overmind,
304+
} as any
305+
)
292306
}
293307
}
294308

0 commit comments

Comments
 (0)