Review main Merged

87224[BUGFIX] Fix missing version number of files from custom backend modules

Marco Kuprat CR +2 V +2 Normal +63 −15 updated 04/09/25, 21:11

Commit message

When using the asset renderer API, Backend assets did not
get cached-busted due to a "bug" in the calling order of
methods in AssetRenderer but also due to a misleading if()
statement if a already used /my-path/myfile.css was included
in BE.

This is now changed and documented properly.

The calling order should always be:

   # make a file reference completely absolute
   1. $file = GeneralUtility::getFileAbsFileName($file);

   # attach ?timestamp to filename
   2. $file = GeneralUtility::createVersionNumberedFilename($file);

   # make it ready for attaching in your HTML/JSON etc.
   3. $file = PathUtility::getAbsoluteWebPath($file);

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Garvin Hicking +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Benni Mack +2
    • Marco Kuprat +1
    • Garvin Hicking +1
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 4

Files 6

Review log 2835

Show 810 earlier messages
  1. Marco Kuprat uploaded patch set 1 11/25/24, 10:27

  2. core-ci voted on patch set 1 V +1 11/25/24, 10:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70127

  3. Simon Schaufelberger commented on patch set 1 11/25/24, 13:59

    This case should be covered by a functional test in my opinion
  4. Garvin Hicking commented on patch set 1 11/25/24, 16:42

    GeneralUtility.php:2020

    ```suggestion // workaround for files from custom backend modules ```
  5. Guido Schmechel commented on patch set 1 11/25/24, 17:56

    GeneralUtility.php:2022

    Can we perhaps use str_starts_with here?
  6. Marco Kuprat uploaded patch set 2 V +1 11/26/24, 06:57

  7. core-ci voted on patch set 2 V +1 11/26/24, 07:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70195

  8. Garvin Hicking commented on patch set 2 11/26/24, 07:07

    Thanks a lot for contributing this. I agree with Simon here, we definitely need tests/cases to verify and test this behavior. Would you be interested in checking out the existing test cases and see if you could add a test case for this, Marco?

    Reply

    I agree, it would be great to have a test securing the behavior because this is a quite central place. Thanks Marco for contributing this - would you be interested to add a test?

    GeneralUtility.php:2020 Reply

    Done

    GeneralUtility.php:2022 Reply

    Done
  9. Marco Kuprat commented on patch set 2 11/26/24, 08:15

    Reply

    Sure, got to get familiar with the testing framework first, tbh.

    Reply

    Of course, I will see that I can provide a test as soon as possible.
    I'll provide a test as soon as I'm familiar with the testing framework.

    GeneralUtility.php:2020 Reply

    Done

    GeneralUtility.php:2022 Reply

    Done
  10. Marco Kuprat uploaded patch set 3 V +1 11/26/24, 08:50

  1. Marco Kuprat commented on patch set 3 11/26/24, 08:53

    Reply

    Done

    Reply

    Done
    Functional test is added.
  2. Torben Hansen commented on patch set 3 CR -1 11/26/24, 08:56

    Having an additional file lookup construct in the try/catch block is a **workaround** as the comment in code describes, but IMO this is not a **solution** for the main problem. The problem here is the `PathUtility::isAbsolutePath($path)` evaluation in backend context. The function retrieves the relative path to the file with a starting slash. For frontend context (see condition in `createVersionNumberedFilename`), the starting slash is removed. For backend context however, the removal of the slash is only performed, when the `isAbsolutePath` evaluation is false (which is not the case here). Unit tests for `createVersionNumberedFilename` actually test the function with an **absolute path**, but I am currently not really sure, why the function at all distiguished between frontend and backend context and allows to return an **absolute path** in backend context with a versioned filename, which IMO makes no sence (e.g. `/var/www/website/public/typo3conf/ext/myext/Resources/Public/Css/styles.css`). I checked core usages for the function and we have it e.g. in `AbstractFormEngineAjaxController`, where the resolved **absolute path** is processed by `PathUtility::getAbsoluteWebPath` directly after usage resulting in the resolved path to the file being relative again. All other usages of the function are called in frontend context (e.g. `PageRenderer` or `ResourceViewHelper`) resulting in a relative path being returned. The functions doc comment also states, that the given parameter `$file` must be a **relative path**, so it is basically wrong to call it with an **absolute path**. I therefore think, we should change core usage here to always call the function with a relative filename. We can then remove the `$isFrontend` condition and as a bonus, we can also remove another `$GLOBALS['TYPO3_REQUEST']` usage in `GeneralUtility`.
  3. core-ci voted on patch set 3 V -1 11/26/24, 08:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70196

  4. Marco Kuprat commented on patch set 3 11/29/24, 07:50

    Reply

    I agree, it is not a solution for the root of the problem, but it is for the effects of the problem. That's why I commented it as "workaround", maybe better called "hotfix". However, IMO it may improve the workflow of a lot of people, as it solved the described problem in my case. A few lines above in the same method there is a comment which says "in v13 this should be resolved by using Environment::getPublicPath() only". So, I think my proposed workaround will be cancelled anyway, when that happens. Due to lack of time I can't dig deeper at the moment. So feel free to "throw away" my contribution. ;-)
  5. Benni Mack uploaded patch set 4 CR -1 V -1 04/09/25, 16:52

  6. Benni Mack commented on patch set 4 04/09/25, 16:53

    Hey Marco, just wanted to let you know that your previous work was the pointer for me to dig into this work. So it was valuable time. This patchset addresses the required changes in various places, and documents them. An updated test will follow ASAP.
  7. core-ci voted on patch set 4 V +1 04/09/25, 16:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77299

  8. Benni Mack uploaded patch set 5 V +1 04/09/25, 17:00

  9. Benni Mack commented on patch set 5 CR +1 V +1 04/09/25, 17:00

    Reply

    Done
  10. core-ci voted on patch set 5 V +1 04/09/25, 17:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77300

  11. Benni Mack uploaded patch set 6 CR +1 V +1 04/09/25, 17:15

  12. Benni Mack voted on patch set 6 CR +1 V +1 04/09/25, 17:15

  13. core-ci voted on patch set 6 V +1 04/09/25, 17:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77301

  14. Marco Kuprat commented on patch set 6 04/09/25, 17:32

    Reply

    Great, thanks a lot!
  15. Christian Kuhn voted on patch set 6 CR +1 V +1 04/09/25, 17:33

  16. Garvin Hicking commented on patch set 6 04/09/25, 17:44

    PageRenderer.php:1994

    remove this FE note now?
  17. Christian Kuhn uploaded patch set 7 CR +1 V +1 04/09/25, 17:52

  18. Christian Kuhn commented on patch set 6 CR +1 V +1 04/09/25, 17:52

    PageRenderer.php:1994 Reply

    Done
  19. Christian Kuhn voted on patch set 7 CR +1 V +1 04/09/25, 17:53

  20. core-ci voted on patch set 7 V +1 04/09/25, 18:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77304

  21. Garvin Hicking commented on patch set 7 CR +1 V +1 04/09/25, 18:11

    I would love for this to be a huge win in the asset processing (which it looks like to me), fingers crossed!
  22. Benni Mack voted on patch set 7 CR +2 04/09/25, 19:15

  23. Benni Mack voted on patch set 7 V +2 04/09/25, 19:15

  24. Benni Mack merged patch set 8 04/09/25, 19:15

  25. Marco Kuprat commented on patch set 8 V +1 04/09/25, 21:11

    Great job, looks good to me,