Replies: 1 comment 7 replies
-
I'm going to answer this question in two parts: one more specific and one more general. Specific: I think in most cases, Generally speaking the only times setting a feature is necessary in a user crate is when there is code that cannot be compiled for non-server targets, but you want to leave the possibility open for server-side WASM so can't simply use I'm always happy to discuss concrete cases but I think it's often not needed at all. For example:
If they want to do something only on the client, they should put it in an General: It is true that the way we use (For example, while |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm doing some work on a component library, and ran across a pattern that I figured I'd ask about here. Leptos currently uses cargo-features to "detect" server/client rendering as far as I've understood. This is fine most of the time, but it causes a lot of feature-passing in cargo. For instance, libraries like
leptos-use
has their ownssr
feature that enables/disables client/server-side functionallity.Where this get's problematic is component-libraries like https://github.com/RustForWeb/radix where each component is it's own crate. If they need to do something only on the client for instance, you might have to add a
ssr
feature to all of the packages. This spreads pretty virally.My question is basically if there is a better way to do this? I'm thinking maybe leptos could expose a
const IS_SERVER: bool = cfg!(feature = ssr)
or something like that. Now, obviously, this won't work for code that can't compile for the server. But I would think in a lot of cases, this simpler approach would be effectively as good as using conditional compilation.Beta Was this translation helpful? Give feedback.
All reactions