timekit-io / booking-js

:date: Make a beautiful embeddable booking widget in minutes
https://developers.timekit.io/docs/booking-widget-v2
MIT License
2.42k stars 188 forks source link

Not working with SSR using Next JS #242

Closed spiftire closed 1 year ago

spiftire commented 2 years ago

I can not get this module to work with server side rendering.

I have followed provided guides and instansiated the the module as follows.

const timekit = new TimekitBooking({
    autoload: false,
    app_key: process.env.NEXT_PUBLIC_TIMEKIT_API,
    project_id: projectId,
})
ReferenceError: window is not defined

This happen even when i set up the following guard. before instansiating the module

if (typeof window === undefined) return
agnese-kerubina commented 1 year ago

It is not Booking Widget's fault, you just need to make sure widget component is not rendered on server. One way to go about this is to create a client side only component and call this via next.js dynamic import.

import dynamic from "next/dynamic";
const TimekitWidget = dynamic(() => import("./TimekitWidget"), { ssr: false });