Problem/Motivation
Steps to reproduce
1. enable media, media_library core modules.
2. create a media field for a node type
3. set Media Library as a form widget for that media field
4. enable autosave for that node type, and for the easier testing, set 2000 as The interval to use for triggering autosave in milliseconds.
5. create a node with that type
5. edit that node and click to Add media on the media field and try to upload files there
Expected behavior:
After uploading the image files, media can be created there.
Actual behavior:
When the upload and the autosave happens at the same time, the upload stops, and the form widget is kinda stuck. Media is not created and I cannot retry the upload, I have to close the media library modal form, and again click to Add media. But even if I set "The interval to use for triggering autosave" to a higher number, then if I upload something just when the autosave AJAX call happens, it breaks the process again.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3208516-05-disable-autosave-during-file-upload.patch | 570 bytes | kaszarobert |
Comments
Comment #2
kaszarobertComment #3
hchonovAutosave should not be running while there is another element that is currently executing an AJAX request.
See
autosave_form.js:Could you please confirm that the issue occurs only while the form is autosaving and you start uploading a media? Could you also please post the responses from both AJAX requests? The one of the autosave request and the one of the media upload?
Comment #4
kaszarobertI encountered this problem with the Media Library form widget. But I can also confirm that it causes problems for Image or File fields, too, if I select a file to upload and right after that the Autosave happens, the file is not uploaded. But in case of File fields at least I can try the upload again. The Media Library's modal window doesn't work after the upload was unfinished, so I have to reopen it to make it work again.
When the Media Library upload starts, this AJAX call happens:
http://drupal9.localhost/web/media-library?media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bimage%5D=image&media_library_allowed_types%5Bvideo%5D=video&media_library_selected_type=image&media_library_remaining=1&media_library_opener_parameters%5Bfield_widget_id%5D=field_bevezeto_media&media_library_opener_parameters%5Bentity_type_id%5D=node&media_library_opener_parameters%5Bbundle%5D=article&media_library_opener_parameters%5Bfield_name%5D=field_bevezeto_media&media_library_opener_parameters%5Bentity_id%5D=50051&media_library_opener_parameters%5Brevision_id%5D=50051&hash=q9JNHga6rGfJdjAdhLUynnDi7dO5BRbSuyqgRftFogc&ajax_form=1&_wrapper_format=drupal_ajax&_wrapper_format=drupal_ajaxThe response is:
But even if the upload is not finished, the autosave_form's AJAX call does happen:
http://drupal9.localhost/web/node/50051/edit?destination=/web/admin/content&ajax_form=1&_wrapper_format=drupal_ajaxAnd then the response is:
If you look at the URLs, the Media Library widget uses a different callback URL than the autosave_form. Maybe the code that checks for AJAX calls should be updated in some way to check for those if possible?
Comment #5
kaszarobertI found a workaround: if the focused element is a file input (that also means someone clicked to the Browse button and right now the file dialog is open), then disable the autosave. That way the start of the file upload AJAX call and the autosave AJAX call cannot happen at the same time. The autosave will continue after the file upload is complete. I attach a patch for it.