Fix Content-Type case sensitivity and add Livewire wire:navigate support#53
Fix Content-Type case sensitivity and add Livewire wire:navigate support#53asamoahboateng wants to merge 2 commits intopanphp:mainfrom
Conversation
|
@nunomaduro Ping Pong ;) Nuno, can u please have a look at this. This should fix issue with #51 . |
|
@buddhaCode , unfortunatly @nunomaduro is most likely too busy to maintain this project, i have pointed this out 2 times in his live streams, first he said to do PR that is already done here and then he said he would look into it, that was maybe a month ago, but i see his deploying new projects and so on, so his probably just busy... quite a shame to be honest, this package does help me alot on my projects. Meanwhile i just make my own middleware, copy his middleware update it with this fix and register it... works as normal.. but annoying to add a middleware just for this every time on a new project... Hopefully he will pick up on this and other PRs soon, however doubt it hehe |
Fix Content-Type case sensitivity and add Livewire
wire:navigatesupportSummary
This PR fixes two issues that prevent Pan from working correctly in certain Laravel environments:
1. Content-Type header case sensitivity (Bug Fix)
The
InjectJavascriptLibrarymiddleware performed a strict equality check againsttext/html; charset=UTF-8(uppercase). However, Laravel's response objects returntext/html; charset=utf-8(lowercase) in many scenarios — particularly when using Blade views and Livewire full-page components. This caused the Pan JavaScript to never be injected into the page, silently breaking all analytics tracking.Before:
After:
The fix uses
str_starts_withto match anytext/htmlContent-Type regardless of charset casing or additional parameters, which is consistent with how browsers interpret the Content-Type header.2. Livewire
wire:navigatesupport (Enhancement)Pan's client-side JavaScript listened for Inertia's
inertia:startevent to reset impression tracking on page navigation, but had no equivalent listener for Livewire'swire:navigateSPA-style transitions. This meant that when usingwire:navigate, navigating between pages would not re-track impressions fordata-panelements on the new page.The fix adds a
livewire:navigatedevent listener that resets the impression, hover, and click tracking arrays and re-scans for visibledata-panelements — matching the existing behavior for Inertia navigation.Changes
src/Adapters/Laravel/Http/Middleware/InjectJavascriptLibrary.php— Usestr_starts_withfor case-insensitive Content-Type matchingresources/js/src/main.ts— Addlivewire:navigatedevent listener for SPA navigation supportresources/js/src/types.ts— AddlivewireNavigatedListenertoGlobalStatetyperesources/js/dist/pan.iife.js— Rebuilt compiled JavaScripttests/.../InjectJavascriptLibraryTest.php— Added test for lowercase charset Content-TypeREADME.md— Updated Livewire compatibility noteTest Plan
charset=utf-8text/plainContent-Typewire:navigate