Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function compileComponentTag(ComponentNode $node, ComponentSource $sou
$functionName = ($this->manager->isFolding() ? '__' : '_') . $hash;
[$attributesArrayString, $boundKeysArrayString, $originalKeysArrayString] = $this->compileAttributes($node);

$output = '<' . '?php $__blaze->ensureRequired(\'' . $source->path . '\', $__blaze->compiledPath.\'/'. $hash . '.php\'); ?>' . "\n";
$output = '<' . '?php $__blaze->ensureRequired(\'' . $source->path . '\', $__blaze->compiledPath.\'/'. $hash . '.php\', \'' . $functionName . '\'); ?>' . "\n";

if ($node->selfClosing) {
$output .= '<' . '?php $__blaze->pushData(' . $attributesArrayString . '); ?>' . "\n";
Expand Down
14 changes: 5 additions & 9 deletions src/Runtime/BlazeRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class BlazeRuntime
protected ?string $compiledPath = null;

protected array $paths = [];
protected array $required = [];
protected array $blazed = [];

protected array $dataStack = [];
Expand All @@ -39,11 +38,11 @@ public function __construct(
}

/**
* Compile a component if its source is newer than the cached output.
* Compile and require a component if its function is not yet defined.
*/
public function ensureRequired(string $path, string $compiledPath): void
public function ensureRequired(string $path, string $compiledPath, string $functionName): void
{
if (isset($this->required[$compiledPath])) {
if (function_exists($functionName)) {
return;
}

Expand All @@ -52,8 +51,6 @@ public function ensureRequired(string $path, string $compiledPath): void
}

require $compiledPath;

$this->required[$compiledPath] = true;
}

/**
Expand All @@ -77,10 +74,9 @@ public function resolve(string $component): string|false

$hash = Utils::hash($path);
$compiled = $this->getCompiledPath().'/'.$hash.'.php';
$functionName = '_'.$hash;

if (! isset($this->required[$path])) {
$this->ensureRequired($path, $compiled);
}
$this->ensureRequired($path, $compiled, $functionName);

return $hash;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ComparisonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
BLADE
));

test('aware nested', fn () => compare(<<<'BLADE'
<x-nested-aware type="number" />
BLADE
));

test('foldable aware', fn () => compare(<<<'BLADE'
<x-foldable.wrapper type="number">
<x-foldable.input-aware />
Expand Down
4 changes: 2 additions & 2 deletions tests/Compiler/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$hash = Utils::hash($path);

expect($compiled->render())->toEqualCollapsingWhitespace(join('', [
'<?php $__blaze->ensureRequired(\''. $path .'\', $__blaze->compiledPath.\'/'. $hash .'.php\'); ?> ',
'<?php $__blaze->ensureRequired(\''. $path .'\', $__blaze->compiledPath.\'/'. $hash .'.php\', \'_'. $hash .'\'); ?> ',
'<?php $__blaze->pushData([\'type\' => \'text\',\'disabled\' => $disabled]); ?> ',
'<?php _'. $hash .'($__blaze, [\'type\' => \'text\',\'disabled\' => $disabled], [], [\'disabled\'], [], $__this ?? (isset($this) ? $this : null)); ?> ',
'<?php $__blaze->popData(); ?>',
Expand Down Expand Up @@ -42,7 +42,7 @@
$hash = Utils::hash($path);

expect($compiled->render())->toEqualCollapsingWhitespace(join('', [
'<?php $__blaze->ensureRequired(\''. $path .'\', $__blaze->compiledPath.\'/'. $hash .'.php\'); ?> ',
'<?php $__blaze->ensureRequired(\''. $path .'\', $__blaze->compiledPath.\'/'. $hash .'.php\', \'_'. $hash .'\'); ?> ',
'<?php if (isset($__slots'. $hash .')) { $__slotsStack'. $hash .'[] = $__slots'. $hash .'; } ?> ',
'<?php if (isset($__attrs'. $hash .')) { $__attrsStack'. $hash .'[] = $__attrs'. $hash .'; } ?> ',
'<?php $__attrs'. $hash .' = [\'class\' => \'mt-8\']; ?> ',
Expand Down
2 changes: 1 addition & 1 deletion tests/Memoizer/MemoizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'<?php echo \Livewire\Blaze\Memoizer\Memo::get($blaze_memoized_key); ?>',
'<?php else : ?>',
'<?php ob_start(); ?>',
'<?php $__blaze->ensureRequired(\''. $path .'\', $__blaze->compiledPath.\'/'. $hash .'.php\'); ?> ',
'<?php $__blaze->ensureRequired(\''. $path .'\', $__blaze->compiledPath.\'/'. $hash .'.php\', \'_'. $hash .'\'); ?> ',
'<?php $__blaze->pushData([\'src\' => $user->avatar]); ?> ',
'<?php _'. $hash .'($__blaze, [\'src\' => $user->avatar], [], [\'src\'], [], $__this ?? (isset($this) ? $this : null)); ?> ',
'<?php $__blaze->popData(); ?>',
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/views/components/nested-aware.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@blaze

<x-input-aware />
Loading