Conversation
Co-authored-by: daveconco <111229272+daveconco@users.noreply.github.com>
Co-authored-by: daveconco <111229272+daveconco@users.noreply.github.com>
Copilot
AI
changed the title
Work on the template/src/index.js, that is the main javascript fioe that handles the SPA functionality of the library. Currently I am having issue with the navigating through browser history using that popstate, what you should fix there is, when navig...
Fix phpSPA navigation issues: improve history handling, add unload event, and enhance script execution stability
Sep 29, 2025
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.
This PR fixes several critical issues in the phpSPA JavaScript navigation system that were causing problems with browser history navigation and script execution stability.
Issues Fixed
1. History Navigation Fetching Issue
Previously, the
popstateevent handler would fetch new content from the server even when valid cached content existed inhistory.state. This caused unnecessary network requests and slower navigation.Before:
After:
2. JavaScript Execution Stability
The previous implementation cleared ALL executed scripts globally during navigation, which could break JavaScript functionality during complex navigation patterns (forward/backward sequences).
Before:
After:
3. Missing Event Lifecycle
The system was missing proper event emissions during browser history navigation and lacked an
unloadevent for cleanup.New event flow:
beforeload→unload→ content replacement → script execution →loadunloadevent that triggers before component removalloadevent4. Property Naming Inconsistency
Fixed inconsistency between
targetIdandtargetIDproperties while maintaining backward compatibility.Changes Made
clearContainerScripts()method for selective script clearing instead of global clearingunloadevent and ensured all navigation types emit proper lifecycle eventsDOMContentLoadednow triggers the phpSPAloadeventtargetIdwith backward compatibility fortargetIDTesting
All existing tests pass, confirming that the changes maintain backward compatibility while fixing the reported issues. The improvements specifically address:
API Additions
These changes ensure that phpSPA navigation works reliably across all scenarios while maintaining the existing API and behavior.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.