Giter VIP home page Giter VIP logo

Comments (6)

VincentBerthier avatar VincentBerthier commented on September 27, 2024 1

Here’s a toy example to reproduce it: https://github.com/VincentBerthier/leptos-repro/tree/i18n

from leptos.

Baptistemontan avatar Baptistemontan commented on September 27, 2024

I've tried to look at the code generated by #[island] and could not found the culprit, so it might but a problem with some wasm_bindgen macros that assume it to exist at the root, not sure.

from leptos.

Baptistemontan avatar Baptistemontan commented on September 27, 2024

if I change those lines: https://github.com/leptos-rs/leptos/blob/0658a550b09d70c372e1a24957f8b0ff90b0f033/leptos_macro/src/component.rs#L449C13-L464C14

to this:

let mod_name = format_ident!("hydrate_fn_{}", hydrate_fn_name);

quote! {
    #[allow(non_snake_case)]
    mod #mod_name {
        use super::*;
        use ::leptos::wasm_bindgen; // <-- import wasm_bindgen here
        #[::leptos::wasm_bindgen::prelude::wasm_bindgen]
        #[allow(non_snake_case)]
        pub fn #hydrate_fn_name(el: ::leptos::web_sys::HtmlElement) {
            if let Some(Ok(key)) = el.dataset().get(::leptos::wasm_bindgen::intern("hkc")).map(|key| std::str::FromStr::from_str(&key)) {
                ::leptos::leptos_dom::HydrationCtx::continue_from(key);
            }
            #deserialize_island_props
            _ = ::leptos::run_as_child(move || {
                ::leptos::SharedContext::register_island(&el);
                ::leptos::leptos_dom::mount_to_with_stop_hydrating(el, false, move || {
                    #name(#island_props)
                })
            });
        }
    }

    pub use #mod_name::#hydrate_fn_name;
}

The error goes away, but this outputed code never direcly use as root wasm_bindgen, so the problem must comes from the wasm_bindgen::prelude::wasm_bindgen macro...

from leptos.

gbj avatar gbj commented on September 27, 2024

Digging through wasm-bindgen source code and docs I discovered that you can add a wasm_bindgen = feature to the wasm_bindgen macro:

#[wasm_bindgen(wasm_bindgen = ::leptos::wasm_bindgen)]

Anyone want to test this out against the islands implementation to see if it fixes the above issue and make a quick PR?

from leptos.

Baptistemontan avatar Baptistemontan commented on September 27, 2024

Yeah sure! I have everything needed to test that locally, I will try it when I get back home from work

from leptos.

Baptistemontan avatar Baptistemontan commented on September 27, 2024

It did fix it! I'm making a PR for the fix

from leptos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.