Fix quote/job create page jumping to bottom on fresh load
The wizard scroll-restore saved scroll position on form submit but never cleared it if the server redirected to a success page. Next fresh visit to the same URL found the stale sessionStorage key and jumped down. Fix: track whether the page unload was caused by our own form submit. On pagehide for any other reason (nav link, success redirect), remove the key so it never fires on a clean page load. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -91,13 +91,23 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
ownerForm.addEventListener('submit', writeHiddenFields, { capture: true });
|
||||
|
||||
// Save scroll position before the form causes a full-page reload so we can
|
||||
// restore it after the server redirects back to this page. Key is path-specific
|
||||
// so navigating away and back doesn't restore a stale position.
|
||||
// restore it after the server redirects back to this page on a validation error.
|
||||
// Key is path-specific; cleared on pagehide unless we're leaving via a submit so
|
||||
// a fresh navigation to this page never restores a stale position.
|
||||
const scrollKey = 'wizardScrollY:' + location.pathname;
|
||||
let wizardSubmitting = false;
|
||||
ownerForm.addEventListener('submit', () => {
|
||||
wizardSubmitting = true;
|
||||
sessionStorage.setItem(scrollKey, String(Math.round(window.scrollY)));
|
||||
}, { capture: true });
|
||||
|
||||
// If the page unloads for any reason other than our own form submit (e.g. the
|
||||
// user clicks a nav link or the server redirects to a success page), discard the
|
||||
// saved position so it doesn't fire on the next fresh visit.
|
||||
window.addEventListener('pagehide', () => {
|
||||
if (!wizardSubmitting) sessionStorage.removeItem(scrollKey);
|
||||
});
|
||||
|
||||
// Restore on load — fire after layout is painted so scrollTo lands correctly.
|
||||
const savedY = sessionStorage.getItem(scrollKey);
|
||||
if (savedY !== null) {
|
||||
|
||||
Reference in New Issue
Block a user