Skip to content

Commit

Permalink
Fixed #11602
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jul 16, 2022
1 parent cc2ee65 commit cad0082
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixed
- Fixed a bug where deprecation warnings for treating an element query as an array weren’t getting logged with an origin, if they involved Twig’s `|batch` filter. ([#11597](https://github.com/craftcms/cms/issues/11597))
- Fixed a bug where `{% js %}`, `{% script %}`, and `{% css %}` tags weren’t registering JavaScript and CSS code properly when used within a `{% cache %}` tag that contained an ungenerated image transform. ([#11602](https://github.com/craftcms/cms/issues/11602))

## 3.7.48 - 2022-07-12

Expand Down
20 changes: 13 additions & 7 deletions src/services/TemplateCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ public function endTemplateCache(string $key, bool $global, ?string $duration, $

// If there are any transform generation URLs in the body, don't cache it.
// stripslashes($body) in case the URL has been JS-encoded or something.
if (StringHelper::contains(stripslashes($body), 'assets/generate-transform')) {
return;
}
$saveCache = !StringHelper::contains(stripslashes($body), 'assets/generate-transform');

// Always add a `template` tag
$dep->tags[] = 'template';
if ($saveCache) {
// Always add a `template` tag
$dep->tags[] = 'template';

$cacheValue = [$body, $dep->tags];
$cacheValue = [$body, $dep->tags];
}

if ($withScripts) {
// Parse the JS/CSS code and tag attributes out of the <script> and <style> tags
Expand All @@ -190,12 +190,18 @@ public function endTemplateCache(string $key, bool $global, ?string $duration, $
return [$tag['children'][0]['value'], $tag['attributes']];
}, $bufferedCss);

array_push($cacheValue, $bufferedJs, $bufferedScripts, $bufferedCss);
if ($saveCache) {
array_push($cacheValue, $bufferedJs, $bufferedScripts, $bufferedCss);
}

// Re-register the JS and CSS
$this->_registerScripts($bufferedJs, $bufferedScripts, $bufferedCss);
}

if (!$saveCache) {
return;
}

$cacheKey = $this->_cacheKey($key, $global);

if ($duration !== null) {
Expand Down

0 comments on commit cad0082

Please sign in to comment.