diff --git a/packages/dnb-eufemia/src/extensions/forms/Field/Upload/Upload.tsx b/packages/dnb-eufemia/src/extensions/forms/Field/Upload/Upload.tsx index b2ced390916..08dae3728d1 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Field/Upload/Upload.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Field/Upload/Upload.tsx @@ -118,7 +118,11 @@ function UploadComponent(props: Props) { const { files: fileContext, setFiles } = useUpload(id) useEffect(() => { - setFiles(value) + // Files stored in session storage will not have a property (due to serialization). + const hasInvalidFiles = value?.some(({ file }) => !file?.name) + if (!hasInvalidFiles) { + setFiles(value) + } }, [setFiles, value]) const handleChangeAsync = useCallback( diff --git a/packages/dnb-eufemia/src/extensions/forms/Field/Upload/__tests__/Upload.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Field/Upload/__tests__/Upload.test.tsx index fe53f07ca5b..97488363022 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Field/Upload/__tests__/Upload.test.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Field/Upload/__tests__/Upload.test.tsx @@ -1253,4 +1253,57 @@ describe('Field.Upload', () => { ) }) }) + + it('should not set files from session storage if they are invalid', async () => { + const file = createMockFile('fileName.png', 100, 'image/png') + + const { unmount } = render( +