Bug #87402
closed
Feature-79409 renderAssetsForRequest does not work for USER_INT/uncached
Added by Peter Niederlag almost 6 years ago.
Updated almost 5 years ago.
Category:
Content Rendering
Description
<f:section name="HeaderAssets">
<script>console.log('Section HeaderAssets was rendered');</script>
<f:debug>I am always triggered however</f:debug>
</f:section>
Does NOT work for uncached Plugin on first hit/cold cache! the debug message is triggered but the script call is not inserted in the rendered html.
However it is working on subseqent calls.
- Related to Feature #79409: Render sections HeaderAssets and FooterAssets automatically from ActionController and attach to PageRenderer added
TYPO3\CMS\Extbase\Mvc\Controller\ActionController->renderAssetsForRequest fetches an instance of TYPO3\CMS\Core\Page\PageRenderer from TYPO3\CMS\Extbase\Object\ObjectManager. In ObjectManager these instances get cached. When rendering uncached elements, the singleton instance in GeneralUtility's cache gets replaced (TSFE->INTincScript calls GeneralUtility::setSingletonInstance). So chances are, that you get the "wrong" instance, when fetching a PageRenderer from ObjectManager.
Reproducible example:
There are two Content Elements on a page, element 1 is cached and element 2 is uncached. Both elements access the PageRenderer fetched from ObjectManager (which is always done for extbase Plugins in TYPO3\CMS\Extbase\Mvc\Controller\ActionController->renderAssetsForRequest).
- The PageRenderer instance gets cached inside ObjectManager when rendering Element 1.
- Before rendering Element 2, TSFE replaces the instance in INTincScript.
- When rendering Element 2, ObjectManager returns the original (not the replacement) instance.
Therefore anything added to the PageRenderer in Element 2, e.g. through addHeaderData(), doesn't make it on the rendered page.
Solutions include:
- One solution to this, would be to not cache PageRenderer instances inside ObjectManager (as in https://review.typo3.org/c/Packages/TYPO3.CMS/+/60943).
- For this specific issue, it would also work to make ActionController->renderAssetsForRequest fetch the PageRenderer directly form core's GeneralUtility instead of extbase's ObjectManager. But there might be other uses of PageGenerator in extbase plugins that would still be affected.
- One could also ask, what the purpose of caching SingletonInterface instances in extbase's ObjectManager is? Since those get cached by GeneralUtility too. It would maybe be cleaner to delegate the caching of instances implementing SingletonInterface completely to GeneralUtility.
- As Alexander Schnitzler mentioned, removing the usage of GeneralUtility::setSingletonInstance in TSFE would also work, but to me that seems to be the most intrusive solution. I have no clue what it's there for.
- Status changed from New to Under Review
- Related to Bug #89445: FooterAsset are not loaded added
- Status changed from Under Review to Resolved
The issue was fixed with #89445
- Status changed from Resolved to Closed
- Related to Bug #91316: MetaTagManagerRegistry instance not unique in uncached plugins added
Also available in: Atom
PDF