statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.7k stars 508 forks source link

Autosave dropping characters being input at the moment of each autoave #10513

Open steveparks opened 1 month ago

steveparks commented 1 month ago

Bug description

When typing into an entry with Autosave enabled, the cursor regularly jumps back a few characters at the point of each sutosave, losing the characters that were being typed at that point.

It seems that autosave is reloading the text as it was at the moment it was autosaved a fraction of a second before, and so anything that was typed in between the autosave and that reload gets dropped.

Have added a screen recording below.

I'm aware Autosave is an experimental feature, so am reporting in the hope of being able to help troubleshoot and improve it ready for primetime.

Options to address the issue:

  1. Don't reload the content after autosave. Just leave the display as it is, saving only in the background.
  2. Only save when detecting a pause in typing, rather than on a regular time basis

Additionally, when editing content locally with npm run dev active, autosave triggers a full reload of the page with every autosave. I guess this is because of the change to the file for the entry. That may not be possible to avoid, so may just need to be documented.

How to reproduce

Enable autosave in /config/statamic/autosave.php, plus in the json config files for a collection (as described in autosave.php).

Go to the main text entry field on an entry edit form for that collection. Type an article as a normal content creator would.

Logs

No response

Environment

Environment
Application Name: Convivio
Laravel Version: 11.17.0
PHP Version: 8.3.9
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: convivio.test
Maintenance Mode: OFF
Timezone: Europe/London
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Livewire
Livewire: v3.5.4

Statamic
Addons: 11
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.17.0 PRO

Statamic Addons
goldnead/statamic-toc: 1.5
jonassiewertsen/statamic-livewire: 3.6.0
mitydigital/feedamic: 2.4.1
statamic/wikilinks: 2.1.0
stillat/relationships: 2.2.1
studio1902/statamic-peak-browser-appearance: 3.5.0
studio1902/statamic-peak-commands: 8.4.0
studio1902/statamic-peak-seo: 8.15.3
studio1902/statamic-peak-tools: 6.3.0
tv2regionerne/statamic-passport: 1.4.1
tv2regionerne/statamic-private-api: 1.15.0

Installation

Fresh statamic/statamic site via CLI

Additional details

https://github.com/user-attachments/assets/ac1e72ba-846b-4330-8988-62a3212bd6fa

duncanmcclean commented 1 month ago

Does this happen in all fieldtypes, or just Bard?

steveparks commented 1 month ago

Good question. I just tried it in a markdown field and the behaviour is slightly different.

In the markdown field it drops fewer characters and puts the cursor back to the start of the block of text that was just saved.

Screen recording attached...

https://github.com/user-attachments/assets/3422606e-80dd-46cf-87ad-a11920877cc9

godismyjudge95 commented 1 month ago

I believe this is due to the PublishForm resetting the values after every save - https://github.com/statamic/cms/blob/5.x/resources/js/components/entries/PublishForm.vue#L607

Not sure why this is done, unless it's a multi-user editing the same content thing. Perhaps the solution is to keep track of which field is in focus and don't reset that field?