Skip to content

Instantly share code, notes, and snippets.

@azriel91
Last active January 27, 2025 01:55
Show Gist options
  • Save azriel91/c7ee2d0275dcec48586d193927414e06 to your computer and use it in GitHub Desktop.
Save azriel91/c7ee2d0275dcec48586d193927414e06 to your computer and use it in GitHub Desktop.
Leptos 0.6 to 0.7 migration

Leptos 0.6 to 0.7 Migration

  1. Cargo.toml: remove "leptos_meta/csr", "leptos_router/csr" feature propagations.

  2. Cargo.toml: remove "leptos_meta/hydrate", "leptos_router/hydrate" feature propagations.

  3. leptos::SignalGet: leptos::prelude::Get

  4. leptos::SignalSet: leptos::prelude::Set

  5. leptos::SignalUpdate: leptos::prelude::Update

  6. leptos::SignalUpdate: leptos::prelude::Update

  7. leptos::ServerFnError: leptos::prelude::ServerFnError

  8. leptos::mount_to_body: leptos::mount::mount_to_body

  9. leptos::spawn_local: leptos::task::spawn_local

  10. leptos::create_effect: leptos::prelude::Effect::new

  11. leptos::create_signal: Either leptos::prelude::signal or leptos::prelude::RwSignal::new

  12. leptos::create_resource: leptos::prelude::Resource::new

  13. leptos::create_node_ref: leptos::prelude::NodeRef::new

  14. leptos::use_context: leptos::context::use_context

  15. leptos::provide_context: leptos::context::provide_context

  16. leptos::Callback: leptos::callback::Callback

  17. leptos::Callable: leptos::callback::Callable

  18. leptos::Callable::call: leptos::callback::Callable::run

  19. Traits to enable attributes:

    use leptos::prelude::{
        ClassAttribute, ElementChild, GlobalAttributes, GlobalOnAttributes, NodeRef,
        NodeRefAttribute, OnAttribute,
    };
  20. Router

    before:

    <Router fallback=|| view! {} >
        <main>
            <Routes>
                <Route
                    path="index"
                />
            </Routes>
        </main>
    </Router>

    after:

    let (is_routing, set_is_routing) = signal(false);
    
    <Router set_is_routing>
        <main>
            <Routes fallback=|| view! {} >
                <div class="routing-progress">
                    <RoutingProgress is_routing max_time=Duration::from_millis(250)/>
                </div>
                <Route
                    path=leptos_router_macro::path!("")
                />
            </Routes>
        </main>
    </Router>
  21. leptos::NodeRef::on_load

    before:

    use leptos::prelude::OnAttribute;
    
    let text_editor_div_on_load = move |node| { .. };
    
    view! {
        <div
            node_ref=div_ref
            ..
            on:load=text_editor_div_on_load
        ></div>
    }

    after:

    use leptos::prelude::OnAttribute;
    
    let _ = Effect::new(move |_| {
        if let Some(node) = div_ref.get() { .. }
    });
    
    view! {
        <div
            node_ref=div_ref
            ..
        ></div>
    }
  22. <noscript> does not work on SSR.

  23. TrailingSlash doesn't exist. Not sure if it's needed yet.

  24. For SSR, add a shell function with AutoReload and HydrationScripts:

    use leptos::hydration::{AutoReload, HydrationScripts};
    use leptos_meta::MetaTags;
    
    pub fn shell(options: LeptosOptions) -> impl IntoView {
        view! {
            <!DOCTYPE html>
            <html lang="en">
                <head>
                    <AutoReload options=options.clone() />
                    <HydrationScripts options />
                    <MetaTags />
                </head>
                <body>
                    <App />
                </body>
            </html>
        }
    }
  25. There's also something about using HashedStyleSheet. Check the release page.

  26. See #3332 for where to place various method calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment