Setting "preprocess" false in "cookies_mySubmodule_alter" could lead to unintentional problems with file aggregation

Created on 11 November 2025, about 20 hours ago

Problem/Motivation

This is a follow-up issue to 🐛 Only file JavaScript assets with preprocessing enabled can be optimized. Active .

All submodules use hook_js_alter() to conditionally modify JavaScript files when "knock out" is enabled. These modifications include

  1. Setting preprocess to FALSE
  2. Adding attributes like type="text/plain" and data-cookieconsent to prevent script execution until consent is given

The problem is that these conditional modifications in hook_js_alter() are not compatible with how JavaScript aggregation caching works in Drupal. Even though aggregation changed significantly in Drupal 10.1, the caching of hook_js_alter() did not change. This means:

  • When JavaScript aggregation is enabled, Drupal creates aggregate files and caches them
  • The cache key doesn't account for conditional modifications based on runtime state (like whether knock out is enabled)
  • This can result in incorrect cached aggregates being served, where scripts that should be modified are served unmodified, or vice versa
  • The same aggregate URL might be generated for different scenarios (with/without knock out), leading to cache collisions

This is the same pattern that core modules like locale and ckeditor5 solved by using placeholder libraries that are conditionally attached, ensuring unique aggregate URLs based on whether the library is present or not.

Proposed resolution

Refactor the cookies submodules to use a placeholder library, following the same approach used by core modules locale and ckeditor5:

This approach ensures that:

  • When knock out is enabled, the placeholder library is attached → unique aggregate URL → correct cache key
  • When knock out is disabled, the placeholder library is not attached → different aggregate URL → separate cache entry
  • The presence/absence of the library is part of the cache key, so aggregation handles it correctly

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇩🇪Germany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024