Review main Merged

86723[BUGFIX] Make `GridEditor.writeConfig` update content area as intended

Ayke Halder CR +2 V +2 Normal +58 −60 updated 12/13/24, 14:23

Commit message

This fixes `GridEditor.writeConfig` to update the content area as
intended.

Before the code used an `undefined` property:
`codemirror.editorView.viewState.state.doc.length`

Correct is:
`codemirror.editorView.state.doc.length`

As a separate change made "t3-editor" part of the backend, the function
`CodeMirrorElement.setContent` is used, instead of fixing the issue.
Thereby the code is de-duplicated.

As LitElement `Ref`-objects are in use, first there is a check for
instantiation of the `Ref.value` to see if the actual object is
ready-to-use.

This also implements proper type-hints:

```
const codemirror: CodeMirrorElement | undefined = this.codeMirrorRef.value;
```

Instead of:

```
const codemirror: any = this.codeMirrorRef.value!;
```

Also this fixes web-test-runner import-map to correctly resolve scripts
in `backend/Resources/Public/JavaScript/Contrib`.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Andreas Kienast +1
  • Verified V +2 Done
    • Benni Mack +2
    • Andreas Kienast +1
    • core-ci +1 CI

Issues 2

Files 3

Review log 1826

Show 1 earlier messages
  1. Ayke Halder uploaded patch set 1 10/23/24, 20:46

  1. core-ci voted on patch set 1 V -1 10/23/24, 20:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68486

  2. Ayke Halder uploaded patch set 2 V -1 10/23/24, 21:22

  3. core-ci voted on patch set 2 V +1 10/23/24, 21:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68487

  4. Ayke Halder uploaded patch set 3 V +1 10/23/24, 22:09

  5. core-ci voted on patch set 3 V +1 10/23/24, 22:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68488

  6. Andreas Kienast commented on patch set 3 11/15/24, 10:59

    grid-editor.ts:466

    This can be shortened to `previewArea?.value`.

    grid-editor.ts:472

    What kind of syntax is this?
  7. Andreas Kienast commented on patch set 3 11/15/24, 11:00

    grid-editor.ts:472 Reply

    Do I understand this correctly, that `codemirror.setContent` might be undefined? When is this the case?
  8. Ayke Halder commented on patch set 3 11/15/24, 13:45

    grid-editor.ts:466 Reply

    IMO this can not be shortened. ``` previewArea.value = ''; if (previewArea && previewArea.value !== undefined) { /* This IS executed. */ } if (previewArea?.value) { /* This is NOT executed. */ } ```

    grid-editor.ts:472 Reply

    Yup, `setContent` might not exist until the object, which the reference points to, becomes properly initialized. We might instead implement some other check to ensure that `coedmirror` is really a properly initialized and fully working `CodeMirroElement`-object. Technically this is somehow about how `Ref` works - also see commit message: > As LitElement `Ref`-objects are in use, first there is a check for > initialization of the `Ref.value` and then an extra check if the > property/function of the actual object is ready-to-use.
  9. Andreas Kienast commented on patch set 3 11/18/24, 09:57

    grid-editor.ts:466 Reply

    I think you misunderstood me. My remark was related to the condition branch I've marked, not the whole condition. `if (previewArea?.value !== undefined) {` has IMO the same effect, `?.` evaluates to `undefined` if `previewArea` is not available.
  10. Ayke Halder uploaded patch set 4 V +1 11/18/24, 11:04

  11. core-ci voted on patch set 4 V -1 11/18/24, 11:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69588

  12. Ayke Halder uploaded patch set 5 V -1 11/18/24, 11:20

  13. core-ci voted on patch set 5 V -1 11/18/24, 11:27 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69589

  14. Ayke Halder uploaded patch set 6 V -1 11/18/24, 12:55

  15. core-ci voted on patch set 6 V -1 11/18/24, 13:01 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69593

  16. Ayke Halder uploaded patch set 7 V -1 11/18/24, 17:24

  17. core-ci voted on patch set 7 V -1 11/18/24, 17:31 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69613

  18. Ayke Halder uploaded patch set 8 V -1 11/18/24, 20:14

  19. core-ci voted on patch set 8 V +1 11/18/24, 20:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69623

  20. Ayke Halder commented on patch set 8 11/18/24, 20:32

    grid-editor.ts:466 Reply

    Thanks, now I see. Your point is valid! But I implemented a check using `instanceof` now.

    grid-editor.ts:472 Reply

    I implemented a proper check for the `Ref.value`-construct now: ```js const codemirror: CodeMirrorElement | undefined = this.codeMirrorRef.value; if (codemirror instanceof CodeMirrorElement) { codemirror.setContent(content); } . ``` My implementation before worked, but did not show the intention: ```js const codemirror: CodeMirrorElement | undefined = this.codeMirrorRef.value; codemirror?.setContent?(content); . ``` ---- Just for completeness, **the following code does not work**: See patchset 5 https://review.typo3.org/c/Packages/TYPO3.CMS/+/86723/5 ```js const codemirror: CodeMirrorElement | undefined = this.codeMirrorRef.value; if (codemirror) { codemirror.setContent(content); } . ``` ``` 1) ElementsBasicInputSimpleCest: Simple input fields | "input_1","This is a demo text","This is a demo text","This is a demo text","This is a demo text","" Test Acceptance/Application/FormEngine/ElementsBasicInputSimpleCest.php:simpleInputFields Found following JavaScript errors in the browser console: 11:23:55.554 SEVERE - http://web/_assets/081fa96a07de1dccb64a8a83e1567439/JavaScript/grid-editor.js?bust=82b918eaa2754c05b9ef3bb302d2fbd62938c405 122:429 Uncaught TypeError: i.setContent is not a function . ```
  21. Ayke Halder commented on patch set 8 11/18/24, 20:35

    This also fixes web-test-runner import-map paths, as otherwise the tests fail. See patchset 6: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86723/6 ``` Sources/TypeScript/backend/tests/grid-editor-test.ts: 🚧 Browser logs: TypeError: Failed to fetch dynamically imported module: http://localhost:8000/Build/Sources/TypeScript/backend/tests/grid-editor-test.ts?wtr-session-id=z-gGdUtIfXE8hWzy3-YBi&wds-import-map=0&wds-import-map=0 ❌ Could not import your test module. Check the browser logs or open the browser in debug mode for more information. . ```
  22. Andreas Kienast voted on patch set 8 CR +1 V +1 12/11/24, 09:24

  23. Benni Mack voted on patch set 8 CR +1 V +1 12/13/24, 13:58

  24. Benni Mack voted on patch set 8 CR +2 V +2 12/13/24, 14:23

  25. Benni Mack merged patch set 9 12/13/24, 14:23