Problem/Motivation
Currently, the Shortcode module does not provide a way for shortcode plugins to expose cacheable metadata such as cache contexts, cache tags, or max-age.
This leads to rendered content not varying properly by user, language, or other contexts when a shortcode output depends on them.
This can cause incorrect content to be served from cache, especially on multilingual or user-specific pages.
Steps to reproduce
Create a shortcode plugin that outputs user-specific or language-specific content.
Place the shortcode in a node body and view the page as an anonymous user.
Log in as a different user or switch languages.
Observe that the output is cached and does not vary based on the expected context.
Proposed resolution
Text filters already support cacheability metadata through FilterProcessResult, which extends BubbleableMetadata.
Shortcode module should allow shortcode plugins to opt-in to cacheable metadata by implementing CacheableDependencyInterface.
The Shortcode module would then:
- Aggregate cacheable metadata from each shortcode plugin instance.
- Merge it into the render pipeline to ensure proper cache invalidation and variation.
Remaining tasks
- Update Shortcode plugin system to check if a plugin implements CacheableDependencyInterface.
- Collect and merge cache tags, contexts, and max-age during shortcode processing.
- Add test coverage for cache variation with shortcodes.
- Update documentation for shortcode plugin developers.
User interface changes
None. This is a backend-only change that affects rendering and caching.
API changes
- Shortcode plugins can optionally implement CacheableDependencyInterface to provide cache metadata.
- Shortcode processing service will merge metadata into the parent render array.
Data model changes