Skip to content

Commit d78248c

Browse files
committed
fix(theming): fix async theme injection context
1 parent bd46663 commit d78248c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/theming/src/provide.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
2+
DestroyRef,
23
EnvironmentProviders,
34
inject,
45
Injector,
56
provideAppInitializer,
7+
runInInjectionContext,
68
} from '@angular/core';
79
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
810
import { filter, firstValueFrom, map, shareReplay, startWith } from 'rxjs';
@@ -55,10 +57,11 @@ export function provideTheme(
5557
): EnvironmentProviders {
5658
return provideAppInitializer(async () => {
5759
const injector = inject(Injector);
60+
const destroyRef = inject(DestroyRef);
5861
const registry = inject(ThemeTokenRegistry);
5962
const transferred = registry.transfer();
6063
const build$ = buildTheme(injector, await theme).pipe(
61-
takeUntilDestroyed(),
64+
takeUntilDestroyed(destroyRef),
6265
map((tokens) => {
6366
registry.setAll(tokens);
6467
return true;
@@ -67,7 +70,9 @@ export function provideTheme(
6770
filter(Boolean),
6871
shareReplay(1),
6972
);
70-
build$.subscribe();
73+
runInInjectionContext(injector, () => {
74+
build$.subscribe();
75+
});
7176
return firstValueFrom(build$);
7277
});
7378
}

0 commit comments

Comments
 (0)