Skip to content

[Live] Do not re-render <input file> if input holds unuploaded files #323

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

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-turbo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
php-versions: ['7.3', '7.4', '8.0']
fail-fast: false
name: PHP ${{ matrix.php-versions }} Test on ubuntu-latest

Expand Down
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