Skip to content

Commit

Permalink
fix: SSR bug with File constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgarciaesgi committed Feb 11, 2025
1 parent b56b096 commit cfc4fa0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/nuxt/test/fixtures/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<label class="inline-flex items-center">
<input
v-model="r$.$value.acceptTC"
data-testid="acceptTC-checkbox"
type="checkbox"
class="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 focus:ring-offset-0"
/>
Expand Down Expand Up @@ -106,6 +107,7 @@ interface Form {
eventType?: string;
details?: string;
acceptTC?: boolean;
eventFile: File;
}
const { r$ } = useRegle({ fullName: 'Hello' } as Form, {
Expand All @@ -129,6 +131,7 @@ const { r$ } = useRegle({ fullName: 'Hello' } as Form, {
$autoDirty: false,
required: withMessage(and(required, checked), 'You must accept the terms and conditions'),
},
eventFile: { required },
});
async function submit() {
Expand Down
4 changes: 4 additions & 0 deletions packages/nuxt/test/nuxt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ describe('Nuxt SSR', async () => {

it('renders the index page', async () => {
await expectNoClientErrors('/');

const page = await createPage('/');

expect(await page.getByTestId('acceptTC-checkbox').isVisible()).toBe(true);
});
});
4 changes: 2 additions & 2 deletions packages/shared/utils/isEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export function isEmpty(
if (value instanceof Date) {
// invalid date won't pass
return isNaN(value.getTime());
} else if (value instanceof File) {
} else if (value.constructor.name == 'File' || value.constructor.name == 'FileList') {
// empty files won't pass
return value.size > 0;
return (value as File).size > 0;
} else if (Array.isArray(value)) {
if (considerEmptyArrayInvalid) {
return value.length === 0;
Expand Down

0 comments on commit cfc4fa0

Please # to comment.