-
Notifications
You must be signed in to change notification settings - Fork 22
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
consider exposing URLPatternList #30
Comments
FWIW, the use cases make sense to me in the abstract still (matching one of many URL patterns). But Jeff and Jake would be better positioned to tell us whether they actually come in practice. |
There are So... assuming it's not much more "work" to expose |
Seems like yes we should include it. |
What does it offer beyond a list of patterns? So you can pass it to match rather than pass match an array? |
Basically it would be a convenience to call |
After further thought I'm going to postpone working on URLPatternList. I have limited bandwidth and want to focus on getting URLPattern out the door. Since the list offers limited value right now and is completely polyfillable I think we can safely exclude it from the MVP. We can add it later if there is developer demand. |
Note, I opened a separate issue (#61) for ordering of URLPattern objects. |
Developers have pointed out that popular routing systems offer optimized route lookup using data structures like radix trees, etc. For example, see find-my-way. This allows them to find the "best" matching route in a set of routes quickly. This feels like a compelling feature for |
It would be useful to know how devs feel about these possible features:
|
I'm speaking mostly in the perspective of app routing, but as URL routing is listed as one of the use cases of URLPattern, I feel that it's necessary for me to chime in. Being able to provide metadata within the pattern list is necessary, as the pattern result itself wouldn't be enough for us to tell whether it should show view A or B. I'm not sure about duplicate equivalent patterns under different groups though, I'm not sure if there's any common use case to justify adding this feature specifically? The rest seems like icing on the cake, so whether or not it makes it in will not make a whole lot of difference, save for dynamically sorted patterns, which may be useful for one feature that's also worth considering... Nested patterns makes it easy to group patterns under the same matcher alongside its metadata, which in the example below, is used to group views under the same layout. let routes = new URLPatternList([
{
// nested routes requires wildcard
pathname: '/users/*',
metadata: { component: UsersLayout },
children: [
{
pathname: '/',
metadata: { component: UsersIndexView },
},
{
pathname: '/@me',
metadata: { component: UsersPersonalView },
},
{
pathname: '/:username',
metadata: { component: UsersView },
},
],
},
]); The pattern result would contain concatenated groups, and a let match;
if ((match = routes.exec('/users/intrnl'))) {
match.scope;
// [ { component: UsersLayout }, { component: UsersView } ]
match.pathname.groups;
// { username: 'intrnl' }
} If parent and children pattern contains a group of the same name, it might be worth throwing early? This would only be useful for app routers specifically, but it's still something that's worth considering, as app routers would try to reimplement something like this on their own. I believe what I've said would be enough for app routing libraries to justify using URLPatternList for path matching, but it might be worth contacting the authors of React Router and Vue Router to see what they'd say about it. ^^ |
I still haven't been able to give this a test but plan on doing by the end of October. For Vue router, I would handle the nesting myself and pass a flat array to URLPatternList so I can handle the normalization of the route records. |
An important note on this: it's not a convenience call. It allows to differentiate urls that can be matched by multiple patterns (routes). For example About the list:
Regarding radix trees, if I remember correctly, they can't handle the specificity of repeatable and optional params correctly:
|
One of the my biggest concerns is that the evaluation algorithm of multiple routes should not be "iterate over all of them and test them all". This is not going to scale up well for many routes and larger applications. A solution to that problem is a radix tree, there are likely other algorithms and data structures that could make that happen and be performant. |
I don't think we will have to iterate all entries in the list. At a minimum we can always at least optimize "prefix match" patterns that begin with fixed text. That fixed text can be in a data structure like a radix tree to reduce the set of possible patterns that can match. |
I think that could optimize quite a few cases. I would still recommend a prefix trie with the known limitation of the repeatable and optional params. In other terms it might be possible to:
Anything that matches the fast path is prioritized over the slow path. |
It's true it doesn't scale well and that a radix tree performs better with very large sets of routes. As a consumer of the API, that's an implementation detail and in practice, for client side routing, the perf difference in a list or a radix tree is, by experience, not significant enough (and sometimes even completely negligeable) while on the server it is critical to the scalability of the request handling. What is critical to me, as a consumer of the API to build client side routing, is supporting repeatable params. |
Can you tell me more about repeatable params? Is this things like |
Sure, here is an explanation: https://next.router.vuejs.org/guide/essentials/route-matching-syntax.html#repeatable-params |
Oh. Parameters with a repeating modifier. Got it. Yes, that is supported in patterns today and will be supported by any container. I was afraid you were asking for something like #96. Thanks for clarifying. |
I ran a little benchmark today, and you can really see a stark difference between a hand-written, and a "naive" URLPattern based router:
The handwritten router is nearly 7x faster than the I am happy to put in the spec work for this. We just need to figure out if we want to spec a "fast" tree based implementation of I'll comment in this issue soon (as time permits) with a more concrete proposal for how to proceed with |
@lucacasonato I'll be very happy to review whatever you came up with! |
I would recommend spec'ing the naive approach and allow non-observable optimizations. Thank you for looking into this! |
After the last face-to-face meeting we changed the plan to make service worker scope take a pathname patter string instead of a full URLPattern object and an array of strings instead of a URLPatternList object.
Given this was the main use case for URLPatternList, should we just not expose URLPatternList? Are there other use cases for URLPatternList?
@jeffposnick @jakearchibald do you think developers would need URLPatternList vs simply just managing a list of URLPattern objects themselves?
The text was updated successfully, but these errors were encountered: