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

Blade Directive @nocache shows NOCACHE_PLACEHOLDER #7820

Closed
jhhazelaar opened this issue Apr 3, 2023 · 4 comments
Closed

Blade Directive @nocache shows NOCACHE_PLACEHOLDER #7820

jhhazelaar opened this issue Apr 3, 2023 · 4 comments

Comments

@jhhazelaar
Copy link
Contributor

jhhazelaar commented Apr 3, 2023

Bug description

I'm using @nocahe blade directive for excluding auth dropdown. This give a NOCACHE_PLACEHOLDER text in non statamic routes. In the comments of issue #6682 the tip is to add statamic.web middleware to the custom route.

With that middleware the nocache placeholder is gone, but then the auth in other section of the page get cached. This is a problem with route that display user data.

User data on the frontend are laravel eloquent users.

How to reproduce

Example repo: https://github.com/jhhazelaar/laravel-statamic-nocache-placeholder

Set STATAMIC_STATIC_CACHING_STRATEGY to half.

Register two users in the application. Login and go to dashboard. Login second user and go to dashboard. See username of first user in dashboard.

Logs

No response

Environment

Environment
Application Name: Laravel Statamic Nocache Placeholder
Laravel Version: 9.52.5
PHP Version: 8.2.4
Composer Version: 2.5.4
Environment: local
Debug Mode: ENABLED
URL: laravel-statamic-nocache-placeholder.test
Maintenance Mode: OFF

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

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Enabled
Static Caching: half
Version: 3.4.7 Solo

Installation

Existing Laravel app

Antlers Parser

None

Additional details

No response

@duncanmcclean
Copy link
Member

I've ran into this one recently too. It happened to me when I had the {{ nocache }} tag present and had a form on the page but the static caching middleware wasn't present.

@jhhazelaar
Copy link
Contributor Author

After debugging and digging around I maybe stumbled on a solution. The @nocache tags push a Statamic\StaticCaching\NoCache\ViewRegion to regions. The ViewRegion extends Statamic\StaticCaching\NoCache\Region and that has a method placeholder. If I add a method placeholder to ViewRegion that returns the original view with context the nocache tags works outside of statamic routes.

Example placeholder method in VIewRegion:

    public function placeholder(): string
    {
        return view($this->view, $this->context);
    }

@jhhazelaar
Copy link
Contributor Author

Pull request isn't working correct. Temp fix for now is:

@if(in_array('statamic.web', Route::current()->gatherMiddleware()))
    @nocache('auth.navigation-dropdown', [], [])
@else
    @include('auth.navigation-dropdown', [], [])
@endif

@duncanmcclean
Copy link
Member

Closing in favour of #6744, which seems to be the same issue.

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

No branches or pull requests

3 participants