Skip to content
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

URLPattern #2286

Open
vamsaya opened this issue Mar 3, 2023 · 23 comments
Open

URLPattern #2286

vamsaya opened this issue Mar 3, 2023 · 23 comments
Labels
enhancement New feature or request web-api Something that relates to a standard Web API wintercg Web-interoperable Runtimes Community Group compatiblity

Comments

@vamsaya
Copy link

vamsaya commented Mar 3, 2023

What is the problem this feature would solve?

https://developer.mozilla.org/en-US/docs/Web/API/URLPattern

What is the feature you are proposing to solve the problem?

Although this is an experimental function, it is undoubtedly very practical for bun routing, and deno has already implemented it, so we can't live without it.

What alternatives have you considered?

No response

@vamsaya vamsaya added the enhancement New feature or request label Mar 3, 2023
@Electroid Electroid added the web-api Something that relates to a standard Web API label Mar 3, 2023
@Jarred-Sumner
Copy link
Collaborator

URLPattern is designed to be slow, so we aren't going to support this officially unless it becomes a web standard (WICG != W3C). You can use JS polyfills until then

@PodaruDragos
Copy link

is it not a web standard ? link

@nektro nektro added the wintercg Web-interoperable Runtimes Community Group compatiblity label Jun 6, 2024
@ghost
Copy link

ghost commented Jun 21, 2024

URLPattern is designed to be slow, so we aren't going to support this officially unless it becomes a web standard (WICG != W3C). You can use JS polyfills until then

Please reconsider this. Make it an optional import and allow us to opt into using it if we are willing to accept the performance hit.

@michaldo
Copy link

I would like to make http server with bun. Here: https://bun.sh/guides/http/server only trivial path matching is demonstrated.
I need match segments, for example /foo/{bar}/baz
I don't want use regexp because they are too complex for simple segment matching.
Bun does not implement URLPattern

Then what is bun proposal for that?

@kravetsone
Copy link

What is the problem this feature would solve?

https://developer.mozilla.org/en-US/docs/Web/API/URLPattern

What is the feature you are proposing to solve the problem?

Although this is an experimental function, it is undoubtedly very practical for bun routing, and deno has already implemented it, so we can't live without it.

What alternatives have you considered?

No response

Routing with regexp is painful and should be abandoned

@kravetsone
Copy link

What is the problem this feature would solve?

https://developer.mozilla.org/en-US/docs/Web/API/URLPattern

What is the feature you are proposing to solve the problem?

Although this is an experimental function, it is undoubtedly very practical for bun routing, and deno has already implemented it, so we can't live without it.

What alternatives have you considered?

No response

Routing with regexp is painful and should be abandoned

It is great feature for web but not so for server-side

@TiBianMod
Copy link

nice to have!!!

@juriadams
Copy link

Currently blocking the use of cross-runtime fetch mocks like @c4spar/mock-fetch.

@samuelstroschein
Copy link

NodeJS just merged support for URLPattern nodejs/node#40844.

If Bun wants full Node compatibility, implementing URLPattern seems unavoidable now.

@samuelstroschein
Copy link

Safari shipped URLPattern this week as well, and URLPattern made it on the Interop 2025 list.

@kravetsone
Copy link

Safari shipped URLPattern this week as well, and URLPattern made it on the Interop 2025 list.

nodejs ship it too

but i guess this feature not so important because it slow by design and etc

@ivan-kleshnin
Copy link

ivan-kleshnin commented Feb 15, 2025

but i guess this feature not so important because it slow by design and etc

We use it for routing, as a polyfill (which is 1000 times slower). I personally don't get how you people call some implementation "slow" without even asking how much calls to that function will be made. In my work perspective LLMs are slow. And all pattern matching algorithms, even the most ineffecient, are super fast 😅

@kravetsone
Copy link

but i guess this feature not so important because it slow by design and etc

We use it for routing, as a polyfill (which is 1000 times slower). I personally don't get how you people call some implementation "slow" without even asking how much calls to that function will be made. In my view LLMs are slow. And all pattern matching algorithms, even the most ineffecient, are super fast 😅

Why u need this?
Routing with regexps is strange thing

Also https://en.m.wikipedia.org/wiki/ReDoS

Radix-tree based routers is more fine

@ivan-kleshnin
Copy link

ivan-kleshnin commented Feb 17, 2025

@kravetsone thanks!

It's an internal routing for unusual purposes. Unrelated to API, not using HTTP(s), no DOS threats.

Radix-tree based routers is more fine

Most likely true. But when this code was written we couldn't find a well supported and typed library (and writing one was not an option). Can you recommend any particular library?

@kravetsone
Copy link

@kravetsone thanks!

It's an internal routing for unusual purposes. Unrelated to API, not using HTTP(s), no DOS threats.

Radix-tree based routers is more fine

Most likely true. But when this code was written we couldn't find a well supported and typed library (and writing one was not an option). Can you recommend any particular library?

https://www.npmjs.com/package/find-my-way

used by fastify

https://www.npmjs.com/package/memoirist

used by elysia

https://github.com/mapljs/router

by @aquapi frameworks

@aquapi
Copy link
Contributor

aquapi commented Feb 17, 2025

@ivan-kleshnin Now you can have route patterns in Bun.
And please stop thinking about RegExp routing no other language actually do this except JS because it's wasteful

@aquapi
Copy link
Contributor

aquapi commented Feb 17, 2025

@kravetsone thanks!
It's an internal routing for unusual purposes. Unrelated to API, not using HTTP(s), no DOS threats.

Radix-tree based routers is more fine

Most likely true. But when this code was written we couldn't find a well supported and typed library (and writing one was not an option). Can you recommend any particular library?

https://www.npmjs.com/package/find-my-way

used by fastify

https://www.npmjs.com/package/memoirist

used by elysia

https://github.com/mapljs/router

by @aquapi frameworks

I think memoirist is a good place to start since find-my-way is slightly slower while designed to integrate well with fastify so it is kinda complex to use.

My router is the fastest possible you can have in JS but I didn't implemenet named parameters, like uWS req.getParameter() API.

@Jarred-Sumner
Copy link
Collaborator

please stop thinking about RegExp routing

@aquapi this is not constructive; there are usecases that RegExp-based routers solve for that trie-based routers do not support.

@ivan-kleshnin we will implement support for URLPattern in Bun (using WebKit's implementation). We haven't yet, but we will given that now it is a web standard that Safari supports and that Node implemented.

@kravetsone
Copy link

please stop thinking about RegExp routing

@aquapi this is not constructive; there are usecases that RegExp-based routers solve for that trie-based routers do not support.

@ivan-kleshnin we will implement support for URLPattern in Bun (using WebKit's implementation). We haven't yet, but we will given that now it is a web standard that Safari supports and that Node implemented.

Yes, I agree that this must be implemented, but for now it probably doesn't make sense to take special priority - there are still a lot of things that are more important for now

i love u work!

@aquapi
Copy link
Contributor

aquapi commented Feb 17, 2025

please stop thinking about RegExp routing

@aquapi this is not constructive; there are usecases that RegExp-based routers solve for that trie-based routers do not support.

@ivan-kleshnin we will implement support for URLPattern in Bun (using WebKit's implementation). We haven't yet, but we will given that now it is a web standard that Safari supports and that Node implemented.

@Jarred-Sumner There are use cases but it's not worth it at all.
Those patterns from uWS is everything you really need. If you want to parse more complex patterns you can capture it first and do the parsing in the handlers later.

I think URLPattern has its use cases but not for URL routing (There is a reason most frameworks in other languages don't support these patterns)

Plus things like this can happen because it seems like JSC doesn't have optimizations for it yet: https://v8.dev/blog/non-backtracking-regexp

https://adventures.nodeland.dev/archive/you-should-not-use-urlpattern-to-route-http/

@aquapi
Copy link
Contributor

aquapi commented Feb 17, 2025

@ivan-kleshnin A better solution would be whatwg/urlpattern#166

@samuelstroschein
Copy link

@aquapi please stop commenting on the issue to avoid ppl unsubscribing.

URLPattern is going to be implemented. There are use cases for routing which are valid and other use cases like Paraglide JS's localization of URLs https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#url

@aquapi
Copy link
Contributor

aquapi commented Feb 17, 2025

@samuelstroschein I'm not against URLPattern being implemented at all. I'm just telling that you should not use it for routing.
There are other good use cases for it.
Your use case is completely fine because matching two patterns won't slow you down at all and benefit bundle size as well.
Didn't realize my please stop piss people off like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request web-api Something that relates to a standard Web API wintercg Web-interoperable Runtimes Community Group compatiblity
Projects
None yet
Development

No branches or pull requests