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

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

Closed
tabatii opened this issue Oct 13, 2023 · 5 comments
Assignees
Labels
bug Something isn't working confirmed low priority
Milestone

Comments

@tabatii
Copy link

tabatii commented Oct 13, 2023

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

  • clone the repo
  • run "cd filament-bugs"
  • run "git checkout lazy-widget"
  • run "composer install"
  • create the ".env" file
  • run "php artisan key:generate"
  • configure the database
  • run "php artisan migrate --seed"
  • navigate to "/admin"
  • email : "[email protected]"
  • password : "password"

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
Copy link
Member

I've found why this happens:

[...(($widget instanceof \Filament\Widgets\WidgetConfiguration) ? $widget->properties : $widget::getDefaultProperties()), ...$data],

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.

@zepfietje zepfietje added this to the v3 milestone Oct 13, 2023
@tabatii
Copy link
Author

tabatii commented Oct 13, 2023

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
Copy link
Member

Fixed in latest version

@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Oct 27, 2023
@caendesilva
Copy link
Contributor

caendesilva commented Jan 5, 2024

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 #10663

@danharrin
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed low priority
Projects
Status: Done
Development

No branches or pull requests

4 participants