Skip to content

Commit 4aa52b9

Browse files
chriscupasc.cupas
andauthored
Fix TypeError when Blade::getPath() returns null during view caching (#150)
* Fix TypeError when Blade::getPath() returns null during view caching Allow the path parameter in FragmentAlias::encode() to be nullable and handle null paths by defaulting to an empty string. This prevents TypeError when caching views with Volt components where the path is not available. * Fix PHPStan errors for Livewire internal classes Add ignoreErrors for ComponentRegistry class references that are internal to Livewire and not available during static analysis. * Register the layouts namespace for L4 compatible --------- Co-authored-by: c.cupas <c.cupas@tamkeentech.sa>
1 parent f3d3bc1 commit 4aa52b9

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ parameters:
66

77
ignoreErrors:
88
- "#Unsafe usage of new static\\(\\)#"
9+
- "#Class Livewire\\\\Mechanisms\\\\ComponentRegistry not found#"
10+
- "#Access to property \\$aliases on an unknown class Livewire\\\\Mechanisms\\\\ComponentRegistry#"

src/FragmentAlias.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class FragmentAlias
1212
/**
1313
* Encode the given fragment's component name and path into a base64 embedded alias.
1414
*/
15-
public static function encode(string $componentName, string $path, ?string $basePath = null): string
15+
public static function encode(string $componentName, ?string $path, ?string $basePath = null): string
1616
{
1717
$basePath = $basePath ?? static::$basePath ?? base_path();
1818

1919
return 'volt-anonymous-fragment-'.base64_encode(json_encode([
2020
'name' => $componentName,
21-
'path' => str_replace($basePath.DIRECTORY_SEPARATOR, '', $path),
21+
'path' => $path ? str_replace($basePath.DIRECTORY_SEPARATOR, '', $path) : '',
2222
]));
2323
}
2424

tests/Feature/ClassComponentTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
beforeEach(function () {
1111
View::setFinder(new FileViewFinder(app()['files'], [__DIR__.'/resources/views']));
1212

13+
View::addNamespace('layouts', __DIR__.'/resources/views/components/layouts');
14+
1315
Volt::mount([__DIR__.'/resources/views/class-api-pages', __DIR__.'/resources/views/class-api']);
1416
});
1517

tests/Feature/FunctionalComponentTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
beforeEach(function () {
2323
View::setFinder(new FileViewFinder(app()['files'], [__DIR__.'/resources/views']));
2424

25+
View::addNamespace('layouts', __DIR__.'/resources/views/components/layouts');
26+
2527
Volt::mount([__DIR__.'/resources/views/functional-api-pages', __DIR__.'/resources/views/functional-api'], [GlobalTrait::class]);
2628
});
2729

0 commit comments

Comments
 (0)