Fix #2040 - Inaccurate rendering during file upload #2241
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2040
The bug is caused by these lines (which I actually called out in #2174):
p5.js-web-editor/client/modules/IDE/actions/uploader.js
Line 111 in 1c05241
p5.js-web-editor/client/modules/IDE/actions/uploader.js
Lines 121 to 122 in 1c05241
Our intention is to insert an additional
input
into the form. But the way that we are implementing it is by replacing the entire content of the uploader with new elements parsed from the modified HTML string.The Dropzone library stores a reference to the
previewElement
associated with each file and modifies the CSS classes on this element at various points in the code. When our bad code gets executed for the first file all of thefile.previewElement
elements get removed from the DOM. Any subsequent changes to these elements will not change the HTML that we actually see.As a result, only the first file will get the "success" styles applied. The second file gets stuck on "processing" and the rest of the files never even get to the "processing" style.
Changes:
I removed the modification of
innerHTML
. Instead I am creating the input withdocument.createElement
and inserting it withappendChild
. This keeps the DOM intact.I had to dig way deep into this code in order to track down the cause of the bug and now that I understand it I do have some further improvements which I can make in future PRs.
I think it would be cleaner to render these hidden inputs via React in the FileUploader component, by storing the data to component state.I think we might not need the hidden inputs at all?I have verified that this pull request:
npm run lint
)npm run test
)develop
branch.Fixes #123