Skip to content

Commit

Permalink
Fix TinyMCE loading behavior after page change
Browse files Browse the repository at this point in the history
The old intersection observer was still active after leaving and reentering the page editor. An old intersection observer will now disconnect on initializer. This is not optimal, but we don't have a lifecycle hook to destroy the intersection on page leave.

Reference: AlchemyCMS#2485
  • Loading branch information
sascha-karnatz committed Jun 20, 2023
1 parent 5f0a70a commit 82e2e29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package/dist/admin.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package/dist/admin.js.map

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions package/src/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,32 @@ function initEditors(ids) {
})
}

// initialize IntersectionObserver if it is not already initialized
// initialize IntersectionObserver
// the observer will initialize Tinymce if the textarea becomes visible
function initializeIntersectionObserver() {
if (tinymceIntersectionObserver === null) {
const observerCallback = (entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
initTinymceEditor(entry.target)
// disable observer after the Tinymce was initialized
observer.unobserve(entry.target)
}
})
}
const options = {
root: Alchemy.ElementEditors.element_area.get(0),
rootMargin: "0px",
threshold: [0.05]
}
if (tinymceIntersectionObserver !== null) {
tinymceIntersectionObserver.disconnect()
}

tinymceIntersectionObserver = new IntersectionObserver(
observerCallback,
options
)
const observerCallback = (entries, observer) => {
entries.forEach((entry) => {
if (entry.intersectionRatio > 0) {
initTinymceEditor(entry.target)
// disable observer after the Tinymce was initialized
observer.unobserve(entry.target)
}
})
}
const options = {
root: Alchemy.ElementEditors.element_area.get(0),
rootMargin: "0px",
threshold: [0.05]
}

tinymceIntersectionObserver = new IntersectionObserver(
observerCallback,
options
)
}

// Initializes one specific TinyMCE editor
Expand Down

0 comments on commit 82e2e29

Please sign in to comment.