Skip to content

Commit ff0c1a2

Browse files
Merge branch 'fix-ngonchanges-not-working-for-themed-components_contribute-7.4' into fix-ngonchanges-not-working-for-themed-components_contribute-7.6
2 parents 404ccd9 + a7bef6f commit ff0c1a2

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/app/shared/theme-support/theme.service.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const themeStateSelector = createFeatureSelector<ThemeState>('theme');
2929

3030
export const currentThemeSelector = createSelector(
3131
themeStateSelector,
32-
(state: ThemeState): string => hasValue(state) ? state.currentTheme : undefined
32+
(state: ThemeState): string => hasValue(state) ? state.currentTheme : BASE_THEME_NAME,
3333
);
3434

3535
@Injectable({
@@ -240,14 +240,7 @@ export class ThemeService {
240240
if (hasValue(parentThemeName)) {
241241
// inherit the head tags of the parent theme
242242
return this.createHeadTags(parentThemeName);
243-
}
244-
const defaultThemeConfig = getDefaultThemeConfig();
245-
const defaultThemeName = defaultThemeConfig.name;
246-
if (
247-
hasNoValue(defaultThemeName) ||
248-
themeName === defaultThemeName ||
249-
themeName === BASE_THEME_NAME
250-
) {
243+
} else {
251244
// last resort, use fallback favicon.ico
252245
return [
253246
this.createHeadTag({
@@ -260,9 +253,6 @@ export class ThemeService {
260253
})
261254
];
262255
}
263-
264-
// inherit the head tags of the default theme
265-
return this.createHeadTags(defaultThemeConfig.name);
266256
}
267257

268258
return headTagConfigs.map(this.createHeadTag.bind(this));
@@ -425,9 +415,10 @@ export class ThemeService {
425415
* @private
426416
*/
427417
private getActionForMatch(newTheme: Theme, currentThemeName: string): SetThemeAction | NoOpAction {
428-
if (hasValue(newTheme) && newTheme.config.name !== currentThemeName) {
418+
const newThemeName: string = newTheme?.config.name ?? BASE_THEME_NAME;
419+
if (newThemeName !== currentThemeName) {
429420
// If we have a match, and it isn't already the active theme, set it as the new theme
430-
return new SetThemeAction(newTheme.config.name);
421+
return new SetThemeAction(newThemeName);
431422
} else {
432423
// Otherwise, do nothing
433424
return new NoOpAction();

src/app/shared/theme-support/themed.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
7575
}
7676

7777
ngOnInit(): void {
78-
this.destroyComponentInstance();
7978
this.initComponentInstance();
8079
}
8180

@@ -96,8 +95,6 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
9695
}
9796

9897
if (hasNoValue(this.lazyLoadObs)) {
99-
this.destroyComponentInstance();
100-
10198
this.lazyLoadObs = combineLatest([
10299
observableOf(changes),
103100
this.resolveThemedComponent(this.themeService.getThemeName()).pipe(
@@ -120,6 +117,7 @@ export abstract class ThemedComponent<T> implements OnInit, OnDestroy, OnChanges
120117
}
121118

122119
this.lazyLoadSub = this.lazyLoadObs.subscribe(([simpleChanges, constructor]: [SimpleChanges, GenericConstructor<T>]) => {
120+
this.destroyComponentInstance();
123121
const factory = this.resolver.resolveComponentFactory(constructor);
124122
this.compRef = this.vcr.createComponent(factory, undefined, undefined, [this.themedElementContent.nativeElement.childNodes]);
125123
if (hasValue(simpleChanges)) {

src/config/config.util.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { environment } from '../environments/environment';
55
import { hasNoValue } from '../app/shared/empty.util';
66

77
import { AppConfig } from './app-config.interface';
8-
import { ThemeConfig } from './theme.model';
8+
import { ThemeConfig, NamedThemeConfig } from './theme.model';
9+
import { BASE_THEME_NAME } from '../app/shared/theme-support/theme.constants';
910

1011
/**
1112
* Extend Angular environment with app config.
@@ -44,7 +45,9 @@ const getDefaultThemeConfig = (): ThemeConfig => {
4445
hasNoValue(themeConfig.regex) &&
4546
hasNoValue(themeConfig.handle) &&
4647
hasNoValue(themeConfig.uuid)
47-
);
48+
) ?? {
49+
name: BASE_THEME_NAME,
50+
} as NamedThemeConfig;
4851
};
4952

5053
export {

0 commit comments

Comments
 (0)