archtechx / tenancy

Automatic multi-tenancy for Laravel. No code changes needed.
https://tenancyforlaravel.com
MIT License
3.67k stars 432 forks source link

3.8.3 ViteBundler incompatibility with Laravel 9 #1223

Closed vikasiwp closed 6 months ago

vikasiwp commented 6 months ago

Bug description

Started getting 500 error when updated packages to 3.8.3

[Fri May 17 12:09:49.839792 2024] [proxy_fcgi:error] [pid 540374:tid 140198747334400] [client 143.244.87.125:0] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught ErrorException: Undefined property: Stancl\Tenancy\Vite::$assetPathResolver in /path/to/your/project/vendor/stancl/tenancy/src/Vite.php:18\nStack trace:\n#0 /path/to/your/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(270): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()\n#1 /path/to/your/project/vendor/stancl/tenancy/src/Vite.php(18): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()\n#2 /path/to/your/project/vendor/laravel/framework/src/Illuminate/Foundation/Vite.php(283): Stancl\Tenancy\Vite->assetPath()\n#3 /path/to/your/project/storage/framework/views/0d81735404e0982d099e7a1fe299815bfe173fc9.php(17): Illuminate\Foundation\Vite->invoke()\n#4 /path/to/your/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(270): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()\n#1 /path/to/your/project/vendor/stancl/tenancy/src/Vite.php(18): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()\n#2 /path/to/your/project/vendor/laravel/framework/src/Illuminate/Foundation/Vite.php(283): Stancl\Tenancy\Vite->assetPath()\n#3 /path/to/your/project/storage/framework/views/0d81735404e0982d099e7a1fe299815bfe173fc9.php(17): Illuminate\Foundation\Vite->invoke()\n#4 /path/to/your/project/vendor/laravel/framework/src/Illuminate/Foundation/Vite.php(283): Stancl\Tenancy\Vite->assetPath()\n#3 /path/to/your/project/storage/framework/views/0d81735404e0982d099e7a1fe299815bfe173fc9.php(17): Illuminate\Foundation\Vite->__invoke()\n#4 /path/to/your/project/...'

Steps to reproduce

Unknown at the moment, we use multi-tenancy and just upgraded the composer package without any code changes.

Expected behavior

No error.

Laravel version

9

stancl/tenancy version

3.8.3

stancl commented 6 months ago

Can you test the following patch?

diff --git a/vendor/stancl/tenancy/src/Vite.php b/vendor/stancl/tenancy/src/Vite.php
index 1464e3a3..91ab9aad 100644
--- a/vendor/stancl/tenancy/src/Vite.php
+++ b/vendor/stancl/tenancy/src/Vite.php
@@ -15,6 +15,9 @@ class Vite extends BaseVite // todo move to a different directory in v4
      */
     protected function assetPath($path, $secure = null)
     {
-        return $this->assetPathResolver ? ($this->assetPathResolver)($path, $secure) : global_asset($path);
+        // In Laravel 9, the property doesn't exist.
+        return (isset($this->assetPathResolver) && $this->assetPathResolver)
+            ? ($this->assetPathResolver)($path, $secure)
+            : global_asset($path);
     }
 }

1221_fix.patch

lynexer commented 6 months ago

The above patch does fix the issue within Laravel 9.

stancl commented 6 months ago

Thanks for the confirmation, tagging a release now.