-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Angular SSR not updating dynamic meta tags and content received from API #53711
Comments
@leandrotassi unfortunately we can't perform any investigation with the information that you've provided and we'd need a repro to see what's happening and whether there is anything on the framework side that should be fixed. You may not be able to reproduce the problem via Stackblitz (as you've mentioned), but you may try creating a new Angular app (via |
@AndrewKushnir: |
@hieutranagi47: did you find any solution for this? |
@kodetratech I don't know the root cause of the issue in this case, Angular renders the home page first, then switch to the post detail page although I access the post detail page. I guess that it's Angular issue, so I don't know what the best solution for this should be. |
@hieutranagi47 thanks for creating a test application! I've tried running it locally and I can see updated meta tags in the page source once the page is SSR'ed and HTML is delivered to a browser. Could you please provide a bit more info on how to reproduce the problem locally? |
@kodetratech Thank you so much for your time. |
@hieutranagi47 I am also facing the same problem. one thing I can tell something has happened after Angular version 17.0.3. I have an application that uses Angular 17.0.3, when I share the URL of my application to social media like Twitter or Facebook, it renders the dynamic meta tags correctly. But my other application which is running on angular 17.2.1, URLs are not working on social media sites. it renders the default value of the meta tags. |
@hieutranagi47 I am also facing the same problem. project is working locally but in production it is not working. meta tags are not updating and not able to working in social media (not displaying correct meta tags and images, showing only default tags) |
If you notice, you will see that Angular renders the root route ("/"), before render the actual route. |
I have notice that when updating the meta tags after receiving response from the api call it is not updating but without API call it is working. Any solution for this |
I am also looking for a solution, please share updates whenever possible |
@roosikem @monacodelisa @yogeshbansal : While we are waiting for the fix from the Angular core team, we could try the pre-render feature of Angular CLI. I tested it and it works. |
@roosikem cool thank you, I am actively trying different options, I will give it a try |
@hieutranagi47 @roosikem @AndrewKushnir Just wondering...Does anyone know the cause of this issue? |
After careful analysis of the situation, I identified that when sharing a website on my own platform, the meta tag information was not being displayed correctly. Instead, default information from the index.html file was being loaded. This issue arises due to the behavior of certain social media crawlers, which do not wait for the website to be fully rendered before collecting information. For example, Twitter is more tolerant in this regard, while Facebook or LinkedIn are not. To address this issue, I adopted a series of strategic measures:
With these measures, I was able to completely resolve the sharing problem. I hope these tips can help those facing the same issue. |
@leandrotassi thanks for the response...I am also exactly doing the same. But it's not working for me. If I share the URL on Twitter or facebook, it's still picking the default meta tags. |
Can anyone provide a minimal repo of this issue? |
@JeanMeche We don't face the issue in the local environment. Please deploy it on a server (Production development) then you can see the issue. I have deployed it on Vercel here: https://ssr-api-ivory.vercel.app/post/3 |
I did build the app and run the dist locally without being able to reproduce your issue. |
@hieutranagi47 Your issue is that you're not using SSR but prerendering (SSG). (
You app isn't prerendering each post entry which explains why the meta still contains the placeholder. |
@JeanMeche thank you for your comments, I wanted to ask something that I am not sure about - as far as I understand, right now both Netlify and Vercel only support SSG and do not fully support SSR - since for SSR you need to be running a Node server on a Node hosting environment like Render, Cyclic, AWS Lambda and so on ? Or can SSR be achieved fully on Netlify / Vercel ? |
@monacodelisa You can deploy on Vercel serverless and Netlify Edge. |
@JeanMeche cool, thank you |
@JeanMeche: Can you give me more info about this issue. |
Yes this is what is hapeing in your case, CSR is what currently renders your posts . You need a node server to run SSR. |
Thank you so much for the great support! |
@yogeshbansal Could it be that the server that hosts your website is not influencing sharing behavior? Did you make sure that the builder is "@angular-devkit/build-angular:application"? Because it was these sets of measures, which I mentioned earlier, that made sharing work. |
@leandrotassi: I have these 2 applications both are running on the same setup and server. One is working and other one is not. |
This is how I solved this. I created a ItemResolver and added it into my routes `import { Injectable } from '@angular/core'; @Injectable({
}` This is route configuration
I did this in onNit of ViewVideoPageComponent `imageUrl: string = '';
}
Example of this is this one |
@codewithbisky This is how your link is looking on twitter when you try to post it. |
Twitter cached that image when I was testing it. You can try other urls on
my platform.
…On Sat, 30 Mar 2024, 18:18 Yogesh Bansal, ***@***.***> wrote:
@codewithbisky <https://github.com/codewithbisky> This is how your link
is looking on twitter when you try to post it.
see the attached image
Screenshot.2024-03-30.at.10.16.00.AM.png (view on web)
<https://github.com/angular/angular/assets/4295712/e8deb56e-815c-4757-8ec2-89df066686bf>
—
Reply to this email directly, view it on GitHub
<#53711 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCC6WIWBSRFCDQBVTSDLALDY23XU3AVCNFSM6AAAAABBEZVDFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRYGMYTONZUGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This is an example.
On Sat, 30 Mar 2024, 18:25 Marshall Chabaga, ***@***.***>
wrote:
… Twitter cached that image when I was testing it. You can try other urls on
my platform.
On Sat, 30 Mar 2024, 18:18 Yogesh Bansal, ***@***.***>
wrote:
> @codewithbisky <https://github.com/codewithbisky> This is how your link
> is looking on twitter when you try to post it.
> see the attached image
> Screenshot.2024-03-30.at.10.16.00.AM.png (view on web)
> <https://github.com/angular/angular/assets/4295712/e8deb56e-815c-4757-8ec2-89df066686bf>
>
> —
> Reply to this email directly, view it on GitHub
> <#53711 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BCC6WIWBSRFCDQBVTSDLALDY23XU3AVCNFSM6AAAAABBEZVDFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRYGMYTONZUGM>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
@codewithbisky works with Angular 17? |
Yes, it works with angular 17
…On Wed, 3 Apr 2024, 01:37 Sebastián Rojas Ricaurte, < ***@***.***> wrote:
@codewithbisky <https://github.com/codewithbisky> works with Angular 17?
—
Reply to this email directly, view it on GitHub
<#53711 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCC6WIWBIFKUVIQOS2DI3QTY3M6NNAVCNFSM6AAAAABBEZVDFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZTGI4DINJSHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Alerady using it :) |
@codewithbisky I noticed that the content on the page you've shared wasn't loaded from API. I've tried your solution but it doesn't work either, I'm on Angular 17.3.3 |
@liamong0422 if you need to load meta-data from an API, you should use resolvers:
|
I'm already using the resolver but I am still experiencing the same issue. The website will load the home page first, then to the details page. But for pages that doesn't load API, it will go straight to the page and the metatags were successfully loaded in the page source. |
Yes, is not working :( |
@JeanMeche Could you Please reopen this issue...we still don't have the solution for this. My angular app is running on AWS with nginx and SSR. Still meta tags are not getting updated dynamically, it loads the default tags |
Which @angular/* package(s) are the source of the bug?
platform-server
Is this a regression?
Yes
Description
I'm working on an Angular SSR application and I'm facing a problem when updating Open Graph meta tags after receiving content from the API, as in another component that updates directly (without consuming the API) there is no problem.
Although when viewing elements in the page source code, all meta tags are updated. The problem is that when sharing, they don't show the updated meta tags.
After I updated to Angular 17 it stopped working, but I'm not sure, because it was in some version that it stopped working and I had made several Angular updates.
Please provide a link to a minimal reproduction of the bug
Unfortunately, I have no way of reproducing the error for you to analyze, as the error only occurs in production and cannot be reproduced in stackblitz.
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: