Skip to content

Switching version silently discards unsaved changes #5134

Description

@elias-ba

As a person editing a workflow, I want to be warned before my unsaved changes are thrown away, so that I do not lose work by clicking something that looked harmless.

Part of #4852 (Sandbox DevX epic).

What's broken

Switching to an older version in the editor destroys the collaborative document and takes any unsaved edits with it. No prompt, no toast, nothing. The change is gone.

This is live on staging now. It is not a consequence of anything in this epic, though the epic makes it easier to hit.

There is no protection anywhere. The editor has no beforeunload handler at all, so closing the tab or following a link loses uncommitted work just as quietly. Leaving for a sandbox does the same, because that is a hard browser navigation.

Why it happens

The editor knows perfectly well that there are unsaved changes. It computes them by comparing the saved workflow against the working document, and the header uses that to show the dirty indicator.

Nothing consults it before destroying the document. Changing version rewrites the URL, and the session provider tears the document down unconditionally when the room changes. The comparison that powers the indicator is never asked.

So the information is already there. It is the guard that is missing.

What to fix

Ask before discarding, wherever the document is about to be destroyed with unsaved work in it: switching version, viewing a run's version, leaving for a sandbox, and leaving the page.

The prompt should say what will be lost and offer to save first, rather than only offering to cancel. Saving is usually what the person wanted, and making them cancel, save, then repeat the original action is a poor exchange for a mistake we caused.

Leaving the page is the one case that has to use the browser's own dialog, which cannot be styled or offer to save. Everything in-app should use our own.

Worth deciding

Whether a read-only view counts. Pinning a version from a live workflow cannot have unsaved changes, because the document was never editable, so the guard should stay quiet there rather than nagging.

Acceptance criteria

  • Given unsaved changes, when I switch to another version, then I am asked before anything is discarded and can save first.
  • Given unsaved changes, when I open a run that pins an older version, then the same applies.
  • Given unsaved changes, when I leave for a sandbox, then the same applies.
  • Given unsaved changes, when I close the tab or navigate away, then the browser warns me.
  • Given no unsaved changes, then nothing prompts and switching stays instant.
  • Given a workflow I cannot edit, then no prompt appears, because there is nothing to lose.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      New Issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions