Site-Sets are killing me (Dependency Ordering Hell)

I have a theme-package, that supports both a fluid rendering stack and a headless rendering stack. I started adding site-settings based features and wanted to add full support for site settings to make things less complicated. But now i am much more confused than ever before. My problem is, that is seems impossible to enforce a given order just with site sets.

I declare my set to depend on typo3/fluid-styled-content AND friendsoftypo3/headless and it will not work because typo3 includes fsc after headless. When i add a intermediate meta-set, that only requires typo3/fluid-styled-content and have that as requirement besides friendsoftypo3/headless, it is shown correctly in the backend (active typoscript) but the frontend is still not working.

How do you solve this? The only answer the LLM could find, was to modify the third-party code

I don’t have an obvious solution to your case, but it is also killing me :wink:

I found that moving 100% to site sets is the sanest approach. With anything loaded from ext_localconf.php or (god beware) from the DB you cannot get into the Site Set Stack where you might need it. That is hard in practice where some extensions don’t use Site Sets yet (which means I make a wrapper for them to load them as Site Set). (And if 3rd party extensions load something themselves in ext_localconf.php, it gets insane).

And then add a dependency from every place where you overwrite something in a Site Set to the original place. And don’t include that original place somewhere else…

I opened up a issue: Feature #111468: Provide a way to shim site-set dependency resolution - TYPO3 Core - TYPO3 Forge

I’ll try overloading the service class and come back to tell you how it went.

Here is what i did to solve this without losing my mind:

Be aware, that this pattern should not be used at all - its only a last-resort option, do not use this, if an api solution is possible!

1: Replace the SetRegistry with a ShimmedSetRegistry

class ShimmedSetRegistry extends SetRegistry
{
    public function computeOrderedSets(): array
    {
        $this->dependencyOrderingService = new ShimmedDependencyOrderingService(function(array $items): array {
            foreach ($items as $setName => &$dependencyData) {
                if (in_array($setName, [
                        "friendsoftypo3/headless",
                        "friendsoftypo3/headless-mixed",
                        "itplusx/headless-container",
                    ], true) && !in_array('typo3/fluid-styled-content', $dependencyData['after'])) {
                    $dependencyData['after'][] = 'typo3/fluid-styled-content';
                }
            }
            return $items;
        });
        return parent::computeOrderedSets();
    }
}

2: The ShimmedDependencyOrderingService does not much:

final readonly class ShimmedDependencyOrderingService extends DependencyOrderingService
{
    public function __construct(
        private Closure $callback
    ) { }

    public function orderByDependencies(array $items, $beforeKey = 'before', $afterKey = 'after'): array
    {
        return parent::orderByDependencies($this->callback->__invoke($items), $beforeKey, $afterKey);
    }
}

Its not a generic or nice solution, because of that i opened the issue in forge.
Maybe this helps save some frustration

Then you can have a very deterministic dependency-chain and have third-party sets processed at a given position…