ReactUSWDS Version & USWDS Version:
"react": "^19.0.0",
"react-dom": "^19.0.0",
"@trussworks/react-uswds": "^10.0.2",
"@uswds/uswds": "^3.13.0",
"next": "^15.3.3",
Describe the bug
When reactStrictMode is enabled in NextJS, components are exercised by unloading and reloading (recurisvelyTraverseAndDoubleInvokeEffectsInDEV). The purpose of this behavior is to catch issues that will impact users on rapid navigation.
Enabling reactStrictMode while using a FileInput component causes the FileInput component to throw an error when a file is selected.
<FileInput id="importFile" name="importFile" />
Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs.
This error traces back to a line in the FilePreview component:
|
fileReaderRef.current.readAsDataURL(file) |
To Reproduce
Steps to reproduce the behavior:
- Create a NextJS project from a template.
- Enable
reactStrictMode in next.config.js.
- Add a
FileInput component.
- Run the application and select a file using the
FileInput component.
- Observe the error.
Expected behavior
File can be selected without throwing an error in reactStrcitMode.
Additional context
While the easiest way to replicate this issue is using NextJS's reactStrictMode, this bug represents a race condition that could affect any React application using the FileInput component.
ReactUSWDS Version & USWDS Version:
"react": "^19.0.0",
"react-dom": "^19.0.0",
"@trussworks/react-uswds": "^10.0.2",
"@uswds/uswds": "^3.13.0",
"next": "^15.3.3",
Describe the bug
When
reactStrictModeis enabled in NextJS, components are exercised by unloading and reloading (recurisvelyTraverseAndDoubleInvokeEffectsInDEV). The purpose of this behavior is to catch issues that will impact users on rapid navigation.Enabling
reactStrictModewhile using aFileInputcomponent causes theFileInputcomponent to throw an error when a file is selected.<FileInput id="importFile" name="importFile" />Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs.This error traces back to a line in the
FilePreviewcomponent:react-uswds/src/components/forms/FileInput/FilePreview.tsx
Line 29 in b25fd42
To Reproduce
Steps to reproduce the behavior:
reactStrictModeinnext.config.js.FileInputcomponent.FileInputcomponent.Expected behavior
File can be selected without throwing an error in
reactStrcitMode.Additional context
While the easiest way to replicate this issue is using NextJS's
reactStrictMode, this bug represents a race condition that could affect any React application using theFileInputcomponent.