DEV Community

WhatsApp link preview is weird

Lucis on December 04, 2019

So, my day as a web developer today was described by this image: As it may not be so easy to understand, I was testing the link preview feature ...
Collapse
 
vitorolivg profile image
Vitor Gomes

Hey Luciano, thanks for sharing. In our project we couldn't fix the problem only with Helmet. What I did was:

gatsby-ssr.js

export const onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
  const headComponents = getHeadComponents();
  headComponents.sort((a, b) => {
    if (a.type === 'meta') {
      return -1;
    } else if (b.type === 'meta') {
      return 1;
    }
    return 0;
  });
  replaceHeadComponents(headComponents);
};
Enter fullscreen mode Exit fullscreen mode

Sorting the Head components with the meta data first.

Cheers

Collapse
 
lucis profile image
Lucis

Very nice, Vitor!

I'll add it to the post as another solution, right?

;)

Collapse
 
eltel profile image
Terry Mitchell

Hi Lucis!!

I have the same problem, I tried Vitor's function in gatsby-ssr.js and it didn't work, I'm not importing any external CSS. It's scraping fine in the Facebook debugger and in devtools > elements all meta tags are above the CSS (after I swapped the order of imports in the Layout component) - do you have any other tips??
It's for the landing page of an English language self-study platform for Brazilians and I'm losing way too much time to get this to share correctly on WhatsApp - any advice appreciated - here's the landing page (not promoted/officially live yet - just for testing purposes):
portugles.com/

Many thanks in advance :)

Collapse
 
eltel profile image
Terry Mitchell

Found the solution here for anyone who needs:

stackoverflow.com/questions/251009...

I'd never heard of this!! Really helped :)

Collapse
 
leobetosouza profile image
Leonardo Alberto Souza

I have the same problem but reversed: My meta tags are working nicely with WhatsApp, but Telegram is ignoring it... I've tried the @previews bot and: Unfortunately, we cannot preview this URL.

Have you done something special for Telegram to display the metadata?

Collapse
 
llgokull profile image
Mandeep choutapelly

I thank you from the bottom of my heart. Even after a day of debugging i couldn't locate the problem in SEO, all this got resolved just minutes after reading you article. Thank you very much.

Collapse
 
kundukundu profile image
Chiyana Simões

Hello Luciano, thanks for sharing. Just one question:

I changed the builded code produced by Gatsby putting the meta tags just after the beginning of the head section.

How did you do that?

Thanks!

Collapse
 
lucis profile image
Lucis

I changed how I was importing stuff using React Helmet

Collapse
 
philolo1 profile image
Patrick Klitzke

Thank you so much, i was debugging this for a long time.

Collapse
 
thesamehunter profile image
seteevinteequatro

LUCIANO DE DEUS!!!!

Cara muito obrigado pelo artigo, consegui graças a vc!

Orgulho de ter um br ajudando os outros assim!!!!!

Collapse
 
lucis profile image
Lucis

Poxa cara, valeu!

Descobri esse problema praticamente sozinho e imaginei que alguém sofreria também no futuro ;)

Collapse
 
emersonpaiva profile image
Emerson Paiva

It works!!! the last thing I could think of was the styles on top of the page.
thanks for sharing the solution.