-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Use URLSearchParams for parsing search params #357
Conversation
packages/router/src/util.js
Outdated
|
||
return [...searchParams.keys()].reduce((params, key) => ({ | ||
...params, | ||
[key]: searchParams.get(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is possible to do searchParams.getAll(key)
instead
Great suggestion! I wonder if there's a way to have Babel dictate the inclusion of the polyfill instead of including it directly. We'd like to end up allowing users to specify what browser support they want to satisfy and have all Redwood dependencies be transpiled for that specification, at which point Babel could make the decision of whether this polyfill was needed or not. @peterp curious what our latest thinking is on this. |
So according to Babel docs for preset-env we can enable Going to try this out and let you know how it works in practice. |
Ok, if Redwood is compiling router in userland using Babel, it will add the polyfill as it does in compiled version here: "use strict";
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
_Object$defineProperty(exports, "__esModule", {
value: true
});
exports.replaceParams = exports.validatePath = exports.parseSearch = exports.matchPath = exports.createNamedContext = void 0;
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/concat"));
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/keys"));
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/for-each"));
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator"));
var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/starts-with"));
var _keys2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/keys"));
var _urlSearchParams = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/url-search-params"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/slice")); |
cd0dcd5
to
5321675
Compare
Our CI Checks were not running for PRs from external, forked repos. See #358 [EDIT: master merged into PR, which trigger checks. Thanks!] Thanks in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, I just need to test it locally, and write a test to make sure. :)
…o mohsen--router-utils
Use URLSearchParams for parsing search params
URL search params is a lot more involved than simple split by
&
and making a a key/value pair from it. I noticed in the router an assumption is made that search params are not repeated. This PR does not fix the issue because this assumption goes deeper in the router. Instead, I've introduced standardURLSearchParasm
for parsing the search params which handles a lot of corner cases such as unicode and also allow us to get a list for repeated search arguments if we decided to support that.I've also updated comments in the util.js to use JSDoc so comments show up in hover in editors.
Also used
String.prototype.startsWith
instead ofpath[0]
for better readability.P.S. This is my first PR and you should expect a lot more contribution from me to come! I love how this project is set up and the decisions that are made are almost perfect! ❤️