Skip to content

Content: guard PreviewMode postMessage against a detached iframe's null contentWindow - #4316

Open
github-actions[bot] wants to merge 1 commit into
devfrom
fix/4289-previewmode-null-contentwindow-guard
Open

Content: guard PreviewMode postMessage against a detached iframe's null contentWindow#4316
github-actions[bot] wants to merge 1 commit into
devfrom
fix/4289-previewmode-null-contentwindow-guard

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Resolves #4289

Severity: low

Summary

  • MANAGER-UI-3E5: PreviewMode.js crashed with TypeError: Cannot read properties of null (reading 'postMessage') when route() ran against an iframe whose contentWindow was already null (the ref still pointed at a detached iframe node), tripping the app's error boundary.
  • The fix extends the existing early-return guard in route() to also check preview.current.contentWindow, not just preview.current, before calling postMessage.

Classification

  • Root-cause certainty: PASS. The crash is fully explained by preview.current being truthy while preview.current.contentWindow is null (iframe detached from the DOM), and the existing guard only checked the former.
  • Blast radius: PASS. The change is confined to src/apps/content-editor/src/app/components/Editor/PreviewMode/PreviewMode.js, none of it touches auth, permissions, IndexedDB hydration, RTK Query base config, webpack config, or workflow files.
  • Verifiable by inspection: PASS. It's a one-line null-guard widening (!preview.current!preview.current?.contentWindow) that is a strict improvement in every case, not just the reported one.
  • Cohesion, not count: PASS. Single file, single guard clause, one conceptual change.

Test plan

  • Open the content/block editor preview, then rapidly navigate away or unmount the editor while a route update is pending, and confirm no postMessage TypeError is thrown and the error boundary doesn't trigger.

@github-actions github-actions Bot added the sentry-auto-fix PR auto-generated by the Sentry Handler workflow's auto-fix path label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

QA Review — ✅ PASS

Validates #4289: TypeError: Cannot read properties of null (reading 'postMessage')

  1. ✅ Guard the preview iframe's postMessage call so route() bails out when the iframe's contentWindow is unavailable, matching the Sentry stack trace (PreviewMode.js:50).
  2. ⚠️ Existing preview routing (loading a content item, switching versions) still fires correctly once the iframe is ready — can't confirm without running the app, but the guard only adds an early return and doesn't touch the success path.
Suggested Cypress coverage

cypress/e2e/content/content.spec.js has no preview-mode coverage today. Worth adding a case that opens an item's preview mode and asserts the iframe loads and reflects the item's route/version without the app crashing — and, if the iframe can be intercepted or its src swapped to simulate a not-yet-attached contentWindow (e.g. toggling preview mode rapidly or navigating away before load fires), asserting no uncaught error/ErrorBoundary trips. A simpler regression check: open preview mode, switch between two content items in quick succession, and confirm the editor stays mounted (no error boundary fallback UI) throughout.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Code Review — ✅ No blockers

finnar-bin added a commit that referenced this pull request Sep 3, 2026
## Summary
- Replace `claude-sentry-handler.yml`'s auto-fix commit path (`git
config` + `git checkout -b` + `git add -A` + `git commit` + `git push`)
with GitHub's Git Data API, called via a SHA-pinned
`actions/github-script@v7` step, so auto-fix commits show GitHub's
Verified badge.
- Split the old "Open auto-fix PR" step into three: **Prepare auto-fix
branch** (reads `branch_slug`/`pr_title`, captures dev HEAD's
commit/tree SHA), **Create verified auto-fix commit** (builds blobs per
touched file — preserving executable mode bits, representing deletions
with `sha: null`, hard-failing on symlinks/non-regular files — then
creates the tree/commit/ref via the API), and **Open auto-fix PR**
(unchanged reviewer-access checks + `gh pr create`, now passing `--head`
explicitly since there's no local checkout of the new branch).
- Updated **Parse classification** to surface its already-computed
`touched_files` list via `$GITHUB_OUTPUT` so the new step reuses it
instead of recomputing it.

## Test plan
- [x] `node --check` on the embedded github-script JS
- [x] YAML parses
- [x] Manual: trigger the Sentry auto-fix flow (or re-run
`claude-sentry-handler.yml` via `workflow_dispatch`) and confirm the
resulting commit shows the Verified badge

## Successful test run
- #4316

Closes #4299

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sentry-auto-fix PR auto-generated by the Sentry Handler workflow's auto-fix path

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read properties of null (reading 'postMessage')

2 participants