From 004b9b6dbef87ea9ae6807d2e273715cd13ce95c Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Sun, 29 Mar 2026 12:14:36 +0200 Subject: [PATCH 1/2] Support View::share() variables in Blaze components Extract shared view data into the component scope so that variables registered via View::share() are accessible without manually calling $__env->shared('key'). Shared data is extracted after component data (EXTR_SKIP) so that props and slots always take priority over shared variables, matching Blade's array_merge($shared, $data) behavior. --- src/Compiler/Wrapper.php | 1 + tests/Compiler/WrapperTest.php | 2 ++ tests/IntegrationTest.php | 9 +++++++++ tests/fixtures/views/components/shared-var.blade.php | 3 +++ 4 files changed, 15 insertions(+) create mode 100644 tests/fixtures/views/components/shared-var.blade.php diff --git a/src/Compiler/Wrapper.php b/src/Compiler/Wrapper.php index 12484ec..cea10fb 100644 --- a/src/Compiler/Wrapper.php +++ b/src/Compiler/Wrapper.php @@ -67,6 +67,7 @@ public function wrap(string $compiled, string $path, ?string $source = null): st $output .= 'if (($__data[\'attributes\'] ?? null) instanceof \Illuminate\View\ComponentAttributeBag) { $__data = $__data + $__data[\'attributes\']->all(); unset($__data[\'attributes\']); }'."\n"; $output .= 'extract($__slots, EXTR_SKIP); unset($__slots);'."\n"; $output .= 'extract($__data, EXTR_SKIP);'."\n"; + $output .= 'extract($__env->getShared(), EXTR_SKIP);'."\n"; $output .= '$attributes = \\Livewire\\Blaze\\Runtime\\BlazeAttributeBag::make($__data, $__bound, $__keys);'."\n"; $output .= 'unset($__data, $__bound, $__keys);'."\n"; $output .= 'ob_start();' . "\n"; diff --git a/tests/Compiler/WrapperTest.php b/tests/Compiler/WrapperTest.php index 83c5089..1c0c492 100644 --- a/tests/Compiler/WrapperTest.php +++ b/tests/Compiler/WrapperTest.php @@ -18,6 +18,7 @@ 'if (($__data[\'attributes\'] ?? null) instanceof \Illuminate\View\ComponentAttributeBag) { $__data = $__data + $__data[\'attributes\']->all(); unset($__data[\'attributes\']); } ', 'extract($__slots, EXTR_SKIP); unset($__slots); ', 'extract($__data, EXTR_SKIP); ', + 'extract($__env->getShared(), EXTR_SKIP); ', '$attributes = \Livewire\Blaze\Runtime\BlazeAttributeBag::make($__data, $__bound, $__keys); ', 'unset($__data, $__bound, $__keys); ', 'ob_start(); ?> ', @@ -44,6 +45,7 @@ 'if (($__data[\'attributes\'] ?? null) instanceof \Illuminate\View\ComponentAttributeBag) { $__data = $__data + $__data[\'attributes\']->all(); unset($__data[\'attributes\']); } ', 'extract($__slots, EXTR_SKIP); unset($__slots); ', 'extract($__data, EXTR_SKIP); ', + 'extract($__env->getShared(), EXTR_SKIP); ', '$attributes = \Livewire\Blaze\Runtime\BlazeAttributeBag::make($__data, $__bound, $__keys); ', 'unset($__data, $__bound, $__keys); ', 'ob_start(); ?> ', diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index c63a08c..49cd338 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\View\Engine; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\View; use Illuminate\View\Component; use Livewire\Blaze\Blaze; use Livewire\Blaze\BlazeManager; @@ -85,6 +86,14 @@ public function render() })->assertSee('from-livewire'); }); +test('View::share variables are accessible in components', function () { + View::share('sharedValue', 'hello-from-share'); + + $html = Blade::render(''); + + expect($html)->toContain('hello-from-share'); +}); + test('folds and compiles the same component', function () { Blade::render(<<<'BLADE' {{-- Folded --}} diff --git a/tests/fixtures/views/components/shared-var.blade.php b/tests/fixtures/views/components/shared-var.blade.php new file mode 100644 index 0000000..5b6f98e --- /dev/null +++ b/tests/fixtures/views/components/shared-var.blade.php @@ -0,0 +1,3 @@ +@blaze + +{{ $sharedValue }} \ No newline at end of file From 72a1109a70a880ddddc12d963593ece37c5251ee Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Sun, 29 Mar 2026 12:14:53 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 5371a0e..a7f46ca 100644 --- a/README.md +++ b/README.md @@ -117,9 +117,6 @@ Blaze supports all essential features and produces HTML output identical to Blad - **Class-based components** are not supported - **The `$component` variable** is not available - **View composers / creators / lifecycle events** do not fire -- **Auto-injecting `View::share()` variables** is not supported - - Access shared data manually using `$__env->shared('key')` - **Cross boundary `@aware`** between Blade and Blaze Both parent and child must use Blaze for values to propagate