-
Within First a related question: How do callbacks work with SSR? Are they ignored on the server and simply attached by the client? In other words: Do I have to worry about callbacks accidental being run on the server in certain configurations? Anyway, this seems to work: let onclick = move |ev| {
cfg_if! { if #[cfg(feature = "hydrate")] {
log::info!("sup?");
}}
}; But this causes lots of "unused" warnings depending on the implementation:
Also, is there any overhead to having that empty callback on the server in first place? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
This doesn't follow for me... #[cfg(not(feature = "ssr"))]
#[wasm_bindgen /* ... */]
fn my_js_function() { /* */ }
#[cfg(feature = "ssr")]
fn my_js_function() { /* */ }
Here's what adding an event handler with Lines 941 to 947 in 3c6748b This will never be run on the server.
See above; not really. |
Beta Was this translation helpful? Give feedback.
The server side of your app crate is already compiling
wasm-bindgen
as part of Leptos to support the ability to have ordinaryon:click
and so on and have the events typed properly viaweb-sys
etc., so I don't think it would add any compile time at all to use it to generate a binding that you'll call in an event listener.Changing the view macro so it doesn't use the value of the handler at all in SSR mode would generate "unused variable" warnings for all event listeners while running in SSR mode, which is surely not desirable.
It seems like there are a few different options here, and which one you want to use is a matter of personal preference, but there aren't really technical limitation…