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

Tenant Pages Livewire Component Error #12837

Closed
dev-idkwhoami opened this issue May 17, 2024 · 1 comment · Fixed by #12844
Closed

Tenant Pages Livewire Component Error #12837

dev-idkwhoami opened this issue May 17, 2024 · 1 comment · Fixed by #12844
Labels

Comments

@dev-idkwhoami
Copy link
Contributor

dev-idkwhoami commented May 17, 2024

Package

filament/filament

Package Version

v3.2.80

Laravel Version

v11.7.0

Livewire Version

v^3.4.10

PHP Version

PHP 8.3.6

Problem description

When trying to submit a form on a tenant page it throws a ComponentNotFoundException and tries to render a view that just doesn't exist.

Expected behavior

The form submission should run the appropiate functions without exception.

Steps to reproduce

Clone the Reproduction repo then run the following commands

composer install
npm install
php artisan migrate --seed

Here are the examples and how to replicate the problem:

  1. Non-Plugin Tenant Profile Page

    • Navigate to $APP_URL/nonplugin login if not already done. In the top left expand tenant dropdown menu and click on Non Plugin Profile

    nonplugin_tenant_profile.png

    • Now click on Save changes and error will be thrown.

    nonplugin_tenant_profile_error.png

  2. Plugin Tenant Profile Page

    • Navigate to $APP_URL/admin login if not already done. In the top left expand tenant dropdown menu and click on Plugin Profile

    plugin_tenant_profile.png

    • Now click on Save changes and error will be thrown.

    plugin_tenant_profile_error.png

  3. Non Plugin Tenant Registration Page

    • Navigate to $APP_URL/nonplugin/new login if not already done.

    nonplugin_tenant_register.png

    • Click on Non Plugin Register and an error will be thrown.

    nonplugin_tenant_register_error.png

Reproduction repository

https://github.com/dev-idkwhoami/filament-livewire-form-on-tenant-profile-page

Relevant log output

No response

@dev-idkwhoami
Copy link
Contributor Author

In Livewire ComponentRegistry.php the function nameToClass

protected function nameToClass($name)
    {
        // Check the aliases...
        if (isset($this->aliases[$name])) {
            if (is_object($this->aliases[$name])) return $this->aliases[$name]::class;

            return $this->aliases[$name];
        }

        // Hash check the non-aliased classes...
        foreach ($this->nonAliasedClasses as $class) {
            if (crc32($class) === $name) {
                return $class;
            }
        }
        $generatedClass = $this->generateClassFromName($name);

        /*
         * This prevents submission issues on Filament Tenant Pages.
         * No idea why ?
         * Maybe the page component is not registered correctly hence why livewire cant find the proper class and adds the App\Livewire\ at the front
         * 
         * Although this doesn't fix the issue itself its just the reason for the error.
         * The source has top be somewhere higher up the chain.
         * */
        if(str_starts_with($generatedClass, "\App\Livewire\App\Filament\Pages")) {
            $generatedClass = str_replace("\App\Livewire\App", 'App', $generatedClass);
        }

        // Reverse generate a class from a name...
        return $generatedClass;
    }

The above code is the reason why livewire throws an exception. It can't find the component classes.

In FilamentPHP HasComponents.php the function registerLivewireComponents

    // This works and was there already
    if ($this->hasLogin() && is_subclass_of($loginRouteAction = $this->getLoginRouteAction(), Component::class)) {
        $this->queueLivewireComponentForRegistration($loginRouteAction);
    }

    /*
     * The following three checks / registrations are missing right now. Seems so few people actually use this feature that nobody noticed you can't actually use it the intended way ^^
     * 
     * I will be making a PR for these 6 lines. I dont think it will break anything but who knows ^^
     * */
    if ($this->hasTenantRegistration() && is_subclass_of($tenantRegistrationComponent = $this->getTenantRegistrationPage(), Component::class)) {
        $this->queueLivewireComponentForRegistration($tenantRegistrationComponent);
    }

    if ($this->hasTenantProfile() && is_subclass_of($tenantProfileComponent = $this->getTenantProfilePage(), Component::class)) {
        $this->queueLivewireComponentForRegistration($tenantProfileComponent);
    }

    if ($this->hasProfile() && is_subclass_of($profilePageComponent = $this->getProfilePage(), Component::class)) {
        $this->queueLivewireComponentForRegistration($profilePageComponent);
    }

dev-idkwhoami added a commit to dev-idkwhoami/filament that referenced this issue May 17, 2024
dev-idkwhoami added a commit to dev-idkwhoami/filament that referenced this issue May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
2 participants
@dev-idkwhoami and others