Only save forms if the browser window is visible

Created on 17 December 2024, about 1 month ago

Problem/Motivation

Nowadays users often have many browser windows open. Frequently saving un-changed forms can hurt performance.

Forms should only be saved, if the document is visible. This can be done with https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API and is supported by all mayor browsers.

This would be a nice feature to have.

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany breidert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @breidert
  • First commit to issue fork.
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    I proposed this on slack. I'm working on it.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    There's no way to create automatic test this. Hopefully we will adopt Playwright ( πŸ“Œ Consider dropping Nightwatch in favor of Functional Javascript tests Active ) that allows to use several sessions/tabs.

    For manually testing, configure autosave_form for nodes, go to edit a node, execute ddev . tail -f /var/log/nginx/access.log while playing with tab active/unactive.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    I can't see any reason this should be optional at all. But if maintainers disagree, could be based on a setting.

  • πŸ‡©πŸ‡ͺGermany breidert

    I am not sure if the approach is safe.

    If you switch windows before the next save interval (e.g. 60s), then your form is not saved.

    I think that you should first stop saving, if the document has been hidden longer than the interval. Then you are sure that the last change was saved.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    That makes a lot of sense.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί
  • πŸ‡©πŸ‡ͺGermany rvolk Frankfurt

    I like to recommend to also implement a checksum of the form values. If the checksum didn't change since the last safe event, we don't need to submit the request to the backend.

    For performance reasons the safe event should be triggered with the onchange event, plus on an interval when the user is active in the current window (e.g. typing in a long textarea doesn't trigger the onchange event unless the focus leaves the field, so we need to do it in a timely manner while he's typing). When the safe event is triggered, it must compare the checksum of the current form with the last submitted checksum. If the checksum didn't change, the safe request can be skipped. This would have the benefit to work with an active and inactive window, enhancing the proposed behaviour with an additional reduction of network load, avoiding to submit unchanged content.

    Once implemented, this makes the experimental feature "Run only on form change" obsolete.

  • πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

    I want to bring the attention also to πŸ› "Experimental" autosave on form change is enabled, but doesn't work. Active . Maybe if the experimental features gets working we do not need other features to prevent unnecessary submissions?

Production build 0.71.5 2024