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

Filament Fabricator: Layout "default" not found when using Octane #120

Closed
plunkettscott opened this issue Dec 4, 2023 · 5 comments
Closed

Comments

@plunkettscott
Copy link

When using Octane (tried both Swoole and RoadRunner for confirmation), pages occasionally load correctly on the first request, but it seems that subsequent requests fail with an error about the layout missing. The same site works correctly without Octane.

@Z3d0X
Copy link
Owner

Z3d0X commented Dec 5, 2023

Potentially related to #111

@ksimenic
Copy link
Contributor

I have the same problem and managed to get to the root of it.

The issue is in Z3d0X\FilamentFabricator\FilamentFabricatorServiceProvider.

    public function packageRegistered(): void
    {
        parent::packageRegistered();

        $this->app->scoped('filament-fabricator', function () {
            return new FilamentFabricatorManager();
        });
    }

Based on the https://laravel.com/docs/10.x/container#binding-scoped

The scoped method binds a class or interface into the container that should only be resolved one time within a given Laravel request / job lifecycle. While this method is similar to the singleton method, instances registered using the scoped method will be flushed whenever the Laravel application starts a new "lifecycle", such as when a Laravel Octane worker processes a new request or when a Laravel queue worker processes a new job:

Because filament-fabricator is registered as scoped it is flushed on every call. When it instantiates new FilamentFabricatorManager this is what happens in the constructor

    public function __construct()
    {
        /** @var Collection<string,string> */
        $pageBlocks = collect([]);

        /** @var Collection<string,string> */
        $layouts = collect([]);

        $this->pageBlocks = $pageBlocks;
        $this->layouts = $layouts;
    }

meaning all previously registered page blocks and layouts will be overwritten by empty collections (removed).

Now this would be fine if bootingPackage() method from Z3d0X\FilamentFabricator\FilamentFabricatorServiceProvider is called, but this happens only once.

This will eventually result in having page blocks and layouts visible on first and N-1 subsequent requests (N = number of workers that you are running octane with), but on the N+1 request they will simply disappear and be gone until you restart octane server.

Solution to this problem is simply changing scoped with singleton but I am not 100% sure of the full implications this might have on the package.

    public function packageRegistered(): void
    {
        parent::packageRegistered();

        $this->app->singleton('filament-fabricator', function () {
            return new FilamentFabricatorManager();
        });
    }

What was the reason of going with scoped instead of singleton in the first place @Z3d0X?

@Z3d0X
Copy link
Owner

Z3d0X commented Jan 18, 2024

I don't think there was any specific reason for going with scoped instead of singleton.

If singleton works let's change to that. Thanks for investigating this issue.

@plunkettscott
Copy link
Author

@Z3d0X any idea when this will be tagged?

@Z3d0X
Copy link
Owner

Z3d0X commented Feb 3, 2024

v2.0.6 Released with #130

@Z3d0X Z3d0X closed this as completed Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants