filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.1k stars 2.83k forks source link

Widget lazy loading not working when displaying the widget using the make() method #9066

Closed tabatii closed 11 months ago

tabatii commented 11 months ago

Package

filament/filament

Package Version

v3.0.74

Laravel Version

v10.28.0

Livewire Version

v3.0.8

PHP Version

PHP 8.2.9

Problem description

when i display a widget using the make() method the lazy loading does not work i want to use the make() method because i want to pass properties to the widget

protected function getHeaderWidgets(): array
{
    return [
        \App\Filament\Widgets\TestWidget::make(), // lazy loading not working
        \App\Filament\Widgets\TestWidget::class, // lazy loading working
    ];
}

Expected behavior

i expect the widget to lazy load when i display it using the make() method

Steps to reproduce

you will find two widgets in the dashboard (one widget displayed twice) the dashboard class is located at "app/Filament/Pages" and the widget class is located at "app/Filament/Widgets" the first widget is displayed using the make() method and it is not lazy loaded the second widget is displayed using the class name and it is lazy loaded

Reproduction repository

https://github.com/tabatii/filament-bugs

Relevant log output

No response

zepfietje commented 11 months ago

I've found why this happens: https://github.com/filamentphp/filament/blob/c1bf4d56cb2b4fa6ef418fd733b26a6ce6f15198/packages/widgets/resources/views/components/widgets.blade.php#L31

You can work around this by passing lazy as a property to the widget:

TestWidget::make([
    'lazy' => true,
])

I will leave this issue open though, since I feel like the default properties should always be merged in. However, there must be a reason for the current behavior, so I will leave this to @danharrin.

tabatii commented 11 months ago

i also noticed that a table widget acts different when you display it using make() like if you display it using make() it will use the query string variable "page" on pagination and you won't be able to modify that variable using "->queryStringIdentifier('something')" that's just what i noticed but i assume this bug will affect some other behaviors as well

danharrin commented 11 months ago

Fixed in latest version

caendesilva commented 8 months ago

I'm not sure if it's related to this but for me, widget lazy loading is not using the $view property. @danharrin should I create a new issue or could it be related to this?

// Throws Livewire\Exceptions\ComponentNotFoundException
// Unable to find component: [app.filament.widgets.git-hub-account-widget]
// So it does not seem to be using the $view property, and instead tries to parse the class name.
// Setting $isLazy to false works, and the $view property seems to be used.

class GitHubAccountWidget extends Widget
{
    protected static string $view = 'filament.widgets.github-account-widget';
    protected static bool $isLazy = true;
}

I'm registering the widget in a page using the class constant syntax like this:

class AccountSettingsPage extends MyProfilePage
{
    protected function getHeaderWidgets(): array
    {
        return [
            GitHubAccountWidget::class,
        ];
    }
}

Edit: See https://github.com/filamentphp/filament/issues/10663

danharrin commented 8 months ago

Please create a new issue as I doubt the existing reproduction repository fits it