From 35246f20bed19b4d3455bc9cc2de08c47b45a785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Guimar=C3=A3es?= Date: Thu, 7 Aug 2025 17:32:36 -0300 Subject: [PATCH 1/2] add failing test --- tests/Feature/Middleware/InjectBoostTest.php | 25 ++++++++++++++++++++ tests/fixtures/injection-test.blade.php | 5 ++++ 2 files changed, 30 insertions(+) create mode 100644 tests/Feature/Middleware/InjectBoostTest.php create mode 100644 tests/fixtures/injection-test.blade.php diff --git a/tests/Feature/Middleware/InjectBoostTest.php b/tests/Feature/Middleware/InjectBoostTest.php new file mode 100644 index 00000000..047ee42c --- /dev/null +++ b/tests/Feature/Middleware/InjectBoostTest.php @@ -0,0 +1,25 @@ +app['view']->addNamespace('test', __DIR__.'/../../fixtures'); + + Route::get('injection-test', function () { + return view('test::injection-test'); + })->middleware(InjectBoost::class); + + $response = $this->get('injection-test'); + + $response->assertViewIs('test::injection-test'); + } +} diff --git a/tests/fixtures/injection-test.blade.php b/tests/fixtures/injection-test.blade.php new file mode 100644 index 00000000..2a46f3b9 --- /dev/null +++ b/tests/fixtures/injection-test.blade.php @@ -0,0 +1,5 @@ + + + foo + + From 3eeaff01bfce5f103162d61893a3be7bd58178fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Guimar=C3=A3es?= Date: Thu, 7 Aug 2025 17:37:49 -0300 Subject: [PATCH 2/2] preserve view --- src/Middleware/InjectBoost.php | 7 ++++++- tests/Feature/Middleware/InjectBoostTest.php | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Middleware/InjectBoost.php b/src/Middleware/InjectBoost.php index d3ec6c22..d82e8cb2 100644 --- a/src/Middleware/InjectBoost.php +++ b/src/Middleware/InjectBoost.php @@ -6,6 +6,7 @@ use Closure; use Illuminate\Http\Request; +use Illuminate\View\View; use Laravel\Boost\Services\BrowserLogger; use Symfony\Component\HttpFoundation\Response; @@ -13,13 +14,17 @@ class InjectBoost { public function handle(Request $request, Closure $next): Response { - // \Illuminate\Http\JsonResponse /** @var \Symfony\Component\HttpFoundation\Response $response */ $response = $next($request); if ($this->shouldInject($response->getContent())) { + $originalView = $response->original ?? null; $injectedContent = $this->injectScript($response->getContent()); $response->setContent($injectedContent); + + if ($originalView instanceof View) { + $response->original = $originalView; + } } return $response; diff --git a/tests/Feature/Middleware/InjectBoostTest.php b/tests/Feature/Middleware/InjectBoostTest.php index 047ee42c..fccea392 100644 --- a/tests/Feature/Middleware/InjectBoostTest.php +++ b/tests/Feature/Middleware/InjectBoostTest.php @@ -10,7 +10,7 @@ class InjectBoostTest extends TestCase { - public function test_it_maintains_the_original_view_response_type(): void + public function test_it_preserves_the_original_view_response_type(): void { $this->app['view']->addNamespace('test', __DIR__.'/../../fixtures'); @@ -20,6 +20,8 @@ public function test_it_maintains_the_original_view_response_type(): void $response = $this->get('injection-test'); - $response->assertViewIs('test::injection-test'); + $response->assertViewIs('test::injection-test') + ->assertSee('browser-logger-active') + ->assertSee('Browser logger active (MCP server detected).'); } }