4 ms·
Oh dear god no. Form Validation is what JavaScript was meant for. Do we really need to download >1MB wasm module so you can do a regex? WASM should be left to
by reactordev 1y ago
Oh dear god no. Form Validation is what JavaScript was meant for. Do we really need to download >1MB wasm module so you can do a regex?
WASM should be left to things like IPC/Canvas/WebGPU stuff, not things easily done with document.querySelector
No offense, but this is using a bomb to kill a fly.
I know it says this is just a demo but people will find this and do this thinking it’s normal.
- milliams 1y agoI just compiled the code provided in the article and the compiled WASM module is 22kb. Not saying that it makes it the right solution, but a 45× difference is not insignificant.
- remram 1y agoBut the example code doesn't do much validation. If you did want to use a regex, you would have to compile and bundle the regex crate...
- littlestymaar 1y agoAnd what kind of form validation are you going to do with a regular expression? E-mail addresses like every other fool? (This is a the best to reject perfectly valid addresses because you baked unjustified assumptions in you regex)
- porridgeraisin 1y agoFor what it's worth, the inbuilt HTML5 validation that implementw input type=email does have a regex in the spec. https://html.spec.whatwg.org/#email-state-(type=email) https://html.spec.whatwg.org/#email-state-(type=email) /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ But it is true that you can implement it with a FSM(which is what firefox does). Webkit uses a regex as well I think.
- drowsspa 1y agoYeah, for all intents and purposes that's the spec for emails now
- littlestymaar 1y agoTIL thanks.
- zoechi 1y agoThe bigger and more complex the application, the less is the effect of this.
- remram 1y agoMe? None. I'm not the one proposing the use of Rust and WASM for form validation. What kind of validation are you going to do without a regular expression?
- littlestymaar 1y ago> What kind of validation are you going to do without a regular expression? Actual form validation… I can't even think of a single kind of form validation where a regex would help…
- 01HNNWZ0MV43FF 1y agoWith `regex-lite` I got under 100,000 bytes on the email regex in the sibling comment. Not great, not terrible.
- qoez 1y agoOnce you compile it to wasm and dead code analysis is applied and notices that only a fraction of whatever libraries you're using is necessary for form validation the code tends to be a lot less than what you'd have if you used non dead code analyzed pure JS.
- graypegg 1y agoWell, if we were implementing the equivalent in JS, we'd also use https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputEl... just like this. I think it would maybe be a few lines of javascript at most to do exactly what this is doing. 400ish bytes? Of course there's always the argument that you'd add more javascript to "framework-ize" this a bit more, but the rust code is just targeting the DOM with IDs, so I don't think it's fair to compare it to any "framework-y" solution.
- madduci 1y agoSame with some JavaScript frameworks. I need to download 700kb+ JS files just to perform some fancy stuff.
- timeon 1y agoAlso Tailwind. Obese HTML just to avoid css.
- jpdenford 1y agoThe author said the following > I’m using form validation as a placeholder. It shows all the crucial aspects to use WASM instead of JS, like wiring up DOM events to Rust functions, and then reacting to those events.
- _mlbt 1y agoYou can actually do a lot of form validation without even using JavaScript. HTML and CSS are capable of handling many common form validation needs... https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation https://developer.mozilla.org/en-US/docs/Learn_web_developme...