Skip to content

Commit a0d3a5d

Browse files
fix: call onChangeCallback when live_preview parameter is present in URL
Visual Builder doesn't send client-data-send on site load, this leads to the site not making any calls to the preview service which is required for the subsequent entry PATCH requests to work correctly. onChangeCallback is called when either skipInitialRender is false or when live_preview search parameter is present in the URL. Since Visual Builder provides these values through the search parameter, the site makes entry GET calls to the preview service. Since live preview doesn't provide these params in non-SSR modes, it will continue to work the same.
1 parent 20c2c58 commit a0d3a5d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/preview/contentstack-live-preview-HOC.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ class ContentstackLivePreview {
152152
onChangeCallback;
153153
}
154154

155-
if (!skipInitialRender) {
155+
const isWindowDefined = typeof window !== "undefined";
156+
const isLivePreviewSearchParamPresent =
157+
isWindowDefined &&
158+
new URLSearchParams(window.location.search).has("live_preview");
159+
// calling onChangeCallback when live_preview search parameter
160+
// is present because we don't send the initial client-data-send
161+
// message in visual builder
162+
if (!skipInitialRender || isLivePreviewSearchParamPresent) {
156163
onChangeCallback();
157164
}
158165

0 commit comments

Comments
 (0)