Skip to content

Commit a984205

Browse files
committed
fixup! fix(@angular/ssr): destroy platform when request is aborted during rendering
1 parent 322f09f commit a984205

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

‎packages/angular/ssr/src/utils/ng.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ export async function renderAngular(
123123
return destroyPromise;
124124
};
125125

126-
const abortHandler = () => {
127-
void destroy();
128-
};
126+
const abortHandler = () => void destroy();
129127

130128
try {
131129
signal?.addEventListener('abort', abortHandler, { once: true });
@@ -164,8 +162,6 @@ export async function renderAngular(
164162
if (!routerIsProvided) {
165163
hasNavigationError = false;
166164
} else if (lastSuccessfulNavigation?.finalUrl) {
167-
hasNavigationError = false;
168-
169165
const requestPrefix =
170166
envInjector.get(APP_BASE_HREF, null, { optional: true }) ??
171167
getFirstHeaderValue(
@@ -179,6 +175,8 @@ export async function renderAngular(
179175
if (urlToRenderString !== finalUrl) {
180176
redirectTo = [pathname, search, hash].join('');
181177
}
178+
179+
hasNavigationError = false;
182180
}
183181

184182
return {
@@ -207,10 +205,6 @@ export async function renderAngular(
207205
}, 0);
208206
}),
209207
};
210-
} catch (error) {
211-
await destroy();
212-
213-
throw error;
214208
} finally {
215209
if (hasNavigationError || redirectTo) {
216210
void destroy();

‎packages/angular/ssr/test/utils/promise_spec.ts‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,25 @@ describe('promiseWithAbort', () => {
3535
});
3636

3737
it('should reject with an AbortError and handle subsequent promise rejection when signal is already aborted', async () => {
38-
const abortController = new AbortController();
39-
abortController.abort('Already aborted');
38+
const onUnhandledRejection = jasmine.createSpy('unhandledRejection');
39+
process.on('unhandledRejection', onUnhandledRejection);
4040

41-
let reject!: (reason?: unknown) => void;
42-
const underlyingPromise = new Promise<void>((_, r) => {
43-
reject = r;
44-
});
45-
const promise = promiseWithAbort(underlyingPromise, abortController.signal, 'Test operation');
41+
try {
42+
const abortController = new AbortController();
43+
abortController.abort('Already aborted');
44+
45+
const { promise: underlyingPromise, reject } = Promise.withResolvers<void>();
46+
const promise = promiseWithAbort(underlyingPromise, abortController.signal, 'Test operation');
47+
48+
await expectAsync(promise).toBeRejectedWithError(DOMException, /Test operation was aborted/);
4649

47-
await expectAsync(promise).toBeRejectedWithError(DOMException, /Test operation was aborted/);
50+
// Rejecting the underlying promise after abort should not cause an unhandled rejection
51+
reject(new Error('Late failure'));
52+
await setTimeout(0);
4853

49-
// Rejecting the underlying promise after abort should not cause an unhandled rejection
50-
reject(new Error('Late failure'));
54+
expect(onUnhandledRejection).not.toHaveBeenCalled();
55+
} finally {
56+
process.off('unhandledRejection', onUnhandledRejection);
57+
}
5158
});
5259
});

‎tsconfig-build-esm.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
"extends": "./tsconfig.json",
88
"compilerOptions": {
99
"module": "esnext",
10-
"target": "es2022",
11-
"lib": ["es2022"],
1210
"moduleResolution": "bundler",
1311
// don't auto-discover @types/node, it results in a ///<reference in the .d.ts output
1412
"types": [],

0 commit comments

Comments
 (0)