Preventing navigation if a workflow is running?

Hi all!

I’ve got a feature in my app which allows users to take notes directly to a Supabase field, and it saves with each keystroke (with a debounce of 500ms).

I’ve got a slightly rough bit of UI set up to make it clear that it’s still saving, but one user suggested making it so if you try to navigate away from the page before it has saved, there’s a browser popup saying “notes are still saving” or similar.

Is this possible?

You could have a variable saving that is set to true on focus and false on blur and then wait for that to be false before navigating. That wouldn’t stop browser refreshes and navigation tho

Here’s something similar Confirmation dialog on closing page

2 Likes

I think the simplest way is via an ‘On page unload’ workflow.

As Sam said, you could have some kind of ‘Is saving’ boolean variable that you set to true/false as needed.

Then, create an app level workflow that uses ‘On page unload’ as the trigger and inside the workflow have a while loop that watches for whether the ‘Is saving’ variable is true. Basically, it means it won’t navigate away from the page until ‘Is saving’ is false.

I added a time delay in the loop to help ease how much performance the loop uses :backhand_index_pointing_down:

2 Likes

Thanks both! Going to play around with this solution - feels like something that needs a bit of UX thinking alongside the implementation.

1 Like

This topic was automatically closed after 75 days. New replies are no longer allowed.