Skip to content

Commit 73e46ae

Browse files
authored
Merge pull request #363 from contentstack/VE-5279-onchange-when-live-preview-parameter-is-present
fix: call onChangeCallback when live_preview parameter is present in URL
2 parents 7f0afad + 269b852 commit 73e46ae

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

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

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

155-
if (!skipInitialRender) {
155+
const searchParams =
156+
typeof window !== "undefined"
157+
? new URLSearchParams(window.location.search)
158+
: null;
159+
const hasLivePreviewHash =
160+
searchParams && searchParams.has("live_preview");
161+
const isBuilder = searchParams && searchParams.has("builder");
162+
const shouldCallCallback = hasLivePreviewHash && isBuilder;
163+
// calling onChangeCallback when live_preview search parameter
164+
// is present because we don't send the initial client-data-send
165+
// message in visual builder
166+
if (!skipInitialRender || shouldCallCallback) {
156167
onChangeCallback();
157168
}
158169

0 commit comments

Comments
 (0)