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

Support for server side pre-rendering #82

Closed
jmezach opened this issue Oct 2, 2016 · 7 comments
Closed

Support for server side pre-rendering #82

jmezach opened this issue Oct 2, 2016 · 7 comments

Comments

@jmezach
Copy link
Contributor

jmezach commented Oct 2, 2016

I've been working on an Angular 2 app with an ASP.NET Core backend that uses server side pre-rendering. Unfortunately I found out that using these pipes breaks the server side rendering.

This mostly seems to be because they use window.setTimeout and window.clearTimeout, but window isn't available during the server side rendering for obvious reasons. Is there something we can do here to make this play nice with server side pre-rendering? Perhaps checking if window is defined would be enough?

@urish
Copy link
Owner

urish commented Oct 2, 2016

This makes sense. Can you please send a PR for that?

Also, please see #74

@jmezach
Copy link
Contributor Author

jmezach commented Oct 3, 2016

I started working on this, but I'm having a hard time trying it out. I've tried to npm link it, but then the server side pre-rendering fails entirely with the same error message that is mentioned in #68. Any thoughts on that?

@urish
Copy link
Owner

urish commented Oct 3, 2016

How did you import the module?

Please see my last comment on #81

@jmezach
Copy link
Contributor Author

jmezach commented Oct 4, 2016

I've tried both:

import { MomentModule } from 'angular2-moment/module';

and:

import { MomentModule } from 'angular2-moment';

But I'm getting the same error in both cases?

@urish
Copy link
Owner

urish commented Oct 4, 2016

Can you please check with the latest beta, 1.0.0-beta.3?

@jmezach
Copy link
Contributor Author

jmezach commented Oct 4, 2016

I merged my forks master with your master and then tried to npm link again, but I'm still getting the same error message.

I noticed that both the TimeAgoPipe and CalendarPipe now use ngZone.runOutsideAngular(), but it looks like that is still being executed during server side pre-rendering so it doesn't fix this issue. I guess we'll have to check for the existence of window explicitly. Want to try that out locally first though.

@jmezach
Copy link
Contributor Author

jmezach commented Oct 4, 2016

I ended up just modifying the copy of this module inside the node_modules folder in order to verify if it works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants