## Description
<ins>Problem</ins>
onPageUnload functionality was not consistently triggered during all
types of page navigation in edit mode, leading to potential missed
cleanup or actions when navigating between pages via different UI
elements or programmatic flows.
<ins>Root cause</ins>
Navigation logic was fragmented across multiple components and methods
(button clicks, navigation tabs, page navigator), and direct history
manipulation bypassed centralized handling, preventing reliable
invocation of onPageUnload actions.
<ins>Solution</ins>
This PR handles the integration of onPageUnload functionality with all
page navigation flows in edit mode by centralizing navigation logic
through the navigateToAnotherPage action, enhancing type safety, and
ensuring onPageUnload actions are filtered and executed based on the
current page context.
Fixes#40998
_or_
Fixes `Issue URL`
> [!WARNING]
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._
## Automation
/ok-to-test tags="@tag.JS, @tag.Sanity"
### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢🟢🟢 All cypress tests have passed! 🎉🎉🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/16042398132>
> Commit: 8ea04e6bb1312d9f468ed3d74ccc080ed6e9bac9
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=16042398132&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JS, @tag.Sanity`
> Spec:
> <hr>Thu, 03 Jul 2025 06:44:33 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Enhanced page unload actions to only trigger for the current page,
improving accuracy and reliability.
* **Bug Fixes**
* Improved navigation consistency by updating the page switching
mechanism to use a unified action.
* **Tests**
* Added tests to ensure correct filtering of JavaScript actions executed
on page unload.
* **Refactor**
* Streamlined selector logic for better maintainability and performance.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->