From c48507ec736df779a9bc2561584d87ebdd301886 Mon Sep 17 00:00:00 2001 From: lazerg Date: Sat, 7 Nov 2026 17:55:30 +0500 Subject: [PATCH 1/2] Reset interpolated variables between requests --- .../Language/Runtime/GlobalRuntimeState.php | 1 + tests/View/StateTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/View/Antlers/Language/Runtime/GlobalRuntimeState.php b/src/View/Antlers/Language/Runtime/GlobalRuntimeState.php index b60ce9abb10..e2d9ab9b038 100644 --- a/src/View/Antlers/Language/Runtime/GlobalRuntimeState.php +++ b/src/View/Antlers/Language/Runtime/GlobalRuntimeState.php @@ -290,6 +290,7 @@ public static function resetGlobalState() self::$tracedRuntimeAssignments = []; self::$traceTagAssignments = false; self::$environmentId = StringUtilities::uuidv4(); + self::$interpolatedVariables = []; self::$yieldCount = 0; self::$yieldStacks = []; self::$abandonedNodes = []; diff --git a/tests/View/StateTest.php b/tests/View/StateTest.php index ca626c5731f..c83a83e8fbc 100644 --- a/tests/View/StateTest.php +++ b/tests/View/StateTest.php @@ -2,6 +2,7 @@ namespace Tests\View; +use Statamic\View\Antlers\Language\Runtime\GlobalRuntimeState; use Statamic\View\Antlers\Language\Utilities\StringUtilities; use Tests\FakesContent; use Tests\FakesViews; @@ -50,6 +51,26 @@ public function test_tag_state_is_cleared_between_responses() $this->assertSame($expected, $resultThree); } + public function test_interpolated_variables_are_cleared_between_responses() + { + $this->withFakeViews(); + $this->viewShouldReturnRaw('layout', '{{ template_content }}'); + $this->viewShouldReturnRaw('default', '{{ link to="/pages/{slug}" }}{{ if "{slug}" == "home" }} yes{{ /if }}'); + + $this->createPage('home', [ + 'with' => [ + 'title' => 'Home Page', + 'template' => 'default', + ], + ]); + + $this->assertSame('/pages/home yes', $this->getResponseContent('/home')); + $this->assertSame([], GlobalRuntimeState::$interpolatedVariables); + + $this->assertSame('/pages/home yes', $this->getResponseContent('/home')); + $this->assertSame([], GlobalRuntimeState::$interpolatedVariables); + } + protected function getResponseContent($uri) { $response = $this->get($uri)->assertStatus(200); From af5715f6e6e9de7d3b5e200758a4cfc4e98a4892 Mon Sep 17 00:00:00 2001 From: lazerg Date: Sat, 7 Nov 2026 17:59:14 +0500 Subject: [PATCH 2/2] Assert interpolation still works after reset --- tests/View/StateTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/View/StateTest.php b/tests/View/StateTest.php index c83a83e8fbc..2d725b06626 100644 --- a/tests/View/StateTest.php +++ b/tests/View/StateTest.php @@ -55,19 +55,20 @@ public function test_interpolated_variables_are_cleared_between_responses() { $this->withFakeViews(); $this->viewShouldReturnRaw('layout', '{{ template_content }}'); - $this->viewShouldReturnRaw('default', '{{ link to="/pages/{slug}" }}{{ if "{slug}" == "home" }} yes{{ /if }}'); + $this->viewShouldReturnRaw('default', '{{ link to="/pages/{slug}" }} {{ num | add:{num} }}'); $this->createPage('home', [ 'with' => [ 'title' => 'Home Page', + 'num' => 3, 'template' => 'default', ], ]); - $this->assertSame('/pages/home yes', $this->getResponseContent('/home')); + $this->assertSame('/pages/home 6', $this->getResponseContent('/home')); $this->assertSame([], GlobalRuntimeState::$interpolatedVariables); - $this->assertSame('/pages/home yes', $this->getResponseContent('/home')); + $this->assertSame('/pages/home 6', $this->getResponseContent('/home')); $this->assertSame([], GlobalRuntimeState::$interpolatedVariables); }