putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
147 stars 35 forks source link

Entry not marked as expired if field in Matrix has ben edited #658

Closed svondervoort closed 1 month ago

svondervoort commented 2 months ago

Bug Report

I've seen this issue come up before but can't find it if I search on matrix, but whenever we change content in a field (ex. CKeditor) within a matrix on an Entry page the page is not marked as expired.

Plugin Version

^4.10

Craft CMS Version

4.8.10

PHP Version

8.2

bencroker commented 2 months ago

Please update to the latest version of the plugin, currently 4.16.3 (for Craft 4). If the issue persists then please refresh the entire cache, to ensure that Blitz is tracking elements correctly, before retesting.

svondervoort commented 2 months ago

Sorry, I copied the version from composer.json instead of the composer.lock. The version in use is 4.16.3.

bencroker commented 2 months ago

Can you provide the exact minimal steps to reproduce the issue, so I can test locally?

svondervoort commented 1 month ago

Hi Ben, sorry for the late reply. I finally had some time creating and testing a minimum setup with the following versions:

Steps

  1. Create a matrix field.
  2. Create a block within the matrix field with a Plain Text field within.
  3. Create an Entry section and add the matrix field to the Entry type.
  4. Add the matrix block with some content and save the entry.
  5. In the blitz_caches table the expireDate for the entry is still null.
  6. Edit the Title of the entry and save the entry.
  7. In the blitz_caches table the expireDate for the entry is updated.

Please let me know if you need more input.

bencroker commented 1 month ago

Before step 5, you should visit the page that outputs the entry with the matrix field, so that Blitz is aware of it. You’ll then be able to see whether the page is tracked in the diagnostics utility. Please try that and let me know if it makes any difference. Testing this locally works as expected.

svondervoort commented 1 month ago

I'm sorry I must be doing something wrong. Just to be sure I've setup a totally new blank Craft v4.9.2 project and only installed Blitz with a basic setup.

General Settings - Refresh mode: Clear the cache, regenerate manually or organically
General Settings - Included URI Patterns: .*
Cache Storage - Folder Path: @webroot/cache/blitz
Cache Generation - Cache Generator: Local Generator

After visiting he page I do see the page in the diagnostics utility but now even when I simply edit the title or add/remove a matrix block the expiry date is never set.

bencroker commented 1 month ago

Since you have the refresh mode set to Clear the cache..., the page will be cleared on refresh, meaning that there’s no reason to set the expiry date. And expiry date is only ever set if the refresh mode is set to Expire the cache....

svondervoort commented 1 month ago

Ah yes. I changed the refresh mode to Expire the cache... and now it at least sets an expire date when I edit the title of the page, but still not when I edit or add a Matrix block to the same Entry.

Can I provide you with the test project or something?

bencroker commented 1 month ago

Yes, you can send access details or a full project to support@putyourlightson.com, along with instructions on how to replicate, and I'll take a look.

svondervoort commented 1 month ago

Thanks for taking the time, email send.

bencroker commented 1 month ago

Tested, and the issue is that the matrix field is not output in the cached page, therefore Blitz is not tracking it. Adding the following Twig code to your template will result in the behaviour you expect.

{% for block in entry.matrix.all() %}
    <p>{{ block.blockTitle }}</p>
{% endfor %}

Note that Blitz 4.18.1 (not yet released) adds field tracking to the diagnostics utility, which should make this more transparent in future.

bencroker commented 1 month ago

FYI 4.18.1 was just released.