Skip to content
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

Memory leak with email validation in zod forms #46

Closed
callmeberzerker opened this issue Sep 18, 2023 · 4 comments
Closed

Memory leak with email validation in zod forms #46

callmeberzerker opened this issue Sep 18, 2023 · 4 comments

Comments

@callmeberzerker
Copy link

callmeberzerker commented Sep 18, 2023

Current Behavior

The browser tab hangs and crashes

Expected Behavior

Email validation works

Steps To Reproduce

  1. basically start writing in the email field with characters and browser tab will grind to a halt (enter at least 50 characters)

Link to Reproduction / Stackblitz

https://stackblitz.com/edit/github-zxmrcw?file=src%2Froutes%2F%2Bpage.svelte,src%2Froutes%2F%2Blayout.svelte

More Information

I did some testing and this only happens when validating the email constraint -> and I have no running hypothesis why is that the case.

@huntabyte
Copy link
Member

Wow, this is definitely a weird one, especially considering it only occurs when validating the email constraint 🤔.

Does this happen when using Superforms by itself, or only when using it with Formsnap? If it was happening for all the validation cases then it would make more sense, but the fact that it's only happening for this one is peculiar.

@huntabyte
Copy link
Member

There's this issue here that might be related: colinhacks/zod#2580

@huntabyte
Copy link
Member

Going to close this as it isn't an issue with Formsnap itself, but rather an issue with Zod and complex email addresses.

As a solution in the meantime, you can stop using .email() and instead create your own custom one which someone recommended in another Zod issue regarding this:

const schema = z.object({
	email: z.regex(/^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/)
})

@callmeberzerker
Copy link
Author

Thank you so much! So weird that this is yet to be actionable by zod. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants