Skip to content

Commit b42d2f8

Browse files
authored
Merge pull request #86 from contentstack/live-preview-fix
Conditionally initializing ContentstackLivePreview
2 parents 0b11419 + 2a5c310 commit b42d2f8

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fileignoreconfig:
1111
- filename: src/sdk/utils.ts
1212
checksum: 00fb0674684ede99467f5d77012d92136481d54c75894768646e58703ae0fa5a
1313
- filename: src/sdk/entry.ts
14-
checksum: 33b8aa8ad61a79911b22c61b418094034b308ca96bdebdc2619398337433fa1d
14+
checksum: 4f8b6df5fa08a66e57286a0dd69d1b49064f7f4540a627e8fa63730b6ee9cbf3
1515
version: "1.0"

src/sdk/entry.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ if (customHostBaseUrl && isValidCustomHostUrl(customHostBaseUrl)) {
3232
Stack.setHost(customHostBaseUrl);
3333
}
3434

35-
// Setting LP if enabled
36-
ContentstackLivePreview.init({
37-
//@ts-ignore
38-
stackSdk: Stack,
39-
enable: ENV.LIVE_PREVIEW === "true",
40-
mode: "builder",
41-
stackDetails: {
42-
apiKey: ENV.API_KEY,
43-
},
44-
clientUrlParams:{
45-
host: ENV.APP_HOST
46-
}
47-
})?.catch((error) => console.error(error));
35+
if (ENV.LIVE_PREVIEW === "true") {
36+
// Setting LP if enabled
37+
ContentstackLivePreview.init({
38+
//@ts-ignore
39+
stackSdk: Stack,
40+
enable: ENV.LIVE_PREVIEW === "true",
41+
mode: "builder",
42+
stackDetails: {
43+
apiKey: ENV.API_KEY,
44+
},
45+
clientUrlParams: {
46+
host: ENV.APP_HOST
47+
}
48+
})?.catch((error) => console.error(error));
49+
}
4850

4951

5052
export const { onEntryChange } = ContentstackLivePreview;

src/sdk/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const isBasicConfigValid = () => {
2727
// Live preview config validation
2828
export const isLpConfigValid = () => {
2929
return (
30-
!!ENV.LIVE_PREVIEW &&
30+
ENV.LIVE_PREVIEW === "true" &&
3131
!!ENV.PREVIEW_TOKEN &&
3232
!!ENV.PREVIEW_HOST &&
3333
!!ENV.APP_HOST
@@ -75,7 +75,7 @@ export const initializeContentStackSdk = (): Stack => {
7575
};
7676

7777
// api host url
78-
export const customHostUrl = (baseUrl=''): string => {
78+
export const customHostUrl = (baseUrl = ''): string => {
7979
return baseUrl.replace("api", "cdn");
8080
};
8181

0 commit comments

Comments
 (0)