Skip to content

Conversation

@revanth-banala
Copy link
Contributor

@revanth-banala revanth-banala commented Aug 13, 2025

Description

Phase 1 of offline form capabilities by implementing browser-based autosave that protects users from losing form progress
This PR introduces a browser-based autosave feature that protects users from losing form progress due to accidental browser closures, refreshes, or crashes. The feature stores form data locally in the browser's localStorage and provides a recovery dialog when users return to continue their work.
New Feature - Form progress protection via local autosave
Database Migration - Adds enableAutoSave column to form table
UI Enhancement - Recovery dialog and settings toggle

Changes Made
Core Features:

Local Autosave System (useLocalAutosave.js)
Debounced saving (3-second delay) to localStorage
Silent failure mode to prevent blocking form operations
Storage key based on formId, userId, versionId, submissionId
Automatic cleanup on successful submission

Recovery Dialog (LocalAutosaveRecoveryDialog.vue)
Prompts users to restore or discard locally saved progress
Only shows when local data is newer than server data

FormViewer Integration
Autosave triggers on form changes (excluding initial load)
Smart beforeunload warnings (suppressed when autosave is active)
Recovery check on component mount

Form Settings
New toggle: "Enable Form Progress Protection"
Database field: enableAutoSave (default: false)
Available in form functionality settings

Technical Implementation:

Storage format: chefs_autosave_[formId]:[userId]:[versionId]:[submissionId]
Data structure: { timestamp: ISO_STRING, data: formData }
Graceful handling of localStorage unavailability (private browsing, quota exceeded)

Low Risk (Safe Changes)
Feature is opt-in (disabled by default)
Silent failure mode prevents breaking existing functionality
Composable pattern for clean separation of concerns
Recovery dialog is non-blocking
Backward compatible database migration

Type of Change

feat (a new feature)

Checklist

  • I have read the CONTRIBUTING doc
  • I have checked that unit tests pass locally with my changes
  • I have run the npm script lint on the frontend and backend
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have approval from the product owner for the contribution in this pull request

Further comments

@revanth-banala revanth-banala marked this pull request as ready for review August 14, 2025 15:40
@nimya-aot
Copy link
Contributor

@revanth-banala When user goes offline in between filling the form, it shows outage screen first, then I had to refresh the page. Seems like after that all the data lost. Can you check that?
image

@sonarqubecloud
Copy link

Copy link
Contributor

@jasonchung1871 jasonchung1871 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the lack of telemetry/logging for auto-save and recovery intentional? If the feature misbehaves, we won't have much diagnostic data to work with. Users might report issues we can't trace.

We might want to add a warning or restrict auto-save for forms marked as sensitive. localStorage is global to the browser context, any script running on the page (including form.io components) could potentially access saved data. It's not a huge issue, but it does mean that someone could create a malicious form to grab form data from auto-save.

@nimya-aot
Copy link
Contributor

@revanth-banala One of the cypress test failed on this PR. When a submitter recall a submission, it still saving the old value in the input field, not the updated one. Could you please check?
image

@github-actions

This comment has been minimized.

Copy link
Contributor

@jasonchung1871 jasonchung1871 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my only concern left with this is for older computers that may be trying to autosave on a larger form. They could be saving still while autosave attempts to save again. This would need to increase the debounce delay.

Copy link
Collaborator

@usingtechnology usingtechnology left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature, looking forward to seeing it in action.

Minor tweaks (may affect your unit tests). 👍

@nimya-aot
Copy link
Contributor

@revanth-banala Please deploy again if recalling submission issue fixed.

@sonarqubecloud
Copy link

@usingtechnology usingtechnology self-requested a review November 26, 2025 19:36
Copy link
Collaborator

@usingtechnology usingtechnology left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Let's see how it works in the wild!

@usingtechnology usingtechnology merged commit 08fc85c into bcgov:main Nov 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants