Review main Abandoned

86819[WIP][TASK] React on FormEngine mutations after initalization

Andreas Kienast CR -2 V -1 Normal +58 −55 updated 03/11/26, 16:25

Commit message

This commit installs a new `MutationObserver` that detects fields that
are added or removed in FormEngine after the initial validation took
place. This makes manual validation of added fields finally obsolete and
eliminates one common ground for issues.

Mutations may be triggered very fast in a sequential manner, therefore
validation is _requested_ by calling the new method
`requestValidation()`. This will dispatch the debounced event
`typo3:formengine:request-validation`, avoiding spamming the form
validation several times in potentially outdated form states.

Review

  • Code review CR -2
    • Andreas Kienast -2
  • Verified V -1
    • core-ci -1 CI

Issues 1

Files 12

Review log 5175

Show 3350 earlier messages
  1. Andreas Kienast uploaded patch set 1 10/29/24, 09:23

  2. Andreas Kienast uploaded patch set 2 10/29/24, 09:24

  3. Andreas Kienast uploaded patch set 3 10/29/24, 09:25

  4. core-ci voted on patch set 3 V +1 10/29/24, 09:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68772

  5. Andreas Kienast uploaded patch set 4 V +1 10/29/24, 09:54

  6. core-ci voted on patch set 4 V +1 10/29/24, 10:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68774

  7. Andreas Kienast uploaded patch set 5 V +1 10/29/24, 10:00

  8. core-ci voted on patch set 5 V +1 10/29/24, 10:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68775

  9. Garvin Hicking voted on patch set 5 CR +1 V +1 10/29/24, 10:37

  10. Andreas Kienast commented on patch set 5 CR -1 10/29/24, 10:43

    form-engine-validation.ts:92

    Will revert this back to an inner loop. Using `.filter()` builds me a nice array, but may invoke more DOM operations than necessary -> potential performance penalty.
  11. Andreas Kienast uploaded patch set 6 CR +1 V +1 10/29/24, 10:44

  12. Andreas Kienast commented on patch set 6 10/29/24, 10:44

    form-engine-validation.ts:92 Reply

    Done
  13. Andreas Kienast uploaded patch set 7 10/29/24, 10:49

  14. core-ci voted on patch set 6 V -1 10/29/24, 10:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68776

  15. core-ci voted on patch set 7 V +1 10/29/24, 10:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68777

  16. Garvin Hicking voted on patch set 7 CR +1 V +1 10/29/24, 11:16

  17. Andreas Kienast uploaded patch set 8 CR +1 V +1 10/30/24, 09:01

  18. core-ci voted on patch set 8 V +1 10/30/24, 09:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68833

  19. Garvin Hicking voted on patch set 8 CR +1 V +1 10/30/24, 09:22

  20. Benjamin Franzke commented on patch set 8 CR -1 10/30/24, 10:19

    I think we should fix the issue in our CKEditor5 itself first (and backport to 12.4), then this `MutationObserver` refactoring (which I'm not against for *real* dynamic cases) is only needed for v14 (maybe v13 if you like). Please see: > https://review.typo3.org/c/Packages/TYPO3.CMS/+/86834 [BUGFIX] Prevent RTE CKEditor5 initialization race condition
  21. Andreas Kienast updated the commit message in patch set 9 CR +1 V +1 10/30/24, 11:33

  22. Andreas Kienast commented on patch set 9 CR -2 10/30/24, 11:33

  23. core-ci voted on patch set 9 V +1 10/30/24, 11:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68846

  24. Andreas Kienast uploaded patch set 10 V +1 10/31/24, 11:27

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  25. Andreas Kienast voted on patch set 10 CR 0 10/31/24, 11:27

  26. core-ci voted on patch set 10 V +1 10/31/24, 11:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68911

  27. Benjamin Franzke commented on patch set 10 11/04/24, 15:28

    files-control-container.ts:381

    Hm, can the same mutation observer actually be moved into `FormEngine` (or at least used for `FormEngineValidation.initializeInputFields`) as well?
  28. Andreas Kienast uploaded patch set 11 V +1 11/06/24, 08:53

  29. Andreas Kienast commented on patch set 10 11/06/24, 08:53

    files-control-container.ts:381 Reply

    Done
  30. Andreas Kienast uploaded patch set 12 11/06/24, 08:54

  31. core-ci voted on patch set 12 V -1 11/06/24, 09:02 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69139

  32. core-ci voted on patch set 11 V -1 11/06/24, 09:16 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69138

  33. Andreas Kienast uploaded patch set 13 V -1 11/06/24, 09:54

  34. core-ci voted on patch set 13 V +1 11/06/24, 10:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69141

  35. Andreas Kienast uploaded patch set 14 V +1 12/05/24, 15:13

  36. core-ci voted on patch set 14 V +1 12/05/24, 15:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70664

  37. Andreas Kienast commented on patch set 14 CR -1 12/05/24, 15:33

    I want to check some performance matters regarding the consecutive call to `.validate()`.
  38. Andreas Kienast uploaded patch set 15 CR -1 V +1 12/06/24, 08:51

  39. core-ci voted on patch set 15 V +1 12/06/24, 08:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70695

  40. Andreas Kienast commented on patch set 15 12/06/24, 09:30

    Reply

    Done
  41. Garvin Hicking uploaded patch set 16 V +1 12/11/24, 09:03

    Fix merge conflict
  42. core-ci voted on patch set 16 V +1 12/11/24, 09:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70902

  43. Garvin Hicking commented on patch set 16 CR +1 V +1 12/11/24, 10:11

    Tested this and tried to break it for an hour (in several formengine contexts, with large and small datasets, with and without irre, dynamically injecting DOM); works quite well dynamically for me. Tested on macOS, Chromium 131.0.6778.108 and Firefox 132.0.2
  44. Andreas Kienast uploaded patch set 17 CR +1 V +1 12/11/24, 10:14

  45. core-ci voted on patch set 17 V +1 12/11/24, 10:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70910

  46. Andreas Kienast uploaded patch set 18 V +1 12/11/24, 10:34

  47. core-ci voted on patch set 18 V +1 12/11/24, 10:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70912

  48. Garvin Hicking voted on patch set 18 CR +1 V +1 12/11/24, 10:56

  49. Andreas Kienast uploaded patch set 19 CR +1 V +1 12/20/24, 10:14

  50. core-ci voted on patch set 19 V +1 12/20/24, 10:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71502

  1. Garvin Hicking voted on patch set 19 CR +1 V +1 12/20/24, 10:33

  2. Garvin Hicking wrote 01/13/25, 09:24

    Topic set to FormEngine
  3. Andreas Kienast uploaded patch set 20 CR +1 V +1 01/15/25, 08:17

  4. core-ci voted on patch set 20 V +1 01/15/25, 08:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72506

  5. Garvin Hicking voted on patch set 20 CR +1 V +1 01/15/25, 10:06

  6. Garvin Hicking commented on patch set 20 01/15/25, 12:04

    Note: I tested this again like this: 1. Pick a EXT:styleguide "Form Engine - required" element 2. Go to tab "Inline", "inline_2" for example 3. Create a new inline child 4. Use DOM inspector to figure out the wrapping ID of the child 5. Use Browser console to manipulate DOM and manually attaching a new child, insert the ID above as selector: ``` // IRRE selector = 'data-3308-tx_styleguide_required-8-inline_2-tx_styleguide_required_inline_2_child-NEW67879be37c556519338462_fields'; oldElement = document.getElementById(selector); newElement = oldElement.cloneNode(true); newElement.id = selector + (BigInt(Date.now()) * 1000n + BigInt(Math.floor(performance.now() * 1000))).toString(); oldElement.parentNode.insertBefore(newElement, oldElement.nextSibling); ``` 6. Verify the duplicated element reacts to validation / review engine Then did the same for a flatpickr field, and an RTE field: ``` // flatpickr // Cloning is painful, do it fresh. selector = 'formengine-input-67879f45cfdb8334220372'; newSelector = selector + (BigInt(Date.now()) * 1000n + BigInt(Math.floor(performance.now() * 1000))).toString(); oldElement = document.querySelector('[recordfieldid="' + selector + '"]'); newElement = oldElement.cloneNode(true); newElement.setAttribute('recordfieldid', newSelector); newElement.innerHTML = ` <div class="form-control-wrap" style="max-width: 204px"> <div class="form-wizards-wrap"> <div class="form-wizards-item-element"> <div class="input-group"> <input type="text" id="${newSelector}" class="form-control form-control-clearable t3js-clearable" data-input-type="datetimepicker" data-date-type="date" data-formengine-validation-rules="[{&quot;type&quot;:&quot;required&quot;}]" data-formengine-input-params="{&quot;field&quot;:&quot;data[tx_styleguide_required][8][input_2]&quot;,&quot;evalList&quot;:&quot;date&quot;}" data-formengine-input-name="data[tx_styleguide_required][8][input_2]"/> <input type="hidden" name="data[tx_styleguide_required][8][input_2]" value="2024-12-31T00:00:00+00:00"/> <button class="btn btn-default" aria-label="Open date picker" type="button" data-global-event="click" data-action-focus="#${newSelector}"> <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-edit-pick-date" data-identifier="actions-edit-pick-date" aria-hidden="true"> <span class="icon-markup"> <svg class="icon-color"><use xlink:href="/_assets/1ee1d3e909b58d32e30dcea666dd3224/Icons/T3Icons/sprites/actions.svg#actions-calendar-alternative"/></svg> </span> </span> </button> </div> </div> </div> </div>`; oldElement.parentNode.insertBefore(newElement, oldElement.nextSibling); ``` ``` // RTE selector = 'data_tx_styleguide_required__8__rte_1_ckeditor5'; oldElement = document.getElementById(selector); newElement = oldElement.cloneNode(true); newElement.id = selector + (BigInt(Date.now()) * 1000n + BigInt(Math.floor(performance.now() * 1000))).toString(); oldElement.parentNode.insertBefore(newElement, oldElement.nextSibling); ``` In all cases the mutation event took care to propagate the new DOM elements to the validation and its review block.
  7. Garvin Hicking rebased onto patch set 21 CR +1 V +1 01/15/25, 12:29

  8. Garvin Hicking commented on patch set 21 CR +1 V +1 01/15/25, 12:31

    sorry, inadvertant creation of a relation chain due to cherry-picking messup on my side
  9. core-ci voted on patch set 21 V +1 01/15/25, 12:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72516

  10. Andreas Kienast uploaded patch set 22 CR +1 V +1 01/16/25, 09:09

  11. core-ci voted on patch set 22 V +1 01/16/25, 09:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72551

  12. Garvin Hicking voted on patch set 22 CR +1 V +1 01/16/25, 10:08

  13. Andreas Kienast uploaded patch set 23 CR +1 V +1 02/20/25, 15:55

  14. core-ci voted on patch set 23 V +1 02/20/25, 16:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/74471

  15. Garvin Hicking voted on patch set 23 CR +1 V +1 02/20/25, 16:10

  16. Oliver Hader commented on patch set 23 02/21/25, 11:05

    form-engine.ts:681

    I guess there might be scenarios, when handling these DOM mutations, would cause new DOM mutations - and thus, probably unexpected loops. For instance, `FormEngine.reinitialize()` might invoke `HTMLInputElement.prototype.clearable` (in `@typo3/backend/input/clearable`), which seems to modify the DOM that is observed.
  17. Andreas Kienast uploaded patch set 24 CR +1 V +1 04/01/25, 12:26

  18. Andreas Kienast commented on patch set 24 04/01/25, 12:27

    form-engine.ts:681 Reply Unresolved

    I agree. Do you have an idea how this may be circumvented?
  19. core-ci voted on patch set 24 V +1 04/01/25, 12:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76778

  20. Andreas Kienast uploaded patch set 25 V +1 07/15/25, 10:31

  21. core-ci voted on patch set 25 V +1 07/15/25, 10:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81735

  22. Andreas Kienast commented on patch set 25 CR -2 07/15/25, 10:53

    form-engine.ts:664 Unresolved

    This will still cause issues as mentioned by Olly.
  23. Andreas Kienast uploaded patch set 26 V +1 07/17/25, 08:10

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  24. core-ci voted on patch set 26 V -1 07/17/25, 08:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81817

  25. Andreas Kienast abandoned the change 03/11/26, 16:25

    Not planning to work on this soon.