Skip to content

Commit

Permalink
do not re-render <input file> if input holds unuploaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed May 18, 2022
1 parent e3c248e commit 2ded2f2
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
* if two nodes are identical.
*/
export function normalizeAttributesForComparison(element: HTMLElement): void {
if (element.value) {
element.setAttribute('value', element.value);
} else if (element.hasAttribute('value')) {
element.setAttribute('value', '');
const isFileInput = element instanceof HTMLInputElement && element.type === 'file';

// don't add value attribute to file inputs
// if a file is selected, but then a re-render happens before it is
// uploaded, we do NOT want to add a value="" attribute because
// this would cause the input to re-render (without the attached file)
if (!isFileInput) {
if (element.value) {
element.setAttribute('value', element.value);
} else if (element.hasAttribute('value')) {
element.setAttribute('value', '');
}
}

Array.from(element.children).forEach((child: HTMLElement) => {
Expand Down

0 comments on commit 2ded2f2

Please sign in to comment.