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
Open
Conversation
) 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.
641b982 to
a2d5448
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
v-ifblocks are toggled, per Text becomes blank if DOM elements are added or removed around tinymce instance #230.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 manualv-ifor:keyworkaround 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
loadevent again on re-insertion. The component now listens for that. The firstloadis the editor's own initialization; anyloadafter 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:
v-modelit 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.loadlistener 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.tsmoves the editor and checks that it recovers. It runs against TinyMCE 4 through 8 and covers:v-model: content preserved and the model handlers re-bound on the new editorThe full suite (62 tests) passes, and the library and demo both build.
Demo
Added a
Modalview to the demo app (route/modal) that reproduces the problem with aTeleport-based modal and shows the editor surviving repeated opens. It pulls in no extra dependencies.