diff --git a/src/Unblaze.php b/src/Unblaze.php index 2fffbb3..418d879 100644 --- a/src/Unblaze.php +++ b/src/Unblaze.php @@ -22,6 +22,14 @@ public static function storeScope($token, $scope = []) static::$unblazeScopes[$token] = $scope; } + /** + * Store runtime replacement content for an @unblaze token. + */ + public static function storeReplacement(string $token, string $replacement) + { + static::$unblazeReplacements[$token] ??= base64_decode($replacement); + } + /** * Check if a template contains @unblaze directives. */ @@ -60,6 +68,7 @@ public static function processUnblazeDirectives(string $template) return '' . '[STARTCOMPILEDUNBLAZE:'.$token.']' . '<'.'?php \Livewire\Blaze\Unblaze::storeScope("'.$token.'", '.$expression.') ?>' + . '<'.'?php \Livewire\Blaze\Unblaze::storeReplacement("'.$token.'", "'.base64_encode($innerContent).'") ?>' . '[ENDCOMPILEDUNBLAZE:'.$token.']'; }, $result); diff --git a/tests/Folder/UnblazeTest.php b/tests/Folder/UnblazeTest.php index bdc7c90..df0823b 100644 --- a/tests/Folder/UnblazeTest.php +++ b/tests/Folder/UnblazeTest.php @@ -1,9 +1,13 @@ Artisan::call('view:clear')); test('compiles unblaze blocks', function () { $input = ''; @@ -52,3 +56,19 @@ ])) ); }); + +test('processes replacements in compiled files', function () { + $path = fixture_path('views/components/foldable/input-unblaze.blade.php'); + $node = app(Parser::class)->parse('')[0]; + + // Force compilation and store replacements... + $before = app(BladeRenderer::class)->render($node, $path); + + // Flush replacements to simulate a separate process... + Unblaze::flushState(); + + // Ensure we can restore replacements from the compiled file... + $after = app(BladeRenderer::class)->render($node, $path); + + expect($before)->toBe($after); +});