I am currently using Next.JS
to create a static website
with the main objective to have a very good SEO-optimized website.
Everything works fine and the website is correctly deployed with Vercel, but I have noticed that part of the content is not present directly in the HTML
files.
For instance, I have a component that loops over an array of data, using the array map
method, like this:
{imageTexts.map((image) => (
<ImageText
key={image.title + 'TitleImage'}
title={image.title}
description={image.description}
size={imagesSize}
image={image.image}
/>
))}
Once the website is deployed to Vercel
, I search inside the HTML
file for the information/strings contained in the array of data (imageTexts
), but I can’t find them. I guess Next.JS uses javascript to target some sort of div
and then loops over its own JSON file to dynamically display content.
For me, this seems to kill a lot of the SEO advantage that static websites
have over SPA
. Is there any way I can have those strings directly inside my HTML files?
I am still not 100% sure this is caused by the map
method, but I don’t find any other explanations. Especially because other dynamically loaded components don’t have the same problem. For example, this component string can be found on the HTML
file, without a problem:
{title ? (
<Text
type="h2"
textAlign="center"
>
{title}
</Text>
) : null}
2
Answers
Ok, I have just found that the reason. It has nothing to do with the
map
method. I was actually using the<Remark>
component from library calledreact-remark
. It seems it does not play well with Next.JSIf you are mapping over
ImageTexts
on the server and that component renders HTML tags, then that HTML should be sent on the first-page load, and you could see it if you do CTRL+U or disable javascript.