Laravel-Backpack / basset

Better asset helpers for Laravel apps.
MIT License
151 stars 10 forks source link

[Bug] When used with laravel octane, css is not loaded. #102

Closed paulzakk closed 7 months ago

paulzakk commented 10 months ago

I am using php 8.1 version and laravel 10, backpack 6.1.15 version. Laravel is configured with octane (swoole). When I log in after completing the configuration, it seems that the css file is not called. Could this be a bug?

welcome[bot] commented 10 months ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

karandatwani92 commented 10 months ago

Hey @paulzakk

Please try this 1) php artisan basset:clear 2) php artisan basset:fresh

paulzakk commented 10 months ago

@karandatwani92

I tried both 1 and 2, but it didn't work.

karandatwani92 commented 10 months ago

Please check APP_URL in env or config. and then re-run the above steps.

paulzakk commented 10 months ago

Thank you for answer. @karandatwani92 I checked APP_URL and there is no problem. In backpack 5.x version, it runs normally without any problem. Is there anything else to check?

karandatwani92 commented 10 months ago

Can you share your env file?

paulzakk commented 10 months ago

@karandatwani92

This is my env file.

APP_NAME=test APP_ENV=production APP_KEY=base64:rmoF4NcebubBlM9tSqi8UVLG+IXNBj7r2cXr00kP1gI= APP_DEBUG=false APP_URL=http://localhost

LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=test DB_USERNAME=test DB_PASSWORD=test

BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_MAILER=smtp MAIL_HOST=mailpit MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_HOST= PUSHER_PORT=443 PUSHER_SCHEME=https PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}" VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" VITE_PUSHER_HOST="${PUSHER_HOST}" VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" OCTANE_SERVER=swoole

paulzakk commented 10 months ago

Additionally, what I checked was that it was normal when I used Laravel serve in the same settings and environment, but it was abnormal when I used octane.

pxpm commented 10 months ago

Depending on your setup, but pretty sure if using artisan serve you need to add the :port, the same way you access in browser: http://localhost:8001 or any port that you are using.

Also from your error I think I would test if the laravel http client is properly working for you. Basset uses guzzle under the hood.

Let me know if that works.

masrodjie commented 8 months ago

I'm facing same problem. I'm using Octane RoadRunner. For a few refresh pages, it's working. Then it's lost loading css. I think the bug is on basset. For temporary fix, i just remove the content in the BassetManager.php file markAsLoaded function:

public function markAsLoaded(string $asset): void
{

}
alruddick commented 7 months ago

When binding the BassetManager in BassetServiceProvider, using a Singleton w/ Octane can cause problems on subsequent requests. Changing this to a normal binding resolves the issue, however, I'm not 100% sure why a singleton was used in the first place. Someone else might be able to shed some light on that

    /**
     * Register any package services.
     *
     * @return void
     */
    public function register(): void
    {
        // Register the service the package provides.
        $this->app->bind('basset', fn () => new BassetManager());

        // Merge the configuration file.
        $this->mergeConfigFrom(__DIR__.'/config/backpack/basset.php', 'backpack.basset');

        // Register blade directives
        $this->registerBladeDirectives();
    }
promatik commented 7 months ago

Hi everyone! Indeed Basset was being loaded as a singleton instead of scoped, so that was leading to files being marked as loaded forever 🤷‍♂️ That should be fixed with #105, tagged on https://github.com/Laravel-Backpack/basset/releases/tag/1.2.2 🙌