Skip to content

Fix: Preserve iframe preview when cancelling brick edit modal#38

Open
hempsworth wants to merge 1 commit into
awcodes:3.xfrom
hempsworth:fix/iframe-blank-on-modal-cancel
Open

Fix: Preserve iframe preview when cancelling brick edit modal#38
hempsworth wants to merge 1 commit into
awcodes:3.xfrom
hempsworth:fix/iframe-blank-on-modal-cancel

Conversation

@hempsworth

Copy link
Copy Markdown

Problem

When editing a brick and cancelling (or closing) the modal, the iframe preview goes blank. Saving works fine — the issue only occurs when the modal is dismissed without saving.

  • Laravel v12.51.0
  • Filament v5.2.1
  • Livewire v4.1.4
  • Mason v3.0.4

Cause

When a Filament action modal is cancelled, unmountAction triggers a Livewire request. The server response causes a DOM morph to update the page. With wire:ignore on the <iframe> element itself, Livewire's morph algorithm can still replace the element if it cannot match it during tree diffing - the wire:ignore attribute is only checked when the morpher updates an existing element, not when it decides to remove and re-insert one.

Once the iframe is replaced, the Alpine component retains a stale reference to the old (now detached) element, and the new empty iframe is never populated with the preview content.

Solution

Move wire:ignore from the <iframe> to its parent mason-editor-wrapper <div>. This tells Livewire to skip the entire subtree during morphs, preventing the iframe from being replaced.

Changes

resources/views/mason.blade.php — moved wire:ignore from <iframe> to parent <div class="mason-editor-wrapper">.

How to verify

  1. Create a page with a Mason field and add one or more bricks
  2. Save the record
  3. Edit any brick (click edit or double-click)
  4. Cancel the modal without saving
  5. Before this fix: iframe preview goes blank
  6. After this fix: iframe preview is preserved

Move `wire:ignore` from the `<iframe>` element to its parent
`mason-editor-wrapper` div. When a Filament action modal is
cancelled, the `unmountAction` Livewire response triggers a DOM
morph that replaces the iframe element, causing the preview to go
blank. Placing `wire:ignore` on the wrapper div ensures the entire
subtree is preserved during morphs.
@awcodes

awcodes commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Can you provide a reproduction repo? I can't replicate this on either Filament v4 or v5.

@hempsworth

hempsworth commented Feb 11, 2026

Copy link
Copy Markdown
Author

Can you provide a reproduction repo? I can't replicate this on either Filament v4 or v5.

Ok, so this is interesting. It looks like the Grammarly Chrome extension is the cause.

Grammarly injects a <grammarly-extension> element inside the mason-editor-wrapper div. When Livewire morphs the DOM, the server HTML doesn't have that element, so the morph algorithm can't match the children correctly and replaces the iframe.

CleanShot 2026-02-11 at 21 46 39@2x

The patch still solves this, and theoretically, for any other tool like Grammarly that injects like this. Moving wire:ignore to the wrapper div protects the subtree from being morphed at all.

Gif here to show what I'm seeing with the Grammarly extension installed:

CleanShot 2026-02-11 at 21 49 50

@awcodes

awcodes commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Interesting. What could possibly be causing grammarly to inject at that spot? That's weird to me. I'm also not sure that it's something specifically that can be handled by the plugin since it has no context of any external thing injecting its own code wherever it sees fit.

@nzmattman

Copy link
Copy Markdown

i can confirm i also get this, and i also have Grammarly installed.
I have disabled it and it works as intended

@hempsworth

hempsworth commented Feb 26, 2026

Copy link
Copy Markdown
Author

Interesting. What could possibly be causing grammarly to inject at that spot? That's weird to me. I'm also not sure that it's something specifically that can be handled by the plugin since it has no context of any external thing injecting its own code wherever it sees fit.

Grammarly injects into every <html> element it sees on the page, so it may well have similar behaviour with <iframe> elements as well. If there are no side-effects to changing the location of the wire:ignore would you consider making this change to naturally fix the issue for anybody who might encounter it?

The problem for devs is we can't really disable this Grammarly behaviour, so it's something we would have to tell end-users to disable.

@awcodes

awcodes commented Feb 27, 2026

Copy link
Copy Markdown
Owner

I'm not opposed to it, but I also don't know that it's a guaranteed fix. Maybe it works for grammarly, but it's not a bullet proof solution. Especially considering that it doesn't make sense why grammarly is injecting into an html element that is not an actual input element. I'm willing to support a fix but not at the cost of supporting external things that I can't control.

@awcodes

awcodes commented Feb 27, 2026

Copy link
Copy Markdown
Owner

I will have to test further, but moving the wire:ignore can have implications on the filament get and set utilities too.

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.

3 participants