SEO / SSR: Ensure data is retrieved before rendering the view #3034
Replies: 4 comments 1 reply
-
AngularFire should do most of this for you with our zone wrappers, which create a zone macrotask that keeps the page from rendering until the first emission from our observables or callbacks. If you're doing this manually yourself, you'll want to read up on how to keep Zone.js from "stablizing". |
Beta Was this translation helpful? Give feedback.
-
@jamesdaniels I currently am not attempting to detect Zone changes manually. I did run a few tests with ngRunOutsideAngular(), but it didn't seem to change much. I am using Angular Material, which seems to work fine with Universal, but maybe that is causing the page to render (detect a change) before data is received? Below is an example component and html template. This is just one way I've tried to collect and render data. I've tried to remove the "page not found" and "loading" containers from the template, I've tried removing the pipes and subscribe from the component ts file. Not sure what the exact issue is. I will include a second example where I try to use tag.component.ts
tag.component.html
Load List Page
|
Beta Was this translation helpful? Give feedback.
-
I created a blank project with only Angular Fire and Universal. I ran into the same issue with data not rendering before the template. That was while using |
Beta Was this translation helpful? Give feedback.
-
I suppose making a resolver to get the data before the component loads is the best way to make an SEO friendly SSR page. 🙃 I made the resolver
|
Beta Was this translation helpful? Give feedback.
-
I am struggling to get data to load before first render on the server side. I would like the data to be retrieved and in place before the initial SERVER-SIDE page is created -- either by direct link or page refresh. Currently, the server page will render the main template without data, then the CLIENT-SIDE will take over and load the data. I understand a lot of tasks are asyncronous and a big reason to use Angular is for fast second action responses; however, metadata and page content need to be rendered server-side so that web crawlers can properly view the page content.
I have tried
resolvers
,ngZone
, re-writing the way data is retrieved. It all comes back to the same issue: the Observable never needs to "complete" in order for the server side page to be created. Really the only thing that does make it work is using a 1000-4000mssetTimeout()
function (depending on content), but that obviously is a bad idea.Any suggestions or ideas are appreciated. In the meantime, I will try to find a solution and share what I come up with. I have already read about the Universal gotchas in-regards to http / api requests. I am also aware that Angular 7 uses zone wrappers.
Current setup:
Angular 12.2.1
Angular/Fire 7.1.1
Firebase 9.1.3
Firebase-tools 9.21.0
Node 14@latest + Npm 6@latest
Beta Was this translation helpful? Give feedback.
All reactions