bentojs.dev icon indicating copy to clipboard operation
bentojs.dev copied to clipboard

[BUG] Bento components on NEXTJS - ReferenceError: self is not defined

Open Beethoven opened this issue 3 years ago • 4 comments

Following guide at

https://bentojs.dev/documentation/guides/bento-next.js-guide/

and gets this error: ReferenceError: self is not defined

Beethoven avatar Apr 29 '22 20:04 Beethoven

Hi @Beethoven 👋🏻

Would you please try using dynamic import with ssr disabled instead of importing conventionally?

Syntax:

import dynamic from "next/dynamic";

const <module_name> = dynamic(() =>
  import(<path>).then((mod) => mod.<component_to_use>),
  { ssr: false }
);

So, this import block:

import {
  BentoAccordion,
  BentoAccordionSection,
  BentoAccordionHeader,
  BentoAccordionContent,
} from '@bentoproject/accordion/react';

import '@bentoproject/accordion/styles.css';

would be written as:

import dynamic from "next/dynamic";

// Use dynamic import with SSR disabled for all imports except CSS
const BentoAccordion = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordion),
  { ssr: false }
);
const BentoAccordionSection = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordionSection),
  { ssr: false }
);
const BentoAccordionHeader = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordionHeader),
  { ssr: false }
);
const BentoAccordionContent = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordionContent),
  { ssr: false }
);

import "@bentoproject/accordion/styles.css";

For detailed information on dynamic import, refer https://nextjs.org/docs/advanced-features/dynamic-import

I am also trying to figure out root cause of the issue. Will post when found!

AnuragVasanwala avatar May 06 '22 14:05 AnuragVasanwala

Hi @Beethoven 👋🏻

Would you please try using dynamic import with ssr disabled instead of importing conventionally?

Syntax:

import dynamic from "next/dynamic";

const <module_name> = dynamic(() =>
  import(<path>).then((mod) => mod.<component_to_use>),
  { ssr: false }
);

So, this import block:

import {
  BentoAccordion,
  BentoAccordionSection,
  BentoAccordionHeader,
  BentoAccordionContent,
} from '@bentoproject/accordion/react';

import '@bentoproject/accordion/styles.css';

would be written as:

import dynamic from "next/dynamic";

// Use dynamic import with SSR disabled for all imports except CSS
const BentoAccordion = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordion),
  { ssr: false }
);
const BentoAccordionSection = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordionSection),
  { ssr: false }
);
const BentoAccordionHeader = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordionHeader),
  { ssr: false }
);
const BentoAccordionContent = dynamic(() =>
  import("@bentoproject/accordion/react").then((mod) => mod.BentoAccordionContent),
  { ssr: false }
);

import "@bentoproject/accordion/styles.css";

For detailed information on dynamic import, refer https://nextjs.org/docs/advanced-features/dynamic-import

I am also trying to figure out root cause of the issue. Will post when found!

Yes, this works, but the robots can't see the info on Accordion (the same with all Bento Components) as It's not rendered on server, only on client. Thus, all Bento components are useless from the SEO perspective.

Beethoven avatar May 11 '22 12:05 Beethoven

And the dos on https://bentojs.dev/documentation/guides/bento-next.js-guide/ is wrong. Client-side rendering can increase the likelihood of a poor user experience and for search engine bots. If Bento is for client side only, it's useless.

Beethoven avatar May 11 '22 12:05 Beethoven

Reporting the same self is not defined error here 👇

error

slavakurilyak avatar Jun 11 '22 16:06 slavakurilyak