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

fix(show-hide): set explicit display fallback for SSR #1252

Merged
merged 1 commit into from
May 13, 2020

Conversation

CaerusKaru
Copy link
Member

In the event that a user specifies two breakpoints with conflicting
show/hide, e.g. fxHide.lt-lg and fxShow.md, fxShow will not be
able to re-enable CSS display, since there's no equivalent to
nulling out the styles, which is what we do when handling it
inline in the browser.

This sets the property to initial in SSR stylesheets only. This
should preserve browser behavior where nulling out the styles still
works.

NOTE: if you have other classes that set the display property of
an element, they may get overridden in SSR only. This is
unavoidable, since getComputedStyle is not available to use in SSR.

Fixes #1250

In the event that a user specifies two breakpoints with conflicting
show/hide, e.g. fxHide.lt-lg and fxShow.md, fxShow will not be
able to re-enable CSS `display`, since there's no equivalent to
nulling out the styles, which is what we do when handling it
inline in the browser.

This sets the property to `initial` in SSR stylesheets only. This
should preserve browser behavior where nulling out the styles still
works.

NOTE: if you have other classes that set the `display` property of
an element, they may get overridden in SSR only. This is
unavoidable, since getComputedStyle is not available to use in SSR.

Fixes #1250
@CaerusKaru CaerusKaru added this to the 10.0.0-beta.31 milestone May 13, 2020
@CaerusKaru CaerusKaru merged commit 0c5811d into master May 13, 2020
@CaerusKaru CaerusKaru deleted the adam/ssr-show branch May 13, 2020 19:44
@sjbeatle
Copy link

@CaerusKaru
Hey! Given your note, do you have any suggestions on what to do?

For example:

// Template
<div class="make-me-display-flex" fxHide.xs>Hello World!</div>
// CSS
.make-me-display-flex { display: flex; }

This change now injects and renders the following inline style for all shown breakpoints:

// Rendered HTML
<div class="make-me-display-flex" style="display: initial;">Hello World!</div>

Which kills the CSS display flex :-(

Current workarounds (neither ideal):
A. Wrap the div and apply the directive there <-- preferable of the two

// Template
<div fxHide.xs>
  <div class="make-me-display-flex">Hello World!</div>
</div>

B. If you preempt with your own inline style, flex-layout will recognize and use that <-- double-duty, yuck!

// Template
<div class="make-me-display-flex" style="display: flex;" fxHide.xs>Hello World!</div>

Any advice would be greatly appreciated. Thanks!

@CaerusKaru
Copy link
Member Author

@sjbeatle We've published 9.0.0-beta.31 to revert the change and add this fix.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show/Hide bug beta30 caused by display:initial
3 participants