Review main Merged

79912[TASK] Render JavaScript modules as script tag if possible

Benjamin Franzke CR +2 V +2 Normal +150 −30 updated 03/26/25, 17:52

Commit message

With the removal of es-module-shims in #101372 it is possible[1]
to add a fastpath for JavaScript modules that do not require
initializer methods to be called.

The fastpath is activated for modules that match the mentioned
requirements, in order to avoid mixing explicit module script
tags and @typo3/core/java-script-item-handler.js invocations.

This allows the browser to load the set of modules from the list
of <script type="module"> tags while global configuration is written
as plain JSON and the intermediate module java-script-item-handler.js
is delayed (or skipped if possible).

Note that `litNonce` is migrated to use global assignment
infrastructure to be guaranteed to be rendered after the importmap
in order to prevent occasional false-positive errors in Firefox 115
> Uncaught TypeError: The specifier "@typo3/backend/modal.js" was
> a bare specifier, but was not remapped to anything.
(The backend and all actions would have worked, as all scripts are
loaded despite of these errors, but javascript console would be
flooded with these message. This is fixed in Firefox 116 and
was triggered because `<script type="importmap">` has not
been placed as first `<script>` element on the page.)

[1] we do not longer need to care about missing support for
    `import()` expressions in `<script type="module" src="…">`
    tags, which were only supported via a fail-first algorithm
    in es-module-shims, and have therefore not been used back then

Review

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

Issues 2

Files 5

Review log 5379

Show 3454 earlier messages
  1. Benjamin Franzke uploaded patch set 1 07/10/23, 04:56

  2. core-ci voted on patch set 1 V -1 07/10/23, 05:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43962

  3. Benjamin Franzke uploaded patch set 2 V -1 07/10/23, 07:03

  4. core-ci voted on patch set 2 V -1 07/10/23, 07:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43969

  5. Benjamin Franzke uploaded patch set 3 V -1 07/10/23, 08:01

  6. core-ci voted on patch set 3 V +1 07/10/23, 08:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43971

  7. Benjamin Franzke marked it work in progress 07/10/23, 08:10

  8. Benjamin Franzke uploaded patch set 4 V +1 07/26/23, 10:35

  9. core-ci voted on patch set 4 V -1 07/26/23, 10:43 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44573

  10. Benjamin Franzke uploaded patch set 5 V -1 07/26/23, 11:24

  11. core-ci voted on patch set 5 V +1 07/26/23, 11:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44577

  12. Benjamin Franzke rebased onto patch set 6 V +1 07/28/23, 07:29

  13. core-ci voted on patch set 6 V +1 07/28/23, 07:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44650

  14. Oliver Hader commented on patch set 6 07/28/23, 18:37

    `window.litNonce` might be used in frontend as well (or might have been "misused", for other JavaScript components other than lit-elements)...
  15. Benjamin Franzke commented on patch set 6 07/28/23, 19:16

    Reply

    yes, which is why is now automagically added, whenever EXT:core importmap is loaded. The idea was: If lit is used in frontend, then the litNonce will be automatically emitted, without having to call `applyNonceHint` (although I noticed – after writing this patch – that we could actually get rid of litNonce, as lit itself doesn't need litNonce any longer for modern browsers, since firefox 101 supports constructable stylesheets. but that requires more work on our side, since we began to use litNonce ourselves for other cases).
  16. Benjamin Franzke uploaded patch set 7 V +1 07/28/23, 19:52

  17. Benjamin Franzke commented on patch set 7 07/28/23, 19:54

    Reply

    Dropped the automagic and kept it in PageRenderer, but swapped the order to fix firefox false positive errors. I'm actually quite happy if litNonce is not applied in frontend, given that I recognized, that one wouldn't want it to be defined, if only modern browsers are targeted.
  18. core-ci voted on patch set 7 V +1 07/28/23, 20:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44699

  19. Oliver Hader commented on patch set 7 CR +1 07/28/23, 20:35

    JavaScriptRenderer.php:94

    Might this signature change probably be breaking?
  20. Benjamin Franzke uploaded patch set 8 CR +1 V +1 07/29/23, 06:39

  21. Benjamin Franzke commented on patch set 8 07/29/23, 06:40

    JavaScriptRenderer.php:94 Reply

    Ack, didn't take into account that JavaScriptRenderer isn't internal. Adapted the signature to be non-breaking.
  22. core-ci voted on patch set 8 V -1 07/29/23, 06:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44708

  23. Benjamin Franzke uploaded patch set 9 V -1 07/29/23, 15:44

  24. core-ci voted on patch set 9 V +1 07/29/23, 15:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44737

  25. Benjamin Franzke uploaded patch set 10 V +1 07/29/23, 17:53

  26. core-ci voted on patch set 10 V +1 07/29/23, 18:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44738

  27. Christian Kuhn commented on patch set 10 07/31/23, 09:46

    PageRenderer.php:1497

    and ?
  28. Benjamin Franzke uploaded patch set 11 V +1 08/02/23, 06:41

  29. Benjamin Franzke commented on patch set 11 08/02/23, 06:41

    PageRenderer.php:1497 Reply

    Right, thx. Has been copied 1:1 from below – but I removed the stray "and" now.
  30. core-ci voted on patch set 11 V +1 08/02/23, 06:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44865

  31. Benni Mack commented on patch set 11 08/02/23, 09:03

    JavaScriptRenderer.php:165

    do we need the comment about the comment? :)
  32. Benjamin Franzke uploaded patch set 12 V +1 08/02/23, 10:16

  33. Benjamin Franzke commented on patch set 12 08/02/23, 10:16

    JavaScriptRenderer.php:165 Reply

    Thank you very much, good catch. I really suck at updating comments (did I mention I hate code that needs comments? 😊) This one needed to be moved to createItemHandlerElement. (And yes, in this case a comment is needed, but I expanded it a bit)
  34. core-ci voted on patch set 12 V +1 08/02/23, 10:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44871

  35. Benni Mack updated the commit message in patch set 13 V +1 08/07/23, 11:49

  36. core-ci voted on patch set 13 V +1 08/07/23, 11:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45188

  37. Benjamin Franzke uploaded patch set 14 V +1 11/29/23, 16:07

  38. core-ci voted on patch set 14 V -1 11/29/23, 16:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50128

  39. Benjamin Franzke uploaded patch set 15 V -1 11/30/23, 06:30

  40. core-ci voted on patch set 15 V +1 11/30/23, 06:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50147

  41. Benjamin Franzke uploaded patch set 16 11/30/23, 15:02

    Copied Votes: * Verified+1 (copy condition: "**changekind:NO_CHANGE**")
  42. core-ci voted on patch set 16 V +1 11/30/23, 15:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50172

  43. Benjamin Franzke rebased onto patch set 17 V +1 12/01/23, 16:06

  44. core-ci voted on patch set 17 V +1 12/01/23, 16:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50212

  45. Benjamin Franzke uploaded patch set 18 V +1 05/31/24, 10:57

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

  47. Benjamin Franzke uploaded patch set 19 V -1 05/31/24, 11:19

  48. core-ci voted on patch set 19 V +1 05/31/24, 11:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58531

  49. Benni Mack voted on patch set 19 CR +1 06/01/24, 21:27

  50. Andreas Kienast commented on patch set 19 06/06/24, 13:25

    JavaScriptItems.php:113

    I assume the foreach() is here to be in line with the `toArray()` method. Otherwise, I'd suggest an `array_map()` invocation: ``` return array_map(static fn (array $item) => [ 'type' => 'globalAssignment', 'payload' => $item, ], $this->globalAssignments); ```

    JavaScriptRenderer.php:108

    The condition is superfluous. If the array is empty, the inner foreach becomes a no-op.

    JavaScriptRenderer.php:150

    The null check can be removed as `->createScriptElement()` uses `GU::implodeAttributes()` which drops the empty elements. This would be in line with the foreach() in line 109.
  51. Benjamin Franzke uploaded patch set 20 CR +1 V +1 06/08/24, 07:17

  52. Benjamin Franzke commented on patch set 20 06/08/24, 07:17

    JavaScriptItems.php:113 Reply

    ack, it was copied from `toArray()`, but `array_map` is better in this case 👍. Done.

    JavaScriptRenderer.php:108 Reply

    Done

    JavaScriptRenderer.php:150 Reply

    Done
  53. core-ci voted on patch set 20 V -1 06/08/24, 07:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58907

  54. Benjamin Franzke uploaded patch set 21 V -1 06/10/24, 08:32

  1. core-ci voted on patch set 21 V +1 06/10/24, 08:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58982

  2. Andreas Kienast voted on patch set 21 CR +1 06/10/24, 12:35

  3. Andreas Kienast voted on patch set 21 V +1 06/11/24, 13:35

  4. Oliver Hader commented on patch set 21 CR -1 06/13/24, 10:13

    Feedback via Slack...
  5. Oliver Hader commented on patch set 21 06/13/24, 10:29

    JavaScriptRenderer.php:111

    ...
  6. Benjamin Franzke marked it work in progress 10/07/24, 09:45

  7. Benjamin Franzke uploaded patch set 22 CR +1 V +1 02/09/25, 01:53

  8. core-ci voted on patch set 22 V -1 02/09/25, 01:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73815

  9. Benjamin Franzke rebased onto patch set 23 V -1 02/09/25, 02:26

  10. core-ci voted on patch set 23 V +1 02/09/25, 02:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/73817

  11. Benjamin Franzke uploaded patch set 24 V +1 03/05/25, 09:48

  12. Benjamin Franzke commented on patch set 24 03/05/25, 09:48

    JavaScriptRenderer.php:111 Reply

    I initially left out any prototype pollution filter as we're using `Object.assign()` which is not affected by prototype polluting object copies when not combined with JSON.parse. Anyway it's still "ok" for me to add this layer of protection which is now implemented.
  13. core-ci voted on patch set 24 V +1 03/05/25, 09:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/75151

  14. Benjamin Franzke rebased onto patch set 25 V +1 03/24/25, 12:22

  15. core-ci voted on patch set 25 V +1 03/24/25, 12:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76148

  16. Andreas Kienast commented on patch set 25 V +1 03/24/25, 15:14

    JavaScriptRenderer.php:199

    Pardon my ignorance – why do we need this and why is it `window` only, compared to the unsets below?

    PageRenderer.php:1430

    Nice, `GeneralUtility::wrapJS()` can get deprecated then.
  17. Andreas Kienast commented on patch set 25 03/24/25, 15:14

    PageRenderer.php:1430 Reply

    Done
  18. Benjamin Franzke commented on patch set 25 03/24/25, 16:31

    JavaScriptRenderer.php:199 Reply

    because we assign to window (via `globalThis` in line 130 which is `window`) and want to allow e.g. `['window' => [ 'name' => 'typo3-backend' ] ]` (because our own code uses that and for BC reasons – we could of course refactor BackendController to avoid the unneded `window` prefix). Therefore we merge that one level up, as we – in general forbid any "too" global assignments (not for security reasons, but for reducing the chance of hard-to-debug side-effects) later on. Therefore `window.window.foo` is disallowed, but `window.foo` is allowed. I guess this deserves comments, although I'd love I could just make the code more self-explanatory.
  19. Benjamin Franzke uploaded patch set 26 V +1 03/25/25, 07:24

  20. Benjamin Franzke commented on patch set 26 03/25/25, 07:24

    JavaScriptRenderer.php:199 Reply

    Done
  21. core-ci voted on patch set 26 V +1 03/25/25, 07:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76211

  22. Andreas Kienast voted on patch set 26 CR +1 V +1 03/25/25, 08:20

  23. Benni Mack commented on patch set 26 CR +1 V +1 03/26/25, 14:09

    behaves just like before. Code is almost clear what it does to me.
  24. Benjamin Franzke voted on patch set 26 CR +2 V +2 03/26/25, 17:41

  25. Benjamin Franzke merged patch set 27 03/26/25, 17:52