File tree
Expand file treeCollapse file tree2 files changed
+10
-1
lines changed Expand file treeCollapse file tree2 files changed
+10
-1
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -145,11 +145,11 @@ export function withEventReplay(): Provider[] {
|
145 | 145 |
|
146 | 146 | appsWithEventReplay.add(appRef);
|
147 | 147 |
|
| 148 | +const appId = injector.get(APP_ID); |
148 | 149 | appRef.onDestroy(() => {
|
149 | 150 | appsWithEventReplay.delete(appRef);
|
150 | 151 | // Ensure that we're always safe calling this in the browser.
|
151 | 152 | if (typeof ngServerMode !== 'undefined' && !ngServerMode) {
|
152 |
| -const appId = injector.get(APP_ID); |
153 | 153 | // `_ejsa` should be deleted when the app is destroyed, ensuring that
|
154 | 154 | // no elements are still captured in the global list and are not prevented
|
155 | 155 | // from being garbage collected.
|
|
Original file line number | Diff line number | Diff line change |
---|
@@ -207,7 +207,16 @@ describe('event replay', () => {
|
207 | 207 | appRef.tick();
|
208 | 208 | const appId = appRef.injector.get(APP_ID);
|
209 | 209 |
|
| 210 | +// Important: This is done intentionally because `ApplicationRef` registers |
| 211 | +// `onDestroy` callbacks, and we want to ensure that they execute successfully |
| 212 | +// without resulting in any errors. This is necessary because the bodies of |
| 213 | +// these `onDestroy` callbacks use the `ngServerMode` variable. |
| 214 | +// Prior to setting this flag, the unit test was throwing a "destroyed injector" |
| 215 | +// error — but we weren't capturing it because we hadn't explicitly set the flag to false. |
| 216 | +globalThis['ngServerMode'] = false; |
210 | 217 | appRef.destroy();
|
| 218 | +globalThis['ngServerMode'] = undefined; |
| 219 | + |
211 | 220 | // This ensure that `_ejsas` for the current application is cleaned up
|
212 | 221 | // once the application is destroyed.
|
213 | 222 | expect(window._ejsas![appId]).toBeUndefined();
|
|
You can’t perform that action at this time.
0 commit comments