Review main Merged

90078[FEATURE] Introduce URL factory in TypeScript

Andreas Kienast CR +2 V +2 Hard +290 −0 updated 09/12/25, 09:12

Commit message

TYPO3 already uses the native `URL` and `URLSearchParams` objects when
working with URLs. To make the generation of said objects easier, the
module `@typo3/core/factory/url-factory.js` is introduced.

Review

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

Issues 1

Files 4

Review log 3345

Show 1420 earlier messages
  1. Andreas Kienast uploaded patch set 1 07/16/25, 13:29

  2. Andreas Kienast uploaded patch set 2 07/16/25, 13:30

  3. Andreas Kienast uploaded patch set 3 07/16/25, 13:32

  4. core-ci voted on patch set 1 V +1 07/16/25, 13:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81775

  5. Andreas Kienast commented on patch set 3 07/16/25, 13:38

    url-factory.ts:27

    This is bonkers...
  6. core-ci voted on patch set 2 V +1 07/16/25, 13:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81776

  7. core-ci voted on patch set 3 V +1 07/16/25, 13:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81777

  8. Benjamin Franzke commented on patch set 3 07/16/25, 13:57

    url-factory.ts:27 Reply

    What will be the consumer of this case? Why would we add arbitrary data structures (see any in method signature) to URLs? Smeels like somethign that should use `FormData` and non-GET requests.

    url-factory.ts:40

    should be `unknown` to make sure we are enforced to check/cast types
  9. Andreas Kienast uploaded patch set 4 V +1 07/16/25, 14:22

  10. Andreas Kienast commented on patch set 4 07/16/25, 14:24

    url-factory.ts:27 Reply

    This is a helper to allow feeding nested structures, which will be flattened to a query string. Please see the tests for an example case.

    url-factory.ts:40 Reply

    I tried and failed to get that method in a compilable state. Can you please assist here?
  11. Andreas Kienast commented on patch set 4 07/16/25, 14:29

    url-factory.ts:27 Reply

    Example: URLs to EditDocumentController Excerpt from file-list.ts ```js const url = new URL(top.TYPO3.settings.FormEngine.moduleUrl, window.location.origin); url.searchParams.set('edit[' + configuration.table + '][' + list.join(',') + ']', 'edit'); url.searchParams.set('returnUrl', Filelist.getReturnUrl(configuration.returnUrl || '')); ``` IMO this is rather counter-intuitive.
  12. core-ci voted on patch set 4 V +1 07/16/25, 14:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81782

  13. Andreas Kienast commented on patch set 4 07/17/25, 06:49

    url-factory.ts:40 Reply

    I can declare this to be `Record<string, string>`, which is fine for TS. However, to my understanding this does conflict with the check `typeof obj[currentValue] === 'object' && obj[currentValue] !== null` as this will never be the case, according to the types. What am I missing here?
  14. Benjamin Franzke uploaded patch set 5 V +1 07/17/25, 07:30

  15. Benjamin Franzke commented on patch set 5 07/17/25, 07:30

    url-factory.ts:40 Reply

    The problem was that `accumulator[objPrefix + currentValue + objSuffix] = obj[currentValue];` actually assigned non-strings (like undefined or null or number) to the object, without casting to a string. I've reworked the code to type via the reducer generic and simplified a bit.
  16. core-ci voted on patch set 5 V +1 07/17/25, 07:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81808

  17. Benjamin Franzke uploaded patch set 6 V +1 07/17/25, 08:15

  18. Benjamin Franzke commented on patch set 6 07/17/25, 08:15

    url-factory.ts:14

    This type does not reflect the nested object case that is used in the generator test… Can be verified by changing the test to ``` function* queryArgumentsDataProvider(): Generator<[string, URLSearchParamsFeedable, string]> { ```
  19. core-ci voted on patch set 6 V +1 07/17/25, 08:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81819

  20. Benjamin Franzke uploaded patch set 7 V +1 07/17/25, 09:03

  1. Benjamin Franzke commented on patch set 7 07/17/25, 09:03

    url-factory.ts:27 Reply

    ok, fine by me.
  2. core-ci voted on patch set 7 V +1 07/17/25, 09:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81824

  3. Andreas Kienast uploaded patch set 8 V +1 07/17/25, 12:17

  4. core-ci voted on patch set 8 V +1 07/17/25, 15:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81849

  5. Simon Schaufelberger voted on patch set 8 CR +1 07/17/25, 15:32

  6. Andreas Kienast uploaded patch set 9 CR +1 V +1 07/18/25, 12:54

  7. core-ci voted on patch set 9 V +1 07/18/25, 13:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81934

  8. Andreas Nedbal voted on patch set 9 CR +1 V +1 07/18/25, 14:30

  9. Simon Schaufelberger voted on patch set 9 CR +1 V +1 07/18/25, 15:23

  10. Andreas Kienast commented on patch set 9 CR -1 07/21/25, 07:21

    The code currently doesn't handle query argument _replacement_, which is rather hard to solve as the API doesn't know the user's intent. Examples: Input: `/typo3/record/edit?edit[pages][1290]=edit` Parameters: `{ edit: { pages: { 1280: 'foo' } } }` Result: `/typo3/record/edit?edit[pages][1290]=edit&edit[pages][1280]=foo` This one is arguably correct Input: `/typo3/record/edit?edit[pages][1290]=edit` Parameters: `{ edit: 'foo' }` Result: `/typo3/record/edit?edit[pages][1290]=edit&edit=foo` This one obviously bonkers.
  11. Benjamin Franzke commented on patch set 9 07/24/25, 14:40

    url-factory.ts:35

    Btw, we already have similar API: ``` import { InputTransformer } from '@typo3/core/ajax/input-transformer'; InputTransformer.toSearchParams({foo: { bar: 'baz' }}) ``` Feels wrong to implement this multiple times. Should we deprecate `@typo3/core/ajax/input-transformer` (or at least base it on this implementation?)
  12. Andreas Kienast commented on patch set 9 07/24/25, 14:54

    url-factory.ts:35 Reply

    I know, I built this API ;). When this patch is in, I'll happily rewrite parts of the AJAX implementation that removes the old code.
  13. Andreas Kienast commented on patch set 9 08/05/25, 12:02

    Reply

    This is pretty tough to handle right now as the URLSearchParams and FormData APIs are limited in that area. Needs to be handled later.

    url-factory.ts:35 Reply

    Done
  14. Andreas Kienast uploaded patch set 10 CR +1 V +1 08/05/25, 12:07

  15. core-ci voted on patch set 10 V +1 08/05/25, 12:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82804

  16. Andreas Kienast rebased onto patch set 11 V +1 09/11/25, 07:53

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

  18. Simon Schaufelberger voted on patch set 11 CR +1 V +1 09/11/25, 08:40

  19. Benjamin Franzke commented on patch set 11 CR +1 V +1 09/12/25, 07:41

    url-factory.ts:35 Reply

    Ok, I would have preferred to see it replaced directly, but I try to respect that we work differently 😜
  20. Andreas Kienast uploaded patch set 12 CR +1 V +1 09/12/25, 07:46

  21. Benjamin Franzke voted on patch set 12 CR +1 V +1 09/12/25, 07:46

  22. core-ci voted on patch set 12 V +1 09/12/25, 07:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/84886

  23. Georg Ringer voted on patch set 12 CR +1 V +1 09/12/25, 09:07

  24. Andreas Kienast voted on patch set 12 CR +2 V +2 09/12/25, 09:12

  25. Andreas Kienast merged patch set 13 09/12/25, 09:12