Skip to content

Commit 83f6b3a

Browse files
authored
Merge pull request #81 from Microsoft/core/template-ref_update-issue
[Core] Workaround for TemplateRef update issues
2 parents 24606fe + 9210187 commit 83f6b3a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libs/core/src/lib/renderer/react-template.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export class ReactTemplate<TContext extends object | void> extends React.Compone
6262

6363
componentDidUpdate() {
6464
// Context has changes, trigger change detection after pushing the new context in
65-
Object.assign(this._embeddedViewRef.context, this.props.context);
65+
if (this.props.context != null && this._embeddedViewRef.context != null) {
66+
Object.assign(this._embeddedViewRef.context, this.props.context);
67+
}
6668
this._embeddedViewRef.detectChanges();
6769
}
6870

@@ -86,9 +88,11 @@ export class ReactTemplate<TContext extends object | void> extends React.Compone
8688

8789
// Throttling the detect changes to an empirically selected value so we don't overload too much work.
8890
// TODO: This needs some better solution to listen to changes to the binding sources of the template.
89-
this._ngZoneSubscription = ngZone.onStable.pipe(throttleTime(TEMPLATE_DETECT_CHANGES_THROTTLE_MS)).subscribe(() => {
90-
this._embeddedViewRef.detectChanges();
91-
});
91+
this._ngZoneSubscription = ngZone.onStable
92+
.pipe(throttleTime(TEMPLATE_DETECT_CHANGES_THROTTLE_MS, undefined, { leading: true, trailing: true }))
93+
.subscribe(() => {
94+
this._embeddedViewRef.detectChanges();
95+
});
9296
}
9397

9498
componentWillUnmount() {

0 commit comments

Comments
 (0)