Skip to content

Commit 98562c7

Browse files
fix: call onLiveEdit on registration only in builder
Avoid calling onLiveEdit in apps other than builder as it can lead to multiple calls in Timeline and LP. Resolving this issue would then require storing some state to ensure the callback is only called from one code location on the first load which then has the posssibiliy of breaking setups that rely on the behaviour of the callback being called multiple times.
1 parent a0d3a5d commit 98562c7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ class ContentstackLivePreview {
156156
const isLivePreviewSearchParamPresent =
157157
isWindowDefined &&
158158
new URLSearchParams(window.location.search).has("live_preview");
159+
const isBuilder =
160+
isWindowDefined &&
161+
new URLSearchParams(window.location.search).has("builder");
162+
const shouldCallCallback =
163+
isLivePreviewSearchParamPresent && isBuilder;
159164
// calling onChangeCallback when live_preview search parameter
160165
// is present because we don't send the initial client-data-send
161166
// message in visual builder
162-
if (!skipInitialRender || isLivePreviewSearchParamPresent) {
167+
if (!skipInitialRender || shouldCallCallback) {
163168
onChangeCallback();
164169
}
165170

0 commit comments

Comments
 (0)