Generated with the help of an LLM.
Problem/Motivation
Each Wysiwyg source form you leave leaves its CKEditor 5 instance alive.
The contextual form island is swapped out-of-band, and core's htmx integration only runs htmx:drupal:unload on the requesting element, not on what an out-of-band swap replaces. So Drupal.detachBehaviors() never runs on the old form, and core's ckeditor5.js never destroys its editor.
The old editor stays in Drupal.CKEditor5Instances, in its callbacks map, and in a drupalViewportOffsetChange handler on document. Nothing visible breaks, since core only reads those maps by id, but memory grows with each Wysiwyg form opened until the page reloads.
Steps to reproduce
1. Add two Wysiwyg sources in a format with an editor, such as Basic HTML.
2. Select the first, then the second, then the first again.
3. In the console, Drupal.CKEditor5Instances.size is 3, and only one editor is in the DOM.
Proposed resolution
Detach behaviors with the unload trigger on the island an out-of-band swap replaces, on htmx:oobBeforeSwap.
Remove it once core's htmx-assets.js unloads what a swap removes.
Comments