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

LivePreview and movement of assets causes error or page load #11358

Open
waldemar-p opened this issue Jan 15, 2025 · 13 comments
Open

LivePreview and movement of assets causes error or page load #11358

waldemar-p opened this issue Jan 15, 2025 · 13 comments

Comments

@waldemar-p
Copy link

Bug description

Every time I use the livepreview and then move an asset the no page call works anymore because of that error until I use the livepreview again (with a refreshed cms, because sometimes the preview doesnt work too).

How to reproduce

  1. create a page with an asset
  2. save and publish
  3. view it via the live preview
  4. calling the url will work
  5. move the asset
  6. calling the url will result in an error as shown below
  7. (refresh the cms) and call any preview
  8. calling the url will work again

Logs

local.ERROR: Call to a member function repository() on null {"exception":"[object] (Error(code: 0): Call to a member function repository() on null at /var/www/project/vendor/statamic/cms/src/Tokens/Handlers/LivePreview.php:15)
[stacktrace]
#0 /var/www/project/vendor/statamic/cms/src/Tokens/AbstractToken.php(59): Statamic\\Tokens\\Handlers\\LivePreview->handle()
#1 /var/www/project/vendor/statamic/cms/src/Http/Middleware/HandleToken.php(18): Statamic\\Tokens\\AbstractToken->handle()
#2 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\HandleToken->handle()
#3 /var/www/project/vendor/statamic/cms/src/Http/Middleware/RequireStatamicPro.php(17): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#4 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\RequireStatamicPro->handle()
#5 /var/www/project/vendor/statamic/cms/src/GraphQL/Middleware/CacheResponse.php(13): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#6 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\GraphQL\\Middleware\\CacheResponse->handle()
#7 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#8 /var/www/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(797): Illuminate\\Pipeline\\Pipeline->then()
#9 /var/www/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(776): Illuminate\\Routing\\Router->runRouteWithinStack()
#10 /var/www/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(740): Illuminate\\Routing\\Router->runRoute()
#11 /var/www/project/vendor/laravel/framework/src/Illuminate/Routing/Router.php(729): Illuminate\\Routing\\Router->dispatchToRoute()
#12 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(190): Illuminate\\Routing\\Router->dispatch()
#13 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(141): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#14 /var/www/project/vendor/statamic/cms/src/Http/Middleware/StopImpersonating.php(12): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#15 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\StopImpersonating->handle()
#16 /var/www/project/vendor/statamic/cms/src/Http/Middleware/DisableFloc.php(17): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#17 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\DisableFloc->handle()
#18 /var/www/project/vendor/statamic/cms/src/Http/Middleware/CheckMultisite.php(14): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#19 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\CheckMultisite->handle()
#20 /var/www/project/vendor/statamic/cms/src/Http/Middleware/CheckComposerJsonScripts.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#21 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\CheckComposerJsonScripts->handle()
#22 /var/www/project/vendor/statamic/cms/src/Http/Middleware/PoweredByHeader.php(18): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#23 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Statamic\\Http\\Middleware\\PoweredByHeader->handle()
#24 /var/www/project/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(59): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#25 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle()
#26 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#27 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#28 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#29 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#30 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#31 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#32 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#33 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#34 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#35 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#36 /var/www/project/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Fruitcake\\Cors\\HandleCors->handle()
#38 /var/www/project/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#40 /var/www/project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#41 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\\Pipeline\\Pipeline->then()
#42 /var/www/project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#43 /var/www/project/public/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle()
#44 {main}
"}

Environment

I use Statamic Headless with Nextjs.


Aside from that the `php please support:details`:

Environment
Application Name: Actiware
Laravel Version: 9.52.16
PHP Version: 8.2.15
Composer Version: 2.7.1
Environment: local
Debug Mode: ENABLED
URL: cmsapi.actiware.de
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: 1
Antlers: runtime
Stache Watcher: Disabled
Static Caching: Disabled
Version: 4.47.0 PRO

Statamic Addons
aerni/font-awesome: 2.0.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@waldemar-p
Copy link
Author

I don't know how much this relates, but I just had the same error log after unpublishing a page. I couldn't call any pages until I published it again.

@waldemar-p
Copy link
Author

Additional to my previous comment I, there also the page is restored to a working state either by calling the livepreview successfull (sometimes that also doesnt work) aside from publishing it again.
But this time it seems (on first try) to only work with the same preview as the page that was unpublished.

@duncanmcclean duncanmcclean changed the title [4.36] LivePreview and movement of assets causes error or page load LivePreview and movement of assets causes error or page load Jan 15, 2025
@duncanmcclean
Copy link
Member

Cache: statamic

Can you provide your config/cache.php file?

@waldemar-p
Copy link
Author

Yes, here it is:

<?php

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Cache Store
    |--------------------------------------------------------------------------
    |
    | This option controls the default cache connection that gets used while
    | using this caching library. This connection is used when another is
    | not explicitly specified when executing a given caching function.
    |
    */

    'default' => env('CACHE_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Cache Stores
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the cache "stores" for your application as
    | well as their drivers. You may even define multiple stores for the
    | same cache driver to group types of items stored in your caches.
    |
    | Supported drivers: "apc", "array", "database", "file",
    |         "memcached", "redis", "dynamodb", "octane", "null"
    |
    */

    'stores' => [

        'apc' => [
            'driver' => 'apc',
        ],

        'array' => [
            'driver' => 'array',
            'serialize' => false,
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'cache',
            'connection' => null,
            'lock_connection' => null,
        ],

        'file' => [
            'driver' => 'file',
            'path' => storage_path('framework/cache/data'),
        ],

        'memcached' => [
            'driver' => 'memcached',
            'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
            'sasl' => [
                env('MEMCACHED_USERNAME'),
                env('MEMCACHED_PASSWORD'),
            ],
            'options' => [
                // Memcached::OPT_CONNECT_TIMEOUT => 2000,
            ],
            'servers' => [
                [
                    'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                    'port' => env('MEMCACHED_PORT', 11211),
                    'weight' => 100,
                ],
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'cache',
            'lock_connection' => 'default',
        ],

        'dynamodb' => [
            'driver' => 'dynamodb',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
            'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
            'endpoint' => env('DYNAMODB_ENDPOINT'),
        ],

        'octane' => [
            'driver' => 'octane',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Cache Key Prefix
    |--------------------------------------------------------------------------
    |
    | When utilizing a RAM based store such as APC or Memcached, there might
    | be other applications utilizing the same cache. So, we'll specify a
    | value to get prefixed to all our keys so we can avoid collisions.
    |
    */

    'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),

];

@duncanmcclean
Copy link
Member

I've just re-read your issue and noticed you're still on Statamic 4.47.0, which is no longer supported. Can you try updating to Statamic 5 and let us know if you're still experiencing the same issues?

@waldemar-p
Copy link
Author

Sadly I cant because of this issue #11245

I couldn't find the reason behind this problem for now so I can't upgrade safely to Statamic 5.

@duncanmcclean
Copy link
Member

Okay! It's very possible the issue you're running into here has been fixed by changes in v5.

If you're still running into this issue after upgrading to Statamic 5, let us know and we can re-open this issue.

@waldemar-p
Copy link
Author

I'm back with the newest Statamic and the cases with that error have slightly changed.

Moving a file did nothing, except that the file was not displayed shortly after.

Now every time I clear the complete cache I get this error. Still until I call the live-preview inside statamic.

Also I dont have the permission to re-open this issue. :D

@waldemar-p
Copy link
Author

After trying a bit I can be more detailed: The error occurs after clearing the application cache.

@duncanmcclean duncanmcclean reopened this Jan 17, 2025
@duncanmcclean
Copy link
Member

Re-opened.

Now that you've updated, can you run php please support:details again and post it here?

@waldemar-p
Copy link
Author

Sure:

php please support:details

Environment
Application Name: Actiware
Laravel Version: 10.48.25
PHP Version: 8.2.15
Composer Version: 2.7.1
Environment: local
Debug Mode: ENABLED
URL: cmsapi.actiware.de
Maintenance Mode: OFF

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

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

Statamic
Addons: 1
Sites: 3 (Deutsch, Schweizer Hochdeutsch, English)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.45.1 PRO

Statamic Addons
aerni/font-awesome: 3.0.2

@waldemar-p
Copy link
Author

After playing with the error for a while I noticed that php please stache:refresh aswell as composer install both result in the same error.

@waldemar-p
Copy link
Author

Ok, I have played around some more and some errors before were due to permission problems. Sorry!

But one thing still doesn't work as intended:

I think starting with Statamic 5 (I didn't notice it before) it's possible to visit unpublished pages while being logged into the CMS by simply calling the url. Now after clearing the cache or composer install the call of said unpublished page leads to the LivePrevie.php:15 error. But not on other page, probably because of the statamic 5 upgrade.

This now is of course vastly less important because a normal visitor shouldnt see the unpublished pages anyway.


Reproducing:

  1. create and publish a page
  2. unpublish the page
  3. visit the url (in the same browser to pass the token)
  4. it works
  5. clear cache
  6. call the url
  7. it doesn't work
  8. reload the control panel page and call the preview
  9. call the url
  10. it works again

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

2 participants