Fix Content-Type case sensitivity and add Livewire wire:navigate support#53
Open
asamoahboateng wants to merge 2 commits intopanphp:mainfrom
Open
Fix Content-Type case sensitivity and add Livewire wire:navigate support#53asamoahboateng wants to merge 2 commits intopanphp:mainfrom
asamoahboateng wants to merge 2 commits intopanphp:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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