From e716481794ddc3f67eca6cf8ce7a6bdea6d1ae07 Mon Sep 17 00:00:00 2001 From: Josh Hanley Date: Wed, 25 Feb 2026 10:25:08 +1000 Subject: [PATCH 1/5] Improve `FluxServiceProvider` boot performance --- src/AssetManager.php | 9 +++++ src/FluxServiceProvider.php | 76 ++++++++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/AssetManager.php b/src/AssetManager.php index 72869746..c6d6d2c5 100644 --- a/src/AssetManager.php +++ b/src/AssetManager.php @@ -16,6 +16,15 @@ static function boot() $instance->registerAssetRoutes(); } + static function bootRoutes() + { + Route::get('/flux/flux.js', [static::class, 'fluxJs']); + Route::get('/flux/flux.min.js', [static::class, 'fluxMinJs']); + Route::get('/flux/editor.css', [static::class, 'editorCss']); + Route::get('/flux/editor.js', [static::class, 'editorJs']); + Route::get('/flux/editor.min.js', [static::class, 'editorMinJs']); + } + public function registerAssetDirective() { Blade::directive('fluxScripts', function ($expression) { diff --git a/src/FluxServiceProvider.php b/src/FluxServiceProvider.php index db1d7648..f8dc9a50 100644 --- a/src/FluxServiceProvider.php +++ b/src/FluxServiceProvider.php @@ -21,64 +21,94 @@ public function register(): void public function boot(): void { - $this->bootComponentPath(); - $this->bootFallbackBlazeDirectivesIfBlazeIsNotInstalled(); - $this->bootTagCompiler(); - $this->bootMacros(); + $this->callAfterResolving('blade.compiler', function ($blade) { + $this->bootComponentPath($blade); + $this->bootFallbackBlazeDirectivesIfBlazeIsNotInstalled($blade); + $this->bootTagCompiler($blade); + $this->bootAssetDirectives($blade); + }); + + AssetManager::bootRoutes(); - app('livewire')->propertySynthesizer(DateRangeSynth::class); + $this->app->booted(function () { + $this->bootMacros(); - AssetManager::boot(); + app('livewire')->propertySynthesizer(DateRangeSynth::class); - app('flux')->boot(); + app('flux')->boot(); + }); $this->bootCommands(); } - public function bootComponentPath() + public function bootComponentPath($blade) { if (file_exists(resource_path('views/flux'))) { - Blade::anonymousComponentPath(resource_path('views/flux'), 'flux'); + $blade->anonymousComponentPath(resource_path('views/flux'), 'flux'); } - Blade::anonymousComponentPath(__DIR__.'/../stubs/resources/views/flux', 'flux'); + $blade->anonymousComponentPath(__DIR__.'/../stubs/resources/views/flux', 'flux'); } - public function bootFallbackBlazeDirectivesIfBlazeIsNotInstalled() + public function bootFallbackBlazeDirectivesIfBlazeIsNotInstalled($blade) { - Blade::directive('blaze', fn () => ''); + $blade->directive('blaze', fn () => ''); // `@pure` directive has been replaced with `@blaze` in Blaze v1.0, but we need to keep it here for // backwards compatibility as people could have published components or custom icons using it... - Blade::directive('pure', fn () => ''); + $blade->directive('pure', fn () => ''); - Blade::directive('unblaze', function ($expression) { + $blade->directive('unblaze', function ($expression) { return '' . '<'.'?php $__getScope = fn($scope = []) => $scope; ?>' . '<'.'?php if (isset($scope)) $__scope = $scope; ?>' . '<'.'?php $scope = $__getScope('.$expression.'); ?>'; }); - Blade::directive('endunblaze', function () { + $blade->directive('endunblaze', function () { return '<'.'?php if (isset($__scope)) { $scope = $__scope; unset($__scope); } ?>'; }); } - public function bootTagCompiler() + public function bootTagCompiler($blade) { - $compiler = new FluxTagCompiler( - app('blade.compiler')->getClassComponentAliases(), - app('blade.compiler')->getClassComponentNamespaces(), - app('blade.compiler') - ); + $compiler = null; + + $this->app->bind('flux.compiler', function () use (&$compiler, $blade) { + return $compiler ??= new FluxTagCompiler( + $blade->getClassComponentAliases(), + $blade->getClassComponentNamespaces(), + $blade + ); + }); - app()->bind('flux.compiler', fn () => $compiler); + $blade->precompiler(function ($in) use (&$compiler, $blade) { + $compiler ??= new FluxTagCompiler( + $blade->getClassComponentAliases(), + $blade->getClassComponentNamespaces(), + $blade + ); - app('blade.compiler')->precompiler(function ($in) use ($compiler) { return $compiler->compile($in); }); } + public function bootAssetDirectives($blade) + { + $blade->directive('fluxScripts', function ($expression) { + return <<forceAssetInjection(); ?> + {!! app('flux')->scripts($expression) !!} + PHP; + }); + + $blade->directive('fluxAppearance', function ($expression) { + return <<fluxAppearance($expression) !!} + PHP; + }); + } + public function bootMacros() { app('view')::macro('getCurrentComponentData', function () { From 12fda57693e26f76085093bb666cc1d6cc5bc617 Mon Sep 17 00:00:00 2001 From: Josh Hanley Date: Wed, 25 Feb 2026 10:36:18 +1000 Subject: [PATCH 2/5] Remove duplicate `bootRoutes` method, call `registerAssetRoutes` directly --- src/AssetManager.php | 11 +---------- src/FluxServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/AssetManager.php b/src/AssetManager.php index c6d6d2c5..af24b06b 100644 --- a/src/AssetManager.php +++ b/src/AssetManager.php @@ -16,16 +16,7 @@ static function boot() $instance->registerAssetRoutes(); } - static function bootRoutes() - { - Route::get('/flux/flux.js', [static::class, 'fluxJs']); - Route::get('/flux/flux.min.js', [static::class, 'fluxMinJs']); - Route::get('/flux/editor.css', [static::class, 'editorCss']); - Route::get('/flux/editor.js', [static::class, 'editorJs']); - Route::get('/flux/editor.min.js', [static::class, 'editorMinJs']); - } - - public function registerAssetDirective() +public function registerAssetDirective() { Blade::directive('fluxScripts', function ($expression) { return <<bootAssetDirectives($blade); }); - AssetManager::bootRoutes(); + (new AssetManager)->registerAssetRoutes(); $this->app->booted(function () { $this->bootMacros(); From c3cb7a635a6a872f55800e554ac3e622039a4547 Mon Sep 17 00:00:00 2001 From: Josh Hanley Date: Wed, 25 Feb 2026 10:37:02 +1000 Subject: [PATCH 3/5] Fix indentation in AssetManager --- src/AssetManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AssetManager.php b/src/AssetManager.php index af24b06b..72869746 100644 --- a/src/AssetManager.php +++ b/src/AssetManager.php @@ -16,7 +16,7 @@ static function boot() $instance->registerAssetRoutes(); } -public function registerAssetDirective() + public function registerAssetDirective() { Blade::directive('fluxScripts', function ($expression) { return << Date: Wed, 25 Feb 2026 10:44:43 +1000 Subject: [PATCH 4/5] Use static `AssetManager::bootDirectives()` and `AssetManager::bootRoutes()` --- src/AssetManager.php | 10 ++++------ src/FluxServiceProvider.php | 21 +++------------------ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/AssetManager.php b/src/AssetManager.php index 72869746..f82791aa 100644 --- a/src/AssetManager.php +++ b/src/AssetManager.php @@ -10,13 +10,11 @@ class AssetManager { static function boot() { - $instance = new static; - - $instance->registerAssetDirective(); - $instance->registerAssetRoutes(); + static::bootDirectives(); + static::bootRoutes(); } - public function registerAssetDirective() + static function bootDirectives() { Blade::directive('fluxScripts', function ($expression) { return <<bootComponentPath($blade); $this->bootFallbackBlazeDirectivesIfBlazeIsNotInstalled($blade); $this->bootTagCompiler($blade); - $this->bootAssetDirectives($blade); + + AssetManager::bootDirectives(); }); - (new AssetManager)->registerAssetRoutes(); + AssetManager::bootRoutes(); $this->app->booted(function () { $this->bootMacros(); @@ -93,22 +94,6 @@ public function bootTagCompiler($blade) }); } - public function bootAssetDirectives($blade) - { - $blade->directive('fluxScripts', function ($expression) { - return <<forceAssetInjection(); ?> - {!! app('flux')->scripts($expression) !!} - PHP; - }); - - $blade->directive('fluxAppearance', function ($expression) { - return <<fluxAppearance($expression) !!} - PHP; - }); - } - public function bootMacros() { app('view')::macro('getCurrentComponentData', function () { From 4115b247e573dab78dae16213c6930a4178b6f17 Mon Sep 17 00:00:00 2001 From: Josh Hanley Date: Wed, 25 Feb 2026 10:49:32 +1000 Subject: [PATCH 5/5] Remove directive call from `AssetManager::boot()` and make `registerAssetDirective` static --- src/AssetManager.php | 9 +++++---- src/FluxServiceProvider.php | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/AssetManager.php b/src/AssetManager.php index f82791aa..e6c5ae69 100644 --- a/src/AssetManager.php +++ b/src/AssetManager.php @@ -10,11 +10,12 @@ class AssetManager { static function boot() { - static::bootDirectives(); - static::bootRoutes(); + $instance = new static; + + $instance->registerAssetRoutes(); } - static function bootDirectives() + public static function registerAssetDirective() { Blade::directive('fluxScripts', function ($expression) { return <<bootFallbackBlazeDirectivesIfBlazeIsNotInstalled($blade); $this->bootTagCompiler($blade); - AssetManager::bootDirectives(); + AssetManager::registerAssetDirective(); }); - AssetManager::bootRoutes(); + AssetManager::boot(); $this->app->booted(function () { $this->bootMacros();