Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 0c5811d

Browse files
authored
fix(show-hide): set explicit display fallback for SSR (#1252)
1 parent b028210 commit 0c5811d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/lib/extended/show-hide/show-hide.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ import {takeUntil} from 'rxjs/operators';
3030

3131
export interface ShowHideParent {
3232
display: string;
33+
isServer: boolean;
3334
}
3435

3536
@Injectable({providedIn: 'root'})
3637
export class ShowHideStyleBuilder extends StyleBuilder {
3738
buildStyles(show: string, parent: ShowHideParent) {
3839
const shouldShow = show === 'true';
39-
return {'display': shouldShow ? parent.display : 'none'};
40+
return {'display': shouldShow ? parent.display || (parent.isServer ? 'initial' : '') : 'none'};
4041
}
4142
}
4243

4344
@Directive()
4445
export class ShowHideDirective extends BaseDirective2 implements AfterViewInit, OnChanges {
4546
protected DIRECTIVE_KEY = 'show-hide';
4647

47-
/** Original dom Elements CSS display style */
48+
/** Original DOM Element CSS display style */
4849
protected display: string = '';
4950
protected hasLayout = false;
5051
protected hasFlexChild = false;
@@ -146,8 +147,9 @@ export class ShowHideDirective extends BaseDirective2 implements AfterViewInit,
146147
if (value === '') {
147148
return;
148149
}
149-
this.addStyles(value ? 'true' : 'false', {display: this.display});
150-
if (isPlatformServer(this.platformId) && this.serverModuleLoaded) {
150+
const isServer = isPlatformServer(this.platformId);
151+
this.addStyles(value ? 'true' : 'false', {display: this.display, isServer});
152+
if (isServer && this.serverModuleLoaded) {
151153
this.nativeElement.style.setProperty('display', '');
152154
}
153155
this.marshal.triggerUpdate(this.parentElement!, 'layout-gap');

src/lib/extended/show-hide/show.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ describe('show directive', () => {
299299
'display': 'inline'
300300
}, styler);
301301
} else {
302-
expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({
303-
'display': '*'
302+
expectEl(queryFor(fixture, elSelector)[0]).toHaveStyle({
303+
'display': 'initial'
304304
}, styler);
305305
}
306306

@@ -318,8 +318,8 @@ describe('show directive', () => {
318318
'display': 'inline'
319319
}, styler);
320320
} else {
321-
expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({
322-
'display': '*'
321+
expectEl(queryFor(fixture, elSelector)[0]).toHaveStyle({
322+
'display': 'initial'
323323
}, styler);
324324
}
325325
});

0 commit comments

Comments
 (0)