Skip to content

Commit f8c0744

Browse files
committed
refactor(@angular/ssr): handle promise-like results from loadChildrenHelper
The `loadChildrenHelper` function can return either an Observable or a Promise. This change ensures that we correctly handle both cases by checking if the return value is "thenable" before calling `.toPromise()`. This provides compatibility with different versions of Angular framework that have different return types for `loadChildren`. This is a temporary workaround and should be removed when Angular framework v21.0.0-next.7 is released.
1 parent ea0da70 commit f8c0744

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/angular/ssr/src/routes/ng-routes.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ async function* handleRoute(options: {
205205
)
206206
: parentInjector;
207207

208-
const loadedChildRoutes = await loadChildrenHelper(
209-
route,
210-
compiler,
211-
routeInjector,
212-
).toPromise();
208+
// TODO(alanagius): replace all the below when FW 21.0.0-next.7 is out.
209+
const loadChildrenHelperResult = loadChildrenHelper(route, compiler, routeInjector);
210+
const loadedChildRoutes = await ('then' in loadChildrenHelperResult
211+
? (loadChildrenHelperResult as unknown as ReturnType<
212+
typeof loadChildrenHelperResult.toPromise
213+
>)
214+
: loadChildrenHelperResult.toPromise());
213215

214216
if (loadedChildRoutes) {
215217
const { routes: childRoutes, injector = routeInjector } = loadedChildRoutes;

0 commit comments

Comments
 (0)