Skip to content

Commit b365b99

Browse files
authored
Merge pull request #505 from contentstack/18th-sept-2025-release
18th sept 2025 release
2 parents ba866e8 + 9cbb317 commit b365b99

File tree

4 files changed

+48
-51
lines changed

4 files changed

+48
-51
lines changed

.github/workflows/secrets-scan.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

CODEOWNERS

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
* @contentstack/security-admin
1+
* @contentstack/ghost-pr-reviewers
2+
3+
.github/workflows/sca-scan.yml @contentstack/security-admin
4+
5+
.github/workflows/codeql-anaylsis.yml @contentstack/security-admin
6+
7+
**/.snyk @contentstack/security-admin
8+
9+
.github/workflows/policy-scan.yml @contentstack/security-admin
10+
11+
.github/workflows/issues-jira.yml @contentstack/security-admin

src/livePreview/eventManager/__test__/postMessageEvent.hooks.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ describe("postMessageEvent.hooks", () => {
159159
(Config.get as any).mockReturnValue(mockConfig);
160160
});
161161

162-
it("should reload window when ssr is true and no event_type", () => {
163-
// Set URL to include live_preview parameter so reload path is taken
164-
mockWindow.location.href = "https://example.com?live_preview=old-hash";
162+
it("should reload window when ssr is true and no event_type and all params present", () => {
163+
// Set URL to include all required params so reload path is taken
164+
mockWindow.location.href = "https://example.com?live_preview=old-hash&content_type_uid=blog&entry_uid=entry-123";
165165

166166
const eventData: OnChangeLivePreviewPostMessageEventData = {
167167
hash: "test-hash",

src/livePreview/eventManager/postMessageEvent.hooks.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function useOnEntryUpdatePostMessageEvent(): void {
5050
LIVE_PREVIEW_POST_MESSAGE_EVENTS.ON_CHANGE,
5151
(event) => {
5252
try {
53-
const { ssr, onChange } = Config.get();
53+
const { ssr, onChange, stackDetails } = Config.get();
5454
const event_type = event.data._metadata?.event_type;
5555
setConfigFromParams({
5656
live_preview: event.data.hash,
@@ -59,41 +59,57 @@ export function useOnEntryUpdatePostMessageEvent(): void {
5959
// This section will run when there is a change in the entry and the website is CSR
6060
if (!ssr && !event_type) {
6161
onChange();
62-
}
62+
}
6363

64-
if(isOpeningInNewTab()) {
65-
if(!window) {
64+
if (isOpeningInNewTab()) {
65+
if (!window) {
6666
PublicLogger.error("window is not defined");
6767
return;
6868
};
69-
70-
// This section will run when there is a change in the entry and the website is SSR
71-
if(ssr && !event_type) {
72-
if(window.location.href.includes("live_preview")) {
69+
70+
if (ssr && !event_type) {
71+
const url = new URL(window.location.href);
72+
let live_preview = url.searchParams.get("live_preview");
73+
let content_type_uid = url.searchParams.get("content_type_uid");
74+
let entry_uid = url.searchParams.get("entry_uid");
75+
76+
if (live_preview && content_type_uid && entry_uid) {
77+
// All required params are present, just reload
7378
window.location.reload();
7479
} else {
75-
const url = new URL(window.location.href);
76-
url.searchParams.set("live_preview", event.data.hash);
77-
url.searchParams.set("content_type_uid", Config.get().stackDetails.contentTypeUid || "");
78-
url.searchParams.set("entry_uid", Config.get().stackDetails.entryUid || "");
80+
live_preview = event.data.hash;
81+
content_type_uid = event.data.content_type_uid || stackDetails.$contentTypeUid?.toString() || "";
82+
entry_uid = event.data.entry_uid || stackDetails.$entryUid?.toString() || "";
83+
// Set missing params and redirect
84+
url.searchParams.set("live_preview", live_preview);
85+
if (content_type_uid) {
86+
url.searchParams.set(
87+
"content_type_uid",
88+
content_type_uid
89+
);
90+
}
91+
if (entry_uid) {
92+
url.searchParams.set(
93+
"entry_uid",
94+
entry_uid
95+
);
96+
}
7997
window.location.href = url.toString();
8098
}
8199
}
82-
100+
83101
// This section will run when the hash changes and the website is SSR or CSR
84-
if(event_type === OnChangeLivePreviewPostMessageEventTypes.HASH_CHANGE){
102+
if (event_type === OnChangeLivePreviewPostMessageEventTypes.HASH_CHANGE) {
85103
const newUrl = new URL(window.location.href);
86104
newUrl.searchParams.set("live_preview", event.data.hash);
87105
window.history.pushState({}, "", newUrl.toString());
88106
}
89-
107+
90108
// This section will run when the URL of the page changes
91-
if(event_type === OnChangeLivePreviewPostMessageEventTypes.URL_CHANGE && event.data.url){
109+
if (event_type === OnChangeLivePreviewPostMessageEventTypes.URL_CHANGE && event.data.url) {
92110
window.location.href = event.data.url;
93111
}
94112
}
95-
96-
97113
} catch (error) {
98114
PublicLogger.error("Error handling live preview update:", error);
99115
return;

0 commit comments

Comments
 (0)