From 4b9162752904e134206f14fbf988bcd354b7e3df Mon Sep 17 00:00:00 2001 From: Ben Grynhaus Date: Sat, 26 Jan 2019 20:26:48 +0200 Subject: [PATCH 1/2] fix template context assumed to always exist --- libs/core/src/lib/renderer/react-template.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/core/src/lib/renderer/react-template.ts b/libs/core/src/lib/renderer/react-template.ts index c3396218..58aa0ec8 100644 --- a/libs/core/src/lib/renderer/react-template.ts +++ b/libs/core/src/lib/renderer/react-template.ts @@ -62,7 +62,9 @@ export class ReactTemplate extends React.Compone componentDidUpdate() { // Context has changes, trigger change detection after pushing the new context in - Object.assign(this._embeddedViewRef.context, this.props.context); + if (this.props.context != null && this._embeddedViewRef.context != null) { + Object.assign(this._embeddedViewRef.context, this.props.context); + } this._embeddedViewRef.detectChanges(); } From 9210187960692fa56f55900f9edf5ce74065ff0a Mon Sep 17 00:00:00 2001 From: Ben Grynhaus Date: Sat, 26 Jan 2019 20:27:31 +0200 Subject: [PATCH 2/2] always get the leading and trailing values, to ensure that we stay up-to-date. See https://github.com/Microsoft/angular-react/issues/79#issuecomment-457853778 for more details --- libs/core/src/lib/renderer/react-template.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/core/src/lib/renderer/react-template.ts b/libs/core/src/lib/renderer/react-template.ts index 58aa0ec8..afd82902 100644 --- a/libs/core/src/lib/renderer/react-template.ts +++ b/libs/core/src/lib/renderer/react-template.ts @@ -88,9 +88,11 @@ export class ReactTemplate extends React.Compone // Throttling the detect changes to an empirically selected value so we don't overload too much work. // TODO: This needs some better solution to listen to changes to the binding sources of the template. - this._ngZoneSubscription = ngZone.onStable.pipe(throttleTime(TEMPLATE_DETECT_CHANGES_THROTTLE_MS)).subscribe(() => { - this._embeddedViewRef.detectChanges(); - }); + this._ngZoneSubscription = ngZone.onStable + .pipe(throttleTime(TEMPLATE_DETECT_CHANGES_THROTTLE_MS, undefined, { leading: true, trailing: true })) + .subscribe(() => { + this._embeddedViewRef.detectChanges(); + }); } componentWillUnmount() {