Synphonyte / leptos-use

Collection of essential Leptos utilities inspired by React-Use / VueUse / SolidJS-USE
https://leptos-use.rs/
Apache License 2.0
299 stars 66 forks source link

Add support for client hints #121

Open dvtkrlbs opened 2 months ago

dvtkrlbs commented 2 months ago

Client hints currently experimental. Maybe we can implement some features of it using a feature flag. Especially the Sec-CH-Prefers-Color-Scheme header could be useful to setup dark mode on the server to prevent flash on non dark mode content.

maccesch commented 2 months ago

Sounds like a good idea. First we have to add a PR to web_sys to support the API.

dvtkrlbs commented 2 months ago

@maccesch from what I read it doesn't need any kind of client side feaute. Since everything only via headers. We just need the integration via axum since at first response server responds with critical hints and client retries the request.

maccesch commented 2 months ago

For #101 we only need the server side part indeed because the client side is already handled. But even in that case we're probably interested in being able to read it on the client as well.

For a general purpose client hints function we definitely need client side. Pages should work the same as much as possible between being rendered on the server or on the client.

This is the client API: https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API

maccesch commented 2 months ago

I made a PR for web_sys: https://github.com/rustwasm/wasm-bindgen/pull/3989

dvtkrlbs commented 2 months ago

@maccesch these are the user agent client hints api and I was mostly considerign User preference media features client hints css features where you can get for example Sec-CH-Prefers-Reduced-Motion, Sec-CH-Prefers-Color-Scheme. These already have client side apis. But yeah for the user agent ones that makes sense.

maccesch commented 2 months ago

Yes, but while we're at it we might as well do it right, don't you agree?

As far as I read it you're talking about a subset but when we implement this API I'd rather do it all at once.

maccesch commented 3 weeks ago

@dvtkrlbs I finally fully understood what you meant with existing client APIs. The Sec-CH-Prefers-Color-Scheme is now implemented.

dvtkrlbs commented 3 weeks ago

@dvtkrlbs I finally fully understood what you meant with existing client APIs. The Sec-CH-Prefers-Color-Scheme is now implemented.

Thank you very much