You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently trying to use this library for isomporphic form validation/rendering. However, this lifted my (uncompressed) JS size from ~700kb to 3.1mb.
After removing formidable, async and qs as dependencies (formidable has the largest contribution), and leaving the server implementation to parse form data, my bundle size is sitting at around 900kb. You can see the fork here
You could also remove the dependencies on shims (object-keys, is, object.assign, string.prototype.trim), if you just specified that people who want support for older browsers/runtimes need to include polyfills themselves.
That will result in zero dependencies with almost no loss in functionality. The changes being:
You have to parse the form data before handing it over
You have to polyfill JS features that aren't available
I know legacy support is an important feature for this library, as is ease of "plug and play" use, so I wanted to see if there was any interest in reducing dependencies.
Everybody should be supporting older browsers/runtimes, so I won't be removing any of the shims - also, "zero dependencies" is not a good metric to shoot for. More deps are better.
I'd be interested in refactoring to avoid uses of async, but forms is primarily meant for node, not the browser - fwiw, there is https://www.npmjs.com/package/browser-forms (I'm not sure of its status).
Separately, if there's a way forms could be architected so that it can be used without formidable, and so that those who want the default behavior could somehow inject it, I'd be OK with that too.
Good to know what would line up with your opinions if I were to open a PR. Removing dependencies on formidable, qs and async is very straight-forward. If you change it so handle only accepts an ordinary JS object, and write two util functions to replace async.forEach and async.forEachSeries, you're done. The former only requires users to pass req.body, for example, instead of req. Naturally, this is a breaking change.
I disagree with your point that we should aim to support all older runtimes (I believe this is currently as far reaching as IE8/Node 0.4?). Or that more/less dependencies is strictly better than the other. Nonetheless, there is less to be gained with removing shims so I'll end the discussion there.
browser-forms is quite out of date (last published 4 years ago), so I'll opt for maintaining a fork at this stage.
Exploring write-once validation that works on the client and the server. There are some unique advantages to using the same language at both ends, let's try and make the most of it!
If forms is not meant for client-side usage, this line is pretty misleading
My hope would be to avoid a breaking change for as much of it as possible, and to make the breaking change for users who want the formidable behavior to be as minimal as possible.
forms is indeed meant for clientside usage but that hasn't been its primary use case, is all.
2f4ba3a has dropped the bundle size by 12% without any changes, so that's a start. #218 seems to drop bundle sizes an additional 4% (from 1.09MB to 1.05MB). Thus, I suspect async is not the biggest contributor.
Activity
ljharb commentedon Oct 29, 2016
Everybody should be supporting older browsers/runtimes, so I won't be removing any of the shims - also, "zero dependencies" is not a good metric to shoot for. More deps are better.
I'd be interested in refactoring to avoid uses of
async, butformsis primarily meant for node, not the browser - fwiw, there is https://www.npmjs.com/package/browser-forms (I'm not sure of its status).Separately, if there's a way
formscould be architected so that it can be used withoutformidable, and so that those who want the default behavior could somehow inject it, I'd be OK with that too.Pinpickle commentedon Oct 29, 2016
Good to know what would line up with your opinions if I were to open a PR. Removing dependencies on
formidable,qsandasyncis very straight-forward. If you change it sohandleonly accepts an ordinary JS object, and write two util functions to replaceasync.forEachandasync.forEachSeries, you're done. The former only requires users to passreq.body, for example, instead ofreq. Naturally, this is a breaking change.I disagree with your point that we should aim to support all older runtimes (I believe this is currently as far reaching as IE8/Node 0.4?). Or that more/less dependencies is strictly better than the other. Nonetheless, there is less to be gained with removing shims so I'll end the discussion there.
browser-formsis quite out of date (last published 4 years ago), so I'll opt for maintaining a fork at this stage.Pinpickle commentedon Oct 29, 2016
One more point, the readme has this line:
If
formsis not meant for client-side usage, this line is pretty misleadingljharb commentedon Oct 29, 2016
My hope would be to avoid a breaking change for as much of it as possible, and to make the breaking change for users who want the formidable behavior to be as minimal as possible.
formsis indeed meant for clientside usage but that hasn't been its primary use case, is all.ljharb commentedon Mar 10, 2020
I'm still happy to accept a PR that removes the
asyncdependency.voxpelli commentedon Jan 19, 2021
asyncgets removed as part of #218ljharb commentedon Jan 20, 2021
2f4ba3a has dropped the bundle size by 12% without any changes, so that's a start. #218 seems to drop bundle sizes an additional 4% (from 1.09MB to 1.05MB). Thus, I suspect
asyncis not the biggest contributor.