Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nocache-Tags not being replaced sometimes when URL contains query parameters #11543

Open
dryven-daniel opened this issue Mar 7, 2025 · 5 comments · May be fixed by #11545
Open

nocache-Tags not being replaced sometimes when URL contains query parameters #11543

dryven-daniel opened this issue Mar 7, 2025 · 5 comments · May be fixed by #11545

Comments

@dryven-daniel
Copy link

Bug description

We have set up a multi-site with full static caching enabled for our customer. Some regions of the website are dynamic and are replaced using the nocache tag. This setup works well, but recently, our customer reported a bug:

They launched a marketing campaign targeting a landing page on their website.

  • The URL includes the following UTM parameters: https://www.example.com/campaign?utm_source=linkedin.com&utm_medium=referral&utm_campaign=returnonprevention
  • The nocache tags aren't being replaced; instead, they remain empty.
  • After some testing, I discovered that the order of the query parameters affects the behavior. Rearranging them to ?utm_campaign=returnonprevention&utm_medium=referral&utm_source=linkedin.com resolves the issue.

Commenting out this line inside the NoCache Controller fixes the problem:
GitHub link

It seems that this line reorders the query parameters, preventing the nocache tags from being replaced correctly.

How to reproduce

Logs

Environment

Application Name: Statamic
Laravel Version: 12.1.1
PHP Version: 8.3.14
Composer Version: 2.7.2
Environment: local
Debug Mode: ENABLED
URL: statamic.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 0
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: full
Version: 5.49.1 Solo

Installation

Fresh statamic/statamic site via CLI

Additional details

It might have something to do with this PR: #7486

@duncanmcclean
Copy link
Member

Are you able to provide your config/statamic/static_caching.php file?

@dryven-daniel
Copy link
Author

Are you able to provide your config/statamic/static_caching.php file?

Yes of course, it's a fresh install using the statamic new command

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Active Static Caching Strategy
    |--------------------------------------------------------------------------
    |
    | To enable Static Caching, you should choose a strategy from the ones
    | you have defined below. Leave this null to disable static caching.
    |
    */

    'strategy' => env('STATAMIC_STATIC_CACHING_STRATEGY', null),

    /*
    |--------------------------------------------------------------------------
    | Caching Strategies
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the static caching strategies for your
    | application as well as their drivers.
    |
    | Supported drivers: "application", "file"
    |
    */

    'strategies' => [

        'half' => [
            'driver' => 'application',
            'expiry' => null,
        ],

        'full' => [
            'driver' => 'file',
            'path' => public_path('static'),
            'lock_hold_length' => 0,
            'permissions' => [
                'directory' => 0755,
                'file' => 0644,
            ],
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Exclusions
    |--------------------------------------------------------------------------
    |
    | Here you may define a list of URLs to be excluded from static
    | caching. You may want to exclude URLs containing dynamic
    | elements like contact forms, or shopping carts.
    |
    */

    'exclude' => [

        'class' => null,

        'urls' => [
            //
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Invalidation Rules
    |--------------------------------------------------------------------------
    |
    | Here you may define the rules that trigger when and how content would be
    | flushed from the static cache. See the documentation for more details.
    | If a custom class is not defined, the default invalidator is used.
    |
    | https://statamic.dev/static-caching
    |
    */

    'invalidation' => [

        'class' => null,

        'rules' => [
            //
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Ignoring Query Strings
    |--------------------------------------------------------------------------
    |
    | Statamic will cache pages of the same URL but with different query
    | parameters separately. This is useful for pages with pagination.
    | If you'd like to ignore the query strings, you may do so.
    |
    */

    'ignore_query_strings' => false,

    'allowed_query_strings' => [
        //
    ],

    'disallowed_query_strings' => [
        //
    ],

    /*
    |--------------------------------------------------------------------------
    | Nocache
    |--------------------------------------------------------------------------
    |
    | Here you may define where the nocache data is stored.
    |
    | https://statamic.dev/tags/nocache#database
    |
    | Supported drivers: "cache", "database"
    |
    */

    'nocache' => 'cache',

    'nocache_js_position' => 'body',

    /*
    |--------------------------------------------------------------------------
    | Replacers
    |--------------------------------------------------------------------------
    |
    | Here you may define replacers that dynamically replace content within
    | the response. Each replacer must implement the Replacer interface.
    |
    */

    'replacers' => [
        \Statamic\StaticCaching\Replacers\CsrfTokenReplacer::class,
        \Statamic\StaticCaching\Replacers\NoCacheReplacer::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Warm Queue
    |--------------------------------------------------------------------------
    |
    | Here you may define the queue name and connection
    | that will be used when warming the static cache.
    |
    */

    'warm_queue' => env('STATAMIC_STATIC_WARM_QUEUE'),

    'warm_queue_connection' => env('STATAMIC_STATIC_WARM_QUEUE_CONNECTION'),

    /*
    |--------------------------------------------------------------------------
    | Shared Error Pages
    |--------------------------------------------------------------------------
    |
    | You may choose to share the same statically generated error page across
    | all errors. For example, the first time a 404 is encountered it will
    | be generated and cached, and then served for all subsequent 404s.
    |
    | This is only supported for half measure.
    |
    */

    'share_errors' => false,

];

.env Config:

STATAMIC_LICENSE_KEY=
STATAMIC_PRO_ENABLED=false
STATAMIC_STACHE_WATCHER=auto
STATAMIC_STATIC_CACHING_STRATEGY=full
STATAMIC_REVISIONS_ENABLED=false
STATAMIC_GRAPHQL_ENABLED=false
STATAMIC_API_ENABLED=false
STATAMIC_GIT_ENABLED=false

@duncanmcclean
Copy link
Member

Thanks!

@faustbrian
Copy link

faustbrian commented Mar 19, 2025

@duncanmcclean I just ran into this issue too and your PR resolves this. Is there an ETA on release? This is blocking us from a release because without static caching we have a handful of pages that are just too slow and your PR resolves it for good in all cases we tested.

@duncanmcclean
Copy link
Member

Sorry, we don't have an ETA for when it'll be merged.

If you need the fix in the meantime, you can pull the PR into your project with a composer patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants