putyourlightson / craft-blitz

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

Inconsistent Results with excludedQueryStringParams #322

Closed jmcgaha closed 3 years ago

jmcgaha commented 3 years ago

Describe the bug

I'm using Blitz and Sprig on a project and I'm trying to whitelist all the query strings that are created from Sprig's pushUrl feature. However one of the items is an array of related entries and it's working by adding querystrings like: type[1]={id}&type[3]={id}. When I add the regex to account for type[n] it doesn't always work if there are additional query strings in the list.

Here is the list of params in my config file:

'excludedQueryStringParams' => [
    '^(?!type\[[0-9]\]$|location\[[0-9]\]$|recruiting$|virtual$|page$|orderBy$|sortBy$|success).*',
],

To reproduce

Steps to reproduce the behaviour:

  1. Go to url: /events?type[1]=196850&location[2]=196829&page=1&orderBy=dateStart&sortBy=desc
  2. Page that Blitz saves is: page=1&orderBy=dateStart&sortBy=desc/index.html

Expected behaviour

  1. Page that Blitz saves should be: type[1]=196850&location[2]=196829&page=1&orderBy=dateStart&sortBy=desc/index.html
  2. The weird thing is that if I edit the url and take off one of the strings like &sortBy=desc it saves the correct page, but it never saves the correct page with all of those query strings.

Versions

bencroker commented 3 years ago

Just tested this locally and it works as expected. Are you using the Blitz File Storage as the cache storage type?

jmcgaha commented 3 years ago

Yes, I had it set in my config for Blitz File Storage. I removed everything in the config except the excludedQueryStringParams part and cleared the craft cache and made sure everything was set right in the plugin from the control panel and it is. Still the same results. If you can't reproduce I may just disable on the page using Sprig.

bencroker commented 3 years ago

In your second step you said:

Page that Blitz saves is: page=1&orderBy=dateStart&sortBy=desc/index.html

Where exactly are you seeing this? The index.html at the end looks off.

jmcgaha commented 3 years ago

Sorry for the confusion, it creates a folder: page=1&orderBy=dateStart&sortBy=desc with an index.html inside of that folder.

bencroker commented 3 years ago

In my Nitro development environment it creates type[1]=196850&location[2]=196829&page=1&orderBy=dateStart&sortBy=desc.

As an aside, I would tweak the regexp as follows to allow for multiple digits:

'excludedQueryStringParams' => [
    '^(?!type\[[0-9]+\]$|location\[[0-9]+\]$|recruiting$|virtual$|page$|orderBy$|sortBy$|success).*',
],