Optimized js assets fed into _locale_parse_js_file

Created on 1 April 2020, about 4 years ago
Updated 15 May 2023, about 1 year ago

We run a site with the advagg-module and css/js minification turned on. A few months later the locale module was also enabled in the website with no special problems.

Since a couple of weeks we stumble upon the following error, coming from the locale module:

Exception: Only local files should be passed to _locale_parse_js_file(). in _locale_parse_js_file() (line 1129 of /var/www/web/core/modules/locale/locale.module). The input for the _locale_parse_js_file function is an optimized file generated by advagg: public://js/optimized/js_dHny-amWPLMeggFZO0q9qztnliwo_qRE1s-q_BE-jjU.3Jy_GbSLrg0o9y5Z5n1uw0qxZECH7C6OQpVBgNFYa0g.js.

The problem occures because _locale_parse_js_file cannot handle files with the public:// scheme in it, because of the following code:

  // If there is still a protocol component in the path, reject that.
  if (strpos($filepath, ':')) {
    throw new Exception('Only local files should be passed to _locale_parse_js_file().');
  }

The problem only occures on a kubernetes cluster with the public files directory mounted via nfs, but not consistently. When this error occures, a Drupal cache clear solves this, and no matter what i do, i cannot reproduce the same error. It suddenly occures again later.

Because of the code of _locale_parse_js_file, i think the kubernetes/nfs cluster setup should not be the problem. Changing the advagg module's weight to 10 (to make its hooks run after the locale module hooks) solves the problem; the javascript files are translated first by _locale_parse_js_file and minified by advagg afterwards.

I don't know if anyone ever experienced these issues, but i think one of the following solutions should be incorporated into the advagg module:

1. Increase the module weight of the advagg module so its hooks are runned last
2. Instead of using public:// paths for $asset['data'], Drupal\advagg\Asset::scanFile should convert these paths to real filesystem paths (using Drupal\Core\File\FileSystemInterface::realPath). This might not be the best solution when the public-streamwrapper does not resolve to a local filesystem.

Hopefully someone with more advagg-knowledge can have a look at this issue and decide which solution would be the best to implement. I am willing to write a patch if needed.

πŸ› Bug report
Status

Needs work

Version

4.1

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands Ruuds

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.

Production build 0.69.0 2024