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

fxLayoutWrap not working with Angular Universal #430

Closed
naveedahmed1 opened this issue Sep 23, 2017 · 26 comments · Fixed by #590
Closed

fxLayoutWrap not working with Angular Universal #430

naveedahmed1 opened this issue Sep 23, 2017 · 26 comments · Fixed by #590
Assignees
Labels
bug P1 Urgent issue that should be resolved before the next re-lease ssr

Comments

@naveedahmed1
Copy link

naveedahmed1 commented Sep 23, 2017

When using fxLayoutWrap with Server Side Rendering, all elements are always shown in one row. With 2.0.0-beta.9 it was working perfectly but its broken in latest nightly update.

@mackelito
Copy link

Could you paste your code as well?

@naveedahmed1
Copy link
Author

naveedahmed1 commented Oct 11, 2017

Please test the below code with Server Side Rendering and observe the initial load, before preboots sync the changes.
It will show all items in one row, and when preboots syncs the changes, its properly formatted. It was working perfectly with last beta.

<div fxLayout fxLayoutWrap class="table-grid touched">
    <div fxFlex.xs="50%" fxFlex="20%">  Item 1          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 1 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 2          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 2 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 3          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 3 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 4          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 4 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 5          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 5 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 6          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 6 Value    </div>
</div>

@CaerusKaru
Copy link
Member

Might be fixed by #466. The latest beta of angular/flex-layout blocked certain methods from being used with Universal, and that PR reverses that change. If/when that PR gets merged, pull the latest nightly build and see if that fixes it.

@CaerusKaru
Copy link
Member

As a side note, the fxLayoutWrap API has been marked as deprecated, so you may want to explore other formatting options for future use.

@naveedahmed1
Copy link
Author

Can you please also share, what are the alternatives to fxLayoutWrap?

@CaerusKaru
Copy link
Member

@naveedahmed1 The deprecation notice is listed here:

/**
* @deprecated
* This functionality is now part of the `fxLayout` API
*
* 'layout-wrap' flexbox styling directive
* Defines wrapping of child elements in layout container
* Optional values: reverse, wrap-reverse, none, nowrap, wrap (default)]
*
*
* @see https://css-tricks.com/almanac/properties/f/flex-wrap/
*/

As shown on the fxLayout section of the Wiki page, you can add a second argument to fxLayout to add a wrap (not adding this argument defaults to no wrap).

So, in your case, you would change fxLayout fxLayoutWrap to fxLayout="row wrap". The documentation is lacking on wrap options, but they are alpha-equivalent to those for flex-wrap CSS:
reverse | wrap-reverse | reverse-wrap | no | none | nowrap | wrap

@naveedahmed1
Copy link
Author

Thank you so much @CaerusKaru , its awesome :)

@CaerusKaru
Copy link
Member

CaerusKaru commented Oct 23, 2017

@naveedahmed1 The fixes from #466 have been merged into the latest nightly build. Does that fix your problem?

@naveedahmed1
Copy link
Author

Yes, its fixed now. Thank you!

@CaerusKaru
Copy link
Member

Great, this issue can be closed.

@naveedahmed1
Copy link
Author

@CaerusKaru I think the latest nightly build has introduced this issue again. Can you please check?

Please also confirm if support for fxLayoutWrap has been removed? I had to update
fxLayout fxLayoutWrap with fxLayout="row wrap".

@naveedahmed1 naveedahmed1 reopened this Jan 18, 2018
@CaerusKaru
Copy link
Member

Please provide a minimal reproduction repo that I can confirm. fxLayoutWrap has been removed in the latest nightly build.

@naveedahmed1
Copy link
Author

naveedahmed1 commented Jan 18, 2018

Can you please try below with SSR enabled and observe the behavior. Before the client side code takes control all blocks are shown in one row when client side code is activated it is displayed correctly.

<div fxLayout="row wrap">
    <div fxFlex.xs="50%" fxFlex="20%">  Item 1          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 1 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 2          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 2 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 3          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 3 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 4          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 4 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 5          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 5 Value    </div>
    <div fxFlex.xs="50%" fxFlex="20%">  Item 6          </div>
    <div fxFlex.xs="50%" fxFlex="30%">  Item 6 Value    </div>
</div>

@CaerusKaru
Copy link
Member

@naveedahmed1 In order to exactly replicate the conditions you're seeing, we need a repo to clone and test. Code snippets are insufficient.

@naveedahmed1
Copy link
Author

@CaerusKaru thank you for your reply. Can you please check it with https://github.com/angular/universal-starter ?

  • Add "@angular/flex-layout": "github:angular/flex-layout-builds", to packages.json
  • Add the flex-layout module toapp.module
  • Add above code to home component.

Run project using below command:
npm run build:ssr && npm run serve:ssr

try refreshing the page few times, and you will notice that before the client side code takes control all divs are shown in one row.

@CaerusKaru CaerusKaru added P1 Urgent issue that should be resolved before the next re-lease and removed needs: demo labels Jan 22, 2018
@CaerusKaru CaerusKaru added this to the v5.0.0-beta.13 milestone Jan 22, 2018
@CaerusKaru CaerusKaru self-assigned this Jan 22, 2018
@CaerusKaru
Copy link
Member

@naveedahmed1 Confirmed the issue, thanks for the detailed steps. Can you also tell me what was the last nightly build that this worked correctly?

@naveedahmed1
Copy link
Author

I think 2.0.0-beta.12-b9745c6

@chriscurnow
Copy link

@CaerusKaru please note the API Documentation here lists fxLayoutWrap under the 'Containers' section with no indication that is now deprecated. I just spent several hours trying to find out why it didn't work 😄

@CaerusKaru
Copy link
Member

@chriscurnow I apologize for the lapse in the documentation. It has indeed been updated and removed, but the Wiki gets updated from source with every release, instead of with every PR (to allow us to avoid cluttering the history and revert/patch if necessary).

The Wiki is planned for a refresh with the next release next Thursday if everything goes as scheduled. The source for the docs is in the docs directory in the repo.

Again, apologies for the confusion.

@naveedahmed1
Copy link
Author

@CaerusKaru thank you for sharing this information. Can you please also confirm if we should expect this issue to be resolved in next release?

@CaerusKaru
Copy link
Member

@naveedahmed1 It's definitely a priority, but the higher priority at the moment is getting a full SSR solution ready. The current goal is for the next release, but depending on other factors it may get bumped to the next release.

The current accepted workaround is to downgrade to the nightly build you indicated (or manually add the necessary CSS)

@CaerusKaru
Copy link
Member

The fix for this, while really annoying to track down, is simple and stems from an issue with the underlying DOM representation Angular uses on the server (aka Domino). The internal method we were using to track styles accounted for this, but since it's internal we could no longer rely on it.

#590 adds another method for overcoming this deficiency in a not-hacky way. Hopefully it will be merged this week, but the next release might be pushed back.

@naveedahmed1
Copy link
Author

Thank you so much @CaerusKaru for the update and sharing the details :)

One more thing, though not directly related to this issue, but since I am uncertain if it worth opening a new issue for this or not so adding it here.

Since the flex-layout adds inline styles for formatting, there are many cases where we see repeated styles throughout the document. For the cases where the app isn't utilizing SSR, it shouldn't have any impact. But for apps that have SSR enabled, it could increase the overall size of the webpage and would require more bandwidth. What if the common styles could be combined as a class and then instead of having inline styles these classes could be used.

@CaerusKaru
Copy link
Member

@naveedahmed1 That's the gist of #567, though combining classes is something I hadn't considered. The solution involves generating one class per element so that we can track the responsive part correctly, I'll have to think about possibly combining classes for common styles.

@naveedahmed1
Copy link
Author

Awesome work @CaerusKaru !

It would be really great if the classes for the common styles could be combined. I just check a page on my site and it had 212 occurrences of inline style -webkit-flex:1 1 0.000000001px;box-sizing:border-box;flex:1 1 0.000000001px; which is roughly 16kb.

Looking forward :)

@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 Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug P1 Urgent issue that should be resolved before the next re-lease ssr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants