Error: Save event is not initialized, please call `ContentfulLivePreview.init()` first

30 Views Asked by At

When I use contentful preview SDK with nextjs 14, and I lazy load the preview SDK using lazy and Suspense it gives me this error, any idea where should I call it to preview this error?

Preview.ts:

import { ContentfulLivePreview } from '@contentful/live-preview';

ContentfulLivePreview.init({
  debugMode: true,
  enableLiveUpdates: true,
  locale: 'en-US',
});

ContentfulLivePreview.subscribe('save', {
  callback: () => {
    const pathname = window.location.pathname;

    return fetch(`/api/revalidate?pathname=${pathname}`);
  },
});

Layout:

<BrandProvider>
   <Suspense fallback={null}>{isEnabled && <Preview />}</Suspense>
   {header}
   <div className="flex-1" data-testid="body-content">
       {children}
   </div>
   {footer}
</BrandProvider>
0

There are 0 best solutions below