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

Next JS (SSR) React support #297

Closed
YElyousfi opened this issue Apr 22, 2019 · 9 comments
Closed

Next JS (SSR) React support #297

YElyousfi opened this issue Apr 22, 2019 · 9 comments
Assignees
Labels

Comments

@YElyousfi
Copy link

How can this be made to not rely on window being defined? Trying to integrate this with Next.JS / server-side-rendering but this means that on the server window is not defined.

@jenssogaard
Copy link
Contributor

jenssogaard commented Apr 22, 2019

hi @YElyousfi. That is a good question. Could you skip SSR for the CF integration and execute when typeof window !== undefined ?

@jenssogaard
Copy link
Contributor

@YElyousfi I haven't heard from you so I will assume that my answer solved your issue. Feel free to open a new issue if needed.

@jonrrivera
Copy link

how can we go about doing this?

@pfortes
Copy link

pfortes commented Nov 10, 2020

Use dynamic imports or check if typeof window !== undefined

@jonrrivera
Copy link

I imported the module using

import dynamic from 'next/dynamic';
const ConversationalForm = dynamic(import('conversational-form'), { ssr: false });

now I'm getting this when copying the get started code:

Screen Shot 2020-11-10 at 11 57 12 AM

@jonrrivera
Copy link

jonrrivera commented Nov 10, 2020

dynamically importing like this made ConversationalForm = undefined

const { ConversationalForm } = dynamic(import('conversational-form'), { ssr: false });

@pfortes
Copy link

pfortes commented Nov 10, 2020

@jonrrivera maybe try adding conversational form inside a component and then importing that component dynamically .

i use suspense

const isSSR = typeof window === 'undefined';

{!isSSR && (
    <React.Suspense fallback={<div />}>
         <ContactChat />
    </React.Suspense>
 )}

in the ContactChat component i import conversationalform normaly:
import { ConversationalForm } from 'conversational-form';

This was referenced Nov 10, 2020
@jonrrivera
Copy link

you legend, this actually worked!

@pfortes
Copy link

pfortes commented Nov 10, 2020

@jonrrivera Glad to hear that!

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

No branches or pull requests

4 participants