Validate client-side that image size is a multiple of block size#3183
Validate client-side that image size is a multiple of block size#3183david-crespo wants to merge 3 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| control={form.control} | ||
| parseValue={(val) => parseInt(val, 10) as BlockSize} | ||
| // re-run imageFile validation when block size changes | ||
| rules={{ deps: ['imageFile'] }} |
There was a problem hiding this comment.
Omg. Claude is constantly teaching me about RHF features. wtf!
885fcad to
7b74789
Compare
7b74789 to
7982a32
Compare
charliepark
left a comment
There was a problem hiding this comment.
This works. There's a small bit of friction in that if you change the block size before you select an image (a reasonable situation to find yourself in, as the block size comes first in the form), it fires off the validator, which then complains that no image has been loaded.

Perhaps this isn't an issue, but I wanted to note it. I tried a few quick attempts to only conditionally make it required, but it was a bit messy and didn't feel like a better path.
|
Good catch, to me that is an issue. One simple approach would be to just remove the explicit dep and rely on it being checked on submit. It’s slightly worse than getting that immediate feedback when you change the block size when an image is present, but better than the spurious error. |
|
Do you have confidence that there's no edge cases here? You might consider a soft validation to allow a user to submit even if it's unlikely to work. |
I have no such confidence. |
|
@iliana or @augustuswm — thoughts on whether there are edge cases that mean we should make my |
|
I had the robot try to come up with edge cases that undermine the strict logic here. The only case it could come up with where this is technically stricter than we might want is if the last weird remainder block is all zeros. Because we skip sending all-zero blocks client-side anyway, you would be able to upload such an image with no issue — the unaligned last block would never be sent. This seems like a very unlikely scenario. |
See #1920 (comment). Easiest thing in the world to do. Without this, the user can sit there for half an hour uploading a giant image file and only find out on the very last block that it is invalid.