Updates Requested NPM Resource Changed PR-5.4-dev Pending

User tests: Successful: Unsuccessful:

avatar adarshdubey03
adarshdubey03
5 Apr 2026

Pull Request resolves #40641 .

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

This fixes two issues affecting Codemirror editors inside subform rows during drag reorder:

  1. Prevents duplicate Codemirror editor instances by avoiding self reordering during dragenter.
  2. Preserves editor content during drag reorder by syncing the current editor value back into the textarea before the editor instance is destroyed.

Testing Instructions

  1. Set CodeMirror as the default editor
  2. Create or edit an item that contains a subform field with an editor field
  3. Go to articles -> new -> feilds and add multiple subform rows
  4. Enter different text into Codemirror editors.
  5. Drag and reorder the rows

Actual result BEFORE applying this Pull Request

  1. Drag reordering creates duplicate Codemirror editor instances.
  2. Editor content is lost after drag reorder.

Expected result AFTER applying this Pull Request

  1. No duplicate Codemirror editor instances are created during drag reorder.
  2. Editor content remains preserved after drag reorder.

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar adarshdubey03 adarshdubey03 - open - 5 Apr 2026
avatar adarshdubey03 adarshdubey03 - change - 5 Apr 2026
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 Apr 2026
Category JavaScript Repository NPM Change
avatar Fedik
Fedik - comment - 5 Apr 2026

Sorry the fix is incorrect.
Hint: It even not really on Codemirror side (however it affects Codemirror itself due to how it work).

I give you a time to find a real reason πŸ˜ƒ

avatar adarshdubey03 adarshdubey03 - change - 6 Apr 2026
Labels Added: NPM Resource Changed PR-5.4-dev
avatar adarshdubey03
adarshdubey03 - comment - 6 Apr 2026

Thanks for the hint @Fedik . The issue turned out to be in how the editor handles its lifecycle during subform row reordering. so the element is actually moved in the dom (not recreated), which triggers disconnectedCallback() and then connectedCallback(). The current code treats this as a real removal and destroys the editor, so when it reconnects a new instance gets created, which causes duplicated editors. so the new fix is to delay the destruction in disconnectedCallback() and only destroy if the element is actually removed, while cancelling that delay if it reconnects ,so the editor instance is preserved.

avatar Fedik
Fedik - comment - 6 Apr 2026

You're close, but not quite there yet.
The disconnectedCallback() happens many times, but Codemirror cannot keep up with such amount.

Look why changing order with Up/Down button does not cause this issue, and why Draging the row do cause this issue.

avatar adarshdubey03
adarshdubey03 - comment - 6 Apr 2026

@Fedik Okay so the difference is not in the logic used to move the rows, since both drag and up/down use the same switchRowPositions() function. The key difference is how often it is triggered.
With the up/down buttons, switchRowPositions() is called once per click, that causes a single insertBefore() and one disconnectedCallback() / connectedCallback() cycle, which codemirror can handle correctly.

During drag, however, the row is repositioned multiple times during a single interaction, causing switchRowPositions() to be triggered multiple times. This results in multiple dom reorders and hence repeated disconnectedCallback() / connectedCallback() cycles. Because the editor is destroyed on each disconnect, Codemirror ends up being repeatedly destroyed and re initialized in quick succession, which it cannot handle properly.

avatar Fedik
Fedik - comment - 6 Apr 2026

Correct, you are looking in the right direction πŸ˜ƒ

avatar adarshdubey03 adarshdubey03 - change - 11 Apr 2026
Labels Added: Updates Requested
avatar adarshdubey03
adarshdubey03 - comment - 11 Apr 2026

@Fedik I have updated the patch. Could you please review the updated fix when you have time?

avatar Fedik
Fedik - comment - 12 Apr 2026

Hm, no.
Another hint. The fix is actually ~1 line of code.
And it is in a different place.

avatar adarshdubey03
adarshdubey03 - comment - 13 Apr 2026

@Fedik There are tow separate effects happeing during reorder of the rows.

  1. Duplicate Codemirror instances
  2. Editor content loss during drag reorder

The one line fix you are suggesting is possibly adding a guard in dragenter - if (!row || row.closest('joomla-field-subform') !== that || row === item) return; but this fixes the duplicate codemirror instances issue, however the content loss still remains.

Should this pr remain scoped only to fixing the duplication issue #40641 , with content loss handled as a separate issue/pr,
or they should be addressed together in this same pr?

avatar Fedik
Fedik - comment - 13 Apr 2026

You can make both fixes here. But add to the PR description so people know what to test.

For joomla 6 will be need additional PR, there is a different version of Codemirror without editor.save();

avatar adarshdubey03 adarshdubey03 - change - 13 Apr 2026
The description was changed
avatar adarshdubey03 adarshdubey03 - edited - 13 Apr 2026
avatar adarshdubey03
adarshdubey03 - comment - 13 Apr 2026

@Fedik I have updated the pr with both the fixes now, and i have also updated the pr description to reflect the new changes.

avatar Fedik
Fedik - comment - 13 Apr 2026

I think it can be tested now.

avatar richard67
richard67 - comment - 13 Apr 2026

@Fedik System tests are failing.

I think it can be tested now.

@Fedik System tests are failing. Not sure if it’s related.

avatar Fedik
Fedik - comment - 13 Apr 2026

System tests are failing.

I looked, it is something about the Update check.
Not relay related to current PR.

avatar richard67
richard67 - comment - 13 Apr 2026

System tests are failing.

I looked, it is something about the Update check. Not relay related to current PR.

Ok, I will restart the tests, maybe that helps.

avatar exlemor exlemor - test_item - 27 Apr 2026 - Tested successfully
avatar exlemor
exlemor - comment - 27 Apr 2026

I have tested this item βœ… successfully on 460e964

I was able to test this successfully. Thanks @adarshdubey03!

For other testers, make sure you Disable Automated Updates if you are installing Joomla 5.4.4 to test this PR via the Download Package Update.zip, otherwise your installation will instantly update to 5.4.5 and you won't be able to test this PR...


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/47548.

avatar exlemor
exlemor - comment - 27 Apr 2026

I have tested this item βœ… successfully on 460e964

I was able to test this successfully. Thanks @adarshdubey03!

For other testers, make sure you Disable Automated Updates if you are installing Joomla 5.4.4 to test this PR via the Download Package Update.zip, otherwise your installation will instantly update to 5.4.5 and you won't be able to test this PR...


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/47548.

Add a Comment

Login with GitHub to post a comment