Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Beethoven opened this issue Apr 29, 2022 · 4 comments
Open
Assignees

Comments

@Beethoven
Copy link

Following guide at

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

and gets this error:
ReferenceError: self is not defined

@AnuragVasanwala
Copy link

AnuragVasanwala commented May 6, 2022

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!

@Beethoven
Copy link
Author

Beethoven commented May 11, 2022

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
Copy link
Author

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.

@slavakurilyak
Copy link

Reporting the same self is not defined error here 👇

error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants