-
-
Notifications
You must be signed in to change notification settings - Fork 177
fix: Wait for upload and refresh the view afterwards #7252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v5/develop
Are you sure you want to change the base?
Conversation
@bastianallgeier Still doesn't work :( |
That's very weird. Works perfectly for me now. Ok, then I need to double-check again. |
It does work for me. @afbora sure there aren't any old files cached, e.g. in |
@distantnative I'm testing always via |
@afbora Very weird. Any insights on the preconditions to have it succeed vs. when it fails? |
@distantnative I can reproduce it with every request via browser's slow 4G or 3G network throttling feature. Not sure but I think this content lost happens when pages/field/files request done after save request. |
@afbora You mention "save request" - so it's not just uploading what you are trying to do (as described in the original issue) but some combination with uploading and directly saving (and if you say slow connection, maybe you are trying to super quickly save before the upload request is actually done)? But then I would think this fix might still be right, but we have in addition still problems with a race condition between |
I mean |
Mmm ok. Couldn't reproduce it. Even when throttling speed. One thought could be if |
@distantnative Here the screencast: Kayit.2025-05-30.010557.mp4 |
I think our main issue really is the view reloading in the done event of the uploader. I have an idea. |
1e6d038
to
7300ab4
Compare
7300ab4
to
0c76efa
Compare
@distantnative @afbora I've refactored the code quite a bit and I hope this PR is not getting too big.
SandboxI've added a new "Others > Uploads" examples page where we can test textarea, structure, blocks and files fields with uploads and we can also see if a files section updates accordingly. |
@bastianallgeier I've tested now. There is restore selection issue at first glance. Click/select to random place of the paragraph text and try to drag/drop items to selected area. You can repeat this with selecting random places of the text with drag/drop an item. You'll see the issue that dragtexts are inserted always same places instead of selected area. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also experienced what @afbora writes. Not always consistently but multiple times the selection would e.g. not be restored when canceling an upload or other dialog.
I think the issue is that the selectionRange
gets stored inside the computed property. But the computed property actually does not get refreshed each time the selection changes. So it ends up restoring always the first state when the computed property got generated.
Co-authored-by: Nico Hoffmann ෴. <me@nhoffmann.com>
7e84c0a
to
cbb1cf6
Compare
6c495a2
to
bb504ff
Compare
Your tests and comments made me realize that I had a logical issue in the way the selectionRange was stored but not updated when dialogs are opened. This makes no sense and leads to the issues that you describe. Then I realized that we can use the I've tested everything in Firefox, Chrome and Safari and it seems to run smoothly now, but I would want to wait for another round of tests from your side. |
@bastianallgeier I tried hundreds of times in different ways, but on one of my first attempts, the file disappeared once. Then I couldn't reproduce the problem again. I think it was cache related. So everything seems to be working fine 🎉 |
@afbora that's great. I think we should wait for another look from @distantnative before we give it a go. I guess it's ok if we put it into rc.4 |
Haven't had much chance to test it myself, but no further comments on the code and totally fine for me to have it merged if you two tested it successfully 👍 |
Changelog
Enhancements
TextareaInput.restoreSelection()
methodinsert
insertFile
insertUpload
prepend
toggle
wrap
file.upload.error
event for every file that could not be uploaded.upload.announce()
method, which sends the success notification andmodel.update
event after uploads have successfully completed.Fixes
panel.content.save()
now callspanel.content.cancelSaving()
to make sure that any old scheduled save requests are properly cancelled. This could have lead to potential race conditions before.FilesField
no longer sends unnecessaryfile.upload
andmodel.update
emitters after upload. Those lead to duplicate section reload requests so far. After uploads, thepanel.upload.done()
already takes care of reloading the current view and all its sections.TextareaInput.insertUpload()
method now usesawait panel.content.update()
to push text value changes directly to the changes API and to reload the view correctly. This fixes [v5] Uploading a file by dragging it over the textarea field doesn't work #7249file.upload
event directly when a file has been uploaded and passes the file object correctly. Before this change, the file.upload event was only called in the FilesField and FilesSection components when all uploads finished.upload.done()
andupload.cancel()
handlers now properly emit thecomplete
event if there are any completed uploads.Refactoring
TextareaInput.selectionRange
andTextareaInput.restoreSelection()
are used to replace the oldrestoreSelectionCallback
method in dialog events for better async control.FilesSection
. The upload module already takes care of the notifications and events.Deprecated
TextareaInput.restoreSelectionCallback()
UseTextareaInput.restoreSelection()
.Breaking changes
None
Sandbox
There's a new "Uploads" tab in the Textarea setup in the sandbox.
Ready?
For review team