From 539cb7706dcb27c6952049b5b21dea60e0f54a32 Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Wed, 19 Aug 2026 05:36:08 +0500 Subject: [PATCH 1/2] Fix @nocache TypeError when rendered outside a matched route --- src/StaticCaching/Middleware/Cache.php | 6 +++++- tests/StaticCaching/BladeDirectiveTest.php | 21 +++++++++++++++++++ .../blade/nocache-probe.blade.php | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/StaticCaching/BladeDirectiveTest.php create mode 100644 tests/StaticCaching/blade/nocache-probe.blade.php diff --git a/src/StaticCaching/Middleware/Cache.php b/src/StaticCaching/Middleware/Cache.php index a30938912c9..85816471a82 100644 --- a/src/StaticCaching/Middleware/Cache.php +++ b/src/StaticCaching/Middleware/Cache.php @@ -265,7 +265,11 @@ private function createLock($request): Lock public static function isBeingUsedOnCurrentRoute() { - return in_array(static::class, app('router')->gatherRouteMiddleware(request()->route())); + if (! $route = request()->route()) { + return false; + } + + return in_array(static::class, app('router')->gatherRouteMiddleware($route)); } private function outputRefreshResponse($request) diff --git a/tests/StaticCaching/BladeDirectiveTest.php b/tests/StaticCaching/BladeDirectiveTest.php new file mode 100644 index 00000000000..99d50dbb65f --- /dev/null +++ b/tests/StaticCaching/BladeDirectiveTest.php @@ -0,0 +1,21 @@ + 'half']); + + View::addLocation(__DIR__.'/blade'); + + $this->assertSame('

region

', trim(Blade::render('@nocache("nocache-probe")'))); + } +} diff --git a/tests/StaticCaching/blade/nocache-probe.blade.php b/tests/StaticCaching/blade/nocache-probe.blade.php new file mode 100644 index 00000000000..d298ee89038 --- /dev/null +++ b/tests/StaticCaching/blade/nocache-probe.blade.php @@ -0,0 +1 @@ +

region

From 6b64e38d93983f4d17705808c94cb324c75159fc Mon Sep 17 00:00:00 2001 From: Lazizbek Ergashev Date: Wed, 19 Aug 2026 05:40:47 +0500 Subject: [PATCH 2/2] Align nocache blade test with sibling naming and view-path conventions Rename BladeDirectiveTest to NocacheBladeTest to match the NocacheRouteTest/ NocacheTagsTest naming pattern in this directory, and use the existing bladeViewPaths DefineEnvironment pattern (from HalfMeasureStaticCachingTest) instead of an inline View::addLocation() call, which was the only such call in the test suite. --- ...ladeDirectiveTest.php => NocacheBladeTest.php} | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) rename tests/StaticCaching/{BladeDirectiveTest.php => NocacheBladeTest.php} (55%) diff --git a/tests/StaticCaching/BladeDirectiveTest.php b/tests/StaticCaching/NocacheBladeTest.php similarity index 55% rename from tests/StaticCaching/BladeDirectiveTest.php rename to tests/StaticCaching/NocacheBladeTest.php index 99d50dbb65f..7309d48166a 100644 --- a/tests/StaticCaching/BladeDirectiveTest.php +++ b/tests/StaticCaching/NocacheBladeTest.php @@ -3,19 +3,26 @@ namespace Tests\StaticCaching; use Illuminate\Support\Facades\Blade; -use Illuminate\Support\Facades\View; +use Orchestra\Testbench\Attributes\DefineEnvironment; use PHPUnit\Framework\Attributes\Test; use Tests\TestCase; -class BladeDirectiveTest extends TestCase +class NocacheBladeTest extends TestCase { #[Test] + #[DefineEnvironment('bladeViewPaths')] public function it_renders_the_view_inline_when_there_is_no_matched_route() { config(['statamic.static_caching.strategy' => 'half']); - View::addLocation(__DIR__.'/blade'); - $this->assertSame('

region

', trim(Blade::render('@nocache("nocache-probe")'))); } + + public function bladeViewPaths($app) + { + $app['config']->set('view.paths', [ + __DIR__.'/blade', + ...$app['config']->get('view.paths'), + ]); + } }