garmeeh / next-seo

Next SEO is a plug in that makes managing your SEO easier in Next.js projects.
MIT License
7.73k stars 402 forks source link

Not able to set empty description if default seo config is provided #934

Open ashwinkhode opened 2 years ago

ashwinkhode commented 2 years ago

Describe the bug I want to set empty description but I am not able to override the default seo's description. Can I do it or is it just not possible? This is more of a question rather than a bug.

Expected behavior Empty description should be set if passed empty string "" in NextSeo even if default seo is present

AntoineKM commented 2 years ago

Try this code:

<NextSeo description={undefined} />
ashwinkhode commented 2 years ago

Try this code:

<NextSeo description={undefined} />

@AntoineKM Tried! not working :(

zeckdude commented 2 years ago

Yeah, i'm running into the same issue. Not even an empty string works.

ofilipowicz commented 2 years ago

Any workaround?

GrzegorzDerdak commented 2 years ago

Guys, for me it was another component, somewhere down the tree, in the same view, that was overriding the "description" with empty string description="" maybe that's your case too

ofilipowicz commented 2 years ago

@GrzegorzDerdak Do you mean that you were able to "unset" a description for a single page when a default is used globally?

Arjan-Zuidema commented 1 year ago

Looks like the only way to "fix" this is by using a space. Would be nice if you can override the default with undefined or null to unset a property

GonzaloZiadi commented 1 year ago

Same issue for me. Is there any workaround?

I'm setting default SEO at the _app.tsx level and want to remove some tags on my 404 page.

GonzaloZiadi commented 1 year ago

Here's my workaround:

import type { AppProps } from "next/app";
import Script from "next/script";
import { DefaultSeo } from "next-seo";
import SEO_CONFIG from "@/lib/seo/next-seo.config";
import Layout from "@/components/layout";

export default function App({ Component, pageProps }: AppProps) {
  const is404 = Component.name === "Custom404";

  return (
    <>
      { !is404 && <DefaultSeo {...SEO_CONFIG} /> }

      <Layout>
        <Component {...pageProps} />
      </Layout>
    </>
  );
}

Then I use NextSeo tag (import { NextSeo } from "next-seo";) in my Custom404 component.

import { PageConfig } from "next";
import { NextSeo } from "next-seo";
import { SITE_NAME } from "@/lib/constants";
import { ADDITIONAL_META_TAGS, FAVICON_TAGS } from "@/lib/seo/next-seo.config";

export const config: PageConfig = {
  unstable_runtimeJS: false,
};

export default function Custom404() {
  const title = `Page not found - ${ SITE_NAME }`;

  return (
    <>
      <NextSeo
        title={ title }
        noindex={ true }
        additionalMetaTags={ ADDITIONAL_META_TAGS }
        additionalLinkTags={ FAVICON_TAGS }
        openGraph= {{
          locale: "en_US",
          title: title,
          siteName: SITE_NAME,
        }}
      />

      <h1>404 - Page Not Found</h1>
  );
};