Skip to content

Fix editor going blank when it is moved in the DOM (modals, Vue re-ordering) (#131, #230)#496

Open
ELHart05 wants to merge 1 commit into
tinymce:mainfrom
ELHart05:fix/131-recover-editor-on-dom-reattach
Open

Fix editor going blank when it is moved in the DOM (modals, Vue re-ordering) (#131, #230)#496
ELHart05 wants to merge 1 commit into
tinymce:mainfrom
ELHart05:fix/131-recover-editor-on-dom-reattach

Conversation

@ELHart05

@ELHart05 ELHart05 commented Jun 11, 2026

Copy link
Copy Markdown

What this fixes

Fixes #131 and #230, two reports of the same "blank editor" problem (also seen in #106 and #113).

The editor works the first time but comes back blank and unresponsive once something moves it in the DOM. Two common triggers:

The cause is browser behavior, not TinyMCE. Per the HTML standard, removing an <iframe> from the document and inserting it again discards and recreates its document, so moving the editor wipes the editing iframe. Vue never unmounts the component during the move, so none of the lifecycle hooks fire and the editor has no chance to recover. SimonFc explained this back in #106; until now the only answer was a manual v-if or :key workaround in application code.

How it works

The same part of the standard says an iframe re-runs its load steps every time it is inserted, so it fires a load event again on re-insertion. The component now listens for that. The first load is the editor's own initialization; any load after that means the iframe was moved and blanked. When it happens, the dead editor is removed and a new one is initialized in place, with its content restored.

A few specifics:

  • Content is kept. For v-model it comes from the bound value. For the uncontrolled (initialValue) case the component keeps a copy of the content current as it changes, since the blanked iframe can no longer be read by the time we detect the move.
  • Inline editors have no iframe, so nothing changes for them.
  • The load listener is removed on every teardown path, and the re-init is guarded so it can't run after the component is unmounted or deactivated, and can't loop.

It is automatic. Existing apps need no changes, and normal and inline usage behave exactly as before.

Tests

src/test/ts/browser/ReattachTest.ts moves the editor and checks that it recovers. It runs against TinyMCE 4 through 8 and covers:

The full suite (62 tests) passes, and the library and demo both build.

Demo

Added a Modal view to the demo app (route /modal) that reproduces the problem with a Teleport-based modal and shows the editor surviving repeated opens. It pulls in no extra dependencies.

@ELHart05 ELHart05 requested a review from a team as a code owner June 11, 2026 00:11
@ELHart05 ELHart05 requested review from TheSpyder and spocke and removed request for a team June 11, 2026 00:11
)

Editors used inside a modal or dialog that relocates its content on open
(Bootstrap-Vue, Vuetify, and others), or moved by Vue re-ordering the
surrounding elements, came back blank and unresponsive after the move. Moving
an iframe in the DOM makes the browser discard its document, and because Vue
never unmounts the component, no lifecycle hook fires to recover.

Listen for the iframe's load event, which the browser re-runs on every
re-insertion: a load after the first one means the editor was moved, so it is
removed and re-created in place with its content restored. Inline editors have
no iframe and are left untouched.

Adds browser tests covering TinyMCE 4-8 (modal-style moves and Vue re-ordering)
and a Teleport-based modal demo.
@ELHart05 ELHart05 force-pushed the fix/131-recover-editor-on-dom-reattach branch from 641b982 to a2d5448 Compare June 11, 2026 00:25
@ELHart05 ELHart05 changed the title Fix editor becoming blank when moved in the DOM, e.g. inside a modal (#131) Fix editor going blank when it is moved in the DOM (modals, Vue re-ordering) (#131, #230) Jun 11, 2026
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.

Workaround for new Boostrap-vue when editor became zombie

1 participant