Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using flex-layout with Angular Universal #187

Closed
BirdInTheCity opened this issue Feb 16, 2017 · 30 comments · Fixed by #353
Closed

Using flex-layout with Angular Universal #187

BirdInTheCity opened this issue Feb 16, 2017 · 30 comments · Fixed by #353
Assignees
Labels
bug build in-progress P1 Urgent issue that should be resolved before the next re-lease
Milestone

Comments

@BirdInTheCity
Copy link

From my limited knowledge of Node, I gather that anything referencing Document or Window will throw a server-side error.

That said, I'd like to incorporate flex-layout into my Angular Universal app. Is that possible? My initial attempt (simply following the readme) throws the following error:

ReferenceError: document is not defined

@ThomasBurleson
Copy link
Contributor

Currently we do NOT support flex-layout with Angular Universal.

@ThomasBurleson ThomasBurleson added this to the v2.0.0-rc.2 milestone Feb 20, 2017
@ThomasBurleson ThomasBurleson self-assigned this Feb 20, 2017
@ThomasBurleson
Copy link
Contributor

ThomasBurleson commented Feb 20, 2017

@alxhub - any thoughts how we should change our use of:

@Josmorsot
Copy link

@BirdInTheCity I had the same problem so I decided to use Layouts from MDL https://getmdl.io/.
Also I had this problem with Material2 buttons and other components but this can be solved using 'isNode' for check if request are being sent by node or browser

@ThomasBurleson
Copy link
Contributor

ThomasBurleson commented Feb 24, 2017

@BirdInTheCity - can you provide a simple project (zip) that demonstrates this ? We will investigate.

Currently I am unclear how Angular Universal handles issues with code references to document ?

I think you are encountering code in match-media.ts::prepareQueryCSS(); and that function is patch code for some browser bugs.

@nicky-lenaers
Copy link

Is this going to make it into the rc.2 release?

@ThomasBurleson
Copy link
Contributor

@nicky-lenaers - no. There are unknowns that still need to be resolved? (see above questions).

@ThomasBurleson ThomasBurleson modified the milestones: v2.0.0-rc.2, v2.0.0-rc.3 Mar 9, 2017
@paullryan
Copy link

When working with this you should focus on angular4 support instead of angular/universal given that 4 has universal built into @angular/platform-browser and @angular/platform-server.

@ThomasBurleson when working with document for universal you want to manipulate the renderer instead of document for rendering updates like your doing on https://github.com/angular/flex-layout/blob/master/src/lib/flexbox/api/base.ts#L138. If you have direct need for getDOM() you'll want to check for getDom() first and if it exists then isBrowser is true else your in node and probably won't be able to directly make that call.

Side note; a quick search through the current master is showing that you don't have any glaring issues with universal support so it should be pretty close to ready as is.

@nicky-lenaers
Copy link

@paullryan nice, I really hope it'll be available soon!

@alxhub
Copy link
Member

alxhub commented Apr 11, 2017

Both getDOM() and the renderer will work fine on @angular/platform-server - it's direct DOM access that needs to be avoided.

@nicky-lenaers
Copy link

I see errors on the matchMedia function server-side. Any thoughts on how to fix that?

@ThomasBurleson
Copy link
Contributor

ThomasBurleson commented Apr 24, 2017

@nicky-lenaers - The current issue is that window.matchMedia() needs to actually run on the client-side; and the server side should be a mock that defalts to "all" matches:

On the client-side, rendering needs to force a re-register of the media queries to trigger the appropriate match announcements.

@nicky-lenaers
Copy link

@ThomasBurleson great to here there is a solution. Is this already in development?

@DmitryEfimenko
Copy link

With the yesterday's 2.0.0-beta-4 release of angular/material2, one of the highlights of which was improved Angular Universal support via PR 4251, I'm surprised angular/flex-layout didn't have similar changes. I'd think they go hand in hand.

@ThomasBurleson
Copy link
Contributor

Once PR #342 has been merged we will submit a revised PR for Angular Universal support.

@glebmachine
Copy link

@ThomasBurleson Merged!
#342 (comment)

@ThomasBurleson
Copy link
Contributor

@glebmachine - We appreciate your passion, thank you. We are working on this issue now! ;-)

ThomasBurleson added a commit that referenced this issue Jul 29, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 29, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 29, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 30, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 30, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 30, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 30, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
ThomasBurleson added a commit that referenced this issue Jul 30, 2017
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187. Closes #346.
@ThomasBurleson
Copy link
Contributor

FYI - The team is hoping to close this issue within the next 2-3 workdays.

@glebmachine
Copy link

glebmachine commented Jul 30, 2017 via email

ThomasBurleson added a commit that referenced this issue Aug 2, 2017
Use getDom() for platform-server/universal fixes
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187, #354. Closes #346.
ThomasBurleson added a commit that referenced this issue Aug 2, 2017
Use getDom() for platform-server/universal fixes
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187, #354. Closes #346.
ThomasBurleson added a commit that referenced this issue Aug 3, 2017
Use getDom() for platform-server/universal fixes
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187, #354. Closes #346.
ThomasBurleson added a commit that referenced this issue Aug 4, 2017
Use getDom() for platform-server/universal fixes
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187, #354. Closes #346.
tinayuangao pushed a commit that referenced this issue Aug 4, 2017
Use getDom() for platform-server/universal fixes
Now gets document object from platform-browser by DI instead of global.

> Thx to @ardatan for PR #346.

Fixes #187, #354. Closes #346.
@fdambrosio
Copy link

I'm using beta.9 and I have the error
ReferenceError: document is not defined

@glebmachine
Copy link

Guys, i'm struggling about:
ReferenceError: getComputedStyle is not defined
In lookupStyle function

Does anybody have monkey patch about that?

@glebmachine
Copy link

glebmachine commented Apr 27, 2018

Done, i'm patch it with:

global['getComputedStyle'] = () => {
  return {
    getPropertyValue() { return '' },
  };
};

That is filthy, but it works)

@CaerusKaru
Copy link
Member

@glebmachine Flex Layout fully supports Angular Universal as of v5.0.0-beta.13. Please ensure you have the correct version installed and follow the SSR guide here.

@glebmachine
Copy link

Thank you! I following this guide, but suddenly got error into ShowHideDirective : (
I hope it was due some external issues

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

Successfully merging a pull request may close this issue.