nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.13k stars 4.94k forks source link

undefined title in google SERP? #27725

Closed carlosvaldesweb closed 2 months ago

carlosvaldesweb commented 3 months ago

Environment

Production in Hosted in Vercel

Reproduction

You can check app.vue and index.vue to check how to set titles. https://stackblitz.com/edit/nuxt-starter-n1zpvy?file=app.vue

Describe the bug

Hello, I am having some SEO issues with my website. Previously, we used Laravel to develop the front end of our site, but we decided to migrate to Nuxt. The problem is that sometimes our website appears with the title "undefined" in Google's SERP. I haven't noticed which specific pages it happens with, but it has already happened with several search terms.

For example, if I search for the term "resumir textos", the page appears as "undefined", but it can stay like that for a few hours or days and then return to normal.

Captura de pantalla 2024-06-19 a la(s) 8 04 17 p m

I have noticed that other people have this specific problem with Nuxt because if I search on Google "undefined in google serp" without adding any programming language or any reference, another Nuxt topic appears.

https://www.reddit.com/r/Nuxt/comments/14cjpq6/undefined_in_title_on_google_serp/

Captura de pantalla 2024-06-19 a la(s) 8 28 03 p m

This is concerning because it is negatively affecting the SEO of our website.

Additional context

No response

Logs

No response

stackblitz[bot] commented 3 months ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

danielroe commented 3 months ago

Can you update the reproduction to reproduce this without @nuxtjs/i18n?

If not, would you open an issue in https://github.com/nuxt-modules/i18n instead? 🙏

github-actions[bot] commented 3 months ago

Would you be able to provide a reproduction? 🙏

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: 👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz 👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
carlosvaldesweb commented 3 months ago

For sure @danielroe , here is reproduction without i18n https://stackblitz.com/edit/nuxt-starter-pfk6oh?file=app.vue

danielroe commented 3 months ago

Sorry, but I've checked your reproduction and it seems to have a defined title. What do I need to do to reproduce?

github-actions[bot] commented 3 months ago

Would you be able to provide a reproduction? 🙏

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: 👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz 👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
carlosvaldesweb commented 3 months ago

@danielroe Yes, i't have a title, but i don't know why in google SERP title is undefined.

danielroe commented 3 months ago

ccing @harlan-zw in case he's encountered this before, but it's very difficult to investigate in this situation

carlosvaldesweb commented 3 months ago

@danielroe I'm thinking that the issue is related that this line

const title = computed(() =>
  route.meta.title
    ? route.meta.title
    : ''
);

When i set empty title, the tag is empty

<title></title>

According to Mozilla, this tag must always have text.

I've changed my code to the following:

const title = computed(() =>
  route.meta.title
    ? route.meta.title
    : undefined
);

Those pages always have a title, but I don't know why Google does that. I'm not sure if there might be an issue with the delay hydration module or if sometimes nuxt sends the empty tag during SSR. What do you think? I've changed my code and push to production, i'll be monitoring these days and updating in this issue.

harlan-zw commented 2 months ago

The issue was probably related to the hydration of the title, given that you have the nuxt-delay-hydration module. Either hydrating to undefined before flashing back "my title" -> undefined -> "my title" or undefined -> "my title".

The current site looks correct so this will sort itself out once google re-indexes it. Will close for now but feel free to ping me if it doesn't sort itself out.

I've also made https://github.com/unjs/unhead/issues/359 to track not including empty titles.