From db1222a53e64ce0faef7d2f6a43e5ad7a8519842 Mon Sep 17 00:00:00 2001 From: Jeremy-Z Date: Wed, 1 Jul 2026 12:53:29 -0400 Subject: [PATCH] Updated logic for initial savesession call to create referral. Move it to beforeEach to make it snchronous. --- src/helpers/order-helper.js | 1 + src/router/index.js | 20 +++++++++++++++++--- src/router/router.afterEach.spec.js | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/helpers/order-helper.js b/src/helpers/order-helper.js index 449f79b6..55a12a9d 100644 --- a/src/helpers/order-helper.js +++ b/src/helpers/order-helper.js @@ -26,6 +26,7 @@ export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitA // This should await anytime the referral number is not set, or the shouldAwaitSaveSessionQueue is set to true. if (!store.order.referralNumber || shouldAwaitSaveSessionQueue) { + console.log('Awaiting save session promise', store.order.referralNumber, shouldAwaitSaveSessionQueue); await saveSessionPromise; } } diff --git a/src/router/index.js b/src/router/index.js index 0c33cae4..6dfd0265 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -155,6 +155,19 @@ router.beforeEach(async (to, from) => { showIssLoadingModal(true); } + const callSaveSession = (to.name === issPageValues.VEHICLE_SELECTION || to.name === issPageValues.POLICY_VEHICLES); + if ( callSaveSession ) { + // Forcing a synchronous savesession call here to create the referral for the first time. + // AfterEach does not support synchronous calls that block navigation. Which is why this is in the beforeEach method. + // This only needs to be called once in a certain location, all other saveession calls are async in afterEach (except the last one on order submission) + // NOTE: This call should be creating the referral number. After this point in the site flow, referral number is critical for several pieces of logic and logging. + // Thereforce, we want to force a bailout here if it errors out. + console.log('Saving session with waiting coming from duplicate check page.'); + showIssLoadingModal(true); + await saveSession({ shouldAwaitSaveSessionQueue: true,bailoutOnError: true }); + showIssLoadingModal(false); + } + const toQueryPage = to.query?.issPage; const notToPayInAdvanceReturn = toQueryPage !== issPageValues.PAYMENT_RETURN; const isInIframe = window !== window.top || fromQueryPage === issPageValues.PAYMENT_PAGE; @@ -204,10 +217,11 @@ router.afterEach(async (to, from) => { to.state?.[routerParams.SKIP_SAVE_SESSION] ?? router.options.history.state?.[routerParams.SKIP_SAVE_SESSION] ); - if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) { - await saveSession({ bailoutOnError: from.name === issPageValues.ENTRY_PAGE}); - } + if (from.name !== undefined && !skipSaveSession && !store.hasSubmittedOrder()) { + await saveSession({ bailoutOnError: false}); + } + document.title = routerTitles[to.query.issPage] || 'Safelite Solutions®'; if (shouldRunExperiments) { diff --git a/src/router/router.afterEach.spec.js b/src/router/router.afterEach.spec.js index 2a2185dc..6f2aee8f 100644 --- a/src/router/router.afterEach.spec.js +++ b/src/router/router.afterEach.spec.js @@ -110,6 +110,6 @@ describe('Router afterEach skipSaveSession', () => { ); expect(saveSession).toHaveBeenCalledTimes(1); - expect(saveSession).toHaveBeenCalledWith({ bailoutOnError: true }); + expect(saveSession).toHaveBeenCalledWith({ bailoutOnError: false }); }); }); \ No newline at end of file