Skip to content

fix(VP-556): replace deprecated unload event with pagehide in page traversal#599

Open
kirtesh-cstk wants to merge 6 commits into
develop_v4from
VP-556-replace-deprecated-unload-event-listeners
Open

fix(VP-556): replace deprecated unload event with pagehide in page traversal#599
kirtesh-cstk wants to merge 6 commits into
develop_v4from
VP-556-replace-deprecated-unload-event-listeners

Conversation

@kirtesh-cstk
Copy link
Copy Markdown
Contributor

@kirtesh-cstk kirtesh-cstk commented May 25, 2026

Summary

  • Replaces the deprecated window.addEventListener("unload", ...) with window.addEventListener("pagehide", ...) in src/livePreview/onPageTraversal.ts
  • Deletes src/utils/handlePageTraversal.ts — this file was dead code (not imported anywhere) but also contained a deprecated unload listener
  • The pagehide event is the browser-recommended drop-in replacement for unload; it fires in the same navigation scenarios without blocking the Back-Forward Cache (BFCache)

Jira: VP-556

Why this change

The unload event has been deprecated since Chrome 115+ as part of BFCache improvements. Browsers suppress it silently in many scenarios, making it unreliable. pagehide is the standardized replacement with identical semantics for page navigation tracking.

The affected code notifies the parent Contentstack window (via livePreviewPostMessage.send) when a user navigates to a new page inside the live preview iframe, so the parent can sync its own navigation.

Impact areas to verify

Please test the following areas end-to-end to confirm no regression:

  • Undo-redo navigation in Live Preview — verify that navigating between pages stores proper history and undo/redo is properly working.
  • Preview Share — verify that shared preview links open and navigate correctly, and URL change events are relayed to the parent
  • Params persistence in Timeline UI — verify that query params (e.g., content type, entry UID, locale) are preserved correctly when navigating pages in Timeline preview mode
  • Composable Studio — verify whether Composable Studio consumes the url-change postMessage event from this SDK; if so, confirm navigation between pages in the preview still works correctly after this change

Notes

  • The advanced-post-message transport layer is unchanged — only the trigger event (unloadpagehide) is swapped
  • No change to the postMessage payload format ({ targetURL }) or event type ("url-change")

hitesh-shetty-cstk and others added 6 commits May 21, 2026 17:47
…aversal

The unload event is deprecated in modern browsers (suppressed since
Chrome 115+ for BFCache compatibility) and was used to notify the parent
frame when a user navigates to a new page in the live preview iframe.

Replaced with the pagehide event, which is the browser-recommended
drop-in replacement — it fires in the same scenarios without blocking
BFCache.

Also deleted src/utils/handlePageTraversal.ts which was dead code
(not imported anywhere) but also contained a deprecated unload listener.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kirtesh-cstk kirtesh-cstk requested review from a team as code owners May 25, 2026 09:50
@github-actions
Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 0 25 ✅ Passed
🟡 Medium Severity 0 0 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

✅ BUILD PASSED - All security checks passed

@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 66.61% 2472 / 3711
🔵 Statements 65.47% 2511 / 3835
🔵 Functions 64.25% 444 / 691
🔵 Branches 60.7% 1480 / 2438
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/livePreview/onPageTraversal.ts 25% 0% 50% 25% 6-13
Generated in workflow #825 for commit 15ab0c6 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

@hitesh-shetty-cstk hitesh-shetty-cstk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants