lukechu10 / mdsycx

markdown with Sycamore
https://lukechu.dev/mdsycx/
MIT License
15 stars 1 forks source link

Compile issues node.to_web_sys() method not found #2

Closed danielnehrig closed 2 years ago

danielnehrig commented 2 years ago

i'm still facing the same issue :/ maybe you have an idea

❯ rustc --version
rustc 1.66.0-nightly (2019147c5 2022-09-19)

my cargo toml

[package]
name = "dn"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
perseus = { version = "0.4.0-beta.10", features = [ "hydrate" ] }
sycamore = { version = "^0.8.2", features = ["ssr", "hydrate" ] }
web-sys = "^0.3.60"
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = { version = "0.4.3"}
serde_json = "1"
reqwasm = {version = "0.5", features = ["json"]}
wasm-bindgen = {version = "0.2", features = ["serde-serialize"]}
mdsycx = "0.1.0"

[patch.crates-io] 
sycamore = { git = "https://github.com/sycamore-rs/sycamore", rev = "2a7d015" } 

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }
perseus-warp = { version = "0.4.0-beta.10", features = [ "dflt-server" ] }

# [target.'cfg(target_arch = "wasm32")'.dependencies]

[lib]
name = "lib"
path = "src/lib.rs"
crate-type = [ "cdylib", "rlib" ]

[[bin]]
name = "dn"
path = "src/lib.rs"

cargo check --target wasm32-unknown-unknown

❯ cargo check --target wasm32-unknown-unknown
warning: file found to be present in multiple build targets: /home/redacted/code/rust/dn/src/lib.rs
    Updating crates.io index
warning: Patch `sycamore v0.8.1 (https://github.com/sycamore-rs/sycamore?rev=2a7d015#2a7d015b)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
  Downloaded perseus-warp v0.4.0-beta.10
  Downloaded perseus v0.4.0-beta.10
  Downloaded perseus-macro v0.4.0-beta.10
  Downloaded 3 crates (140.6 KB) in 0.31s
   Compiling perseus-macro v0.4.0-beta.10
    Checking mdsycx v0.1.0
error[E0599]: no method named `to_web_sys` found for type parameter `G` in the current scope
   --> /home/redacted/.cargo/registry/src/github.com-1ecc6299db9ec823/mdsycx-0.1.0/src/components.rs:124:45
    |
92  | fn events_to_view<'a, G: Html>(
    |                       - method `to_web_sys` not found for this type parameter
...
124 |                             let node = node.to_web_sys();
    |                                             ^^^^^^^^^^ method not found in `G`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `mdsycx` due to previous error
warning: build failed, waiting for other jobs to finish...
lukechu10 commented 2 years ago

The published version shouldn't need the sycamore patch anymore. Can you try removing that line and also run cargo update?

danielnehrig commented 2 years ago

Ok this works but now im running into lifetime issues

#[perseus::template_rx]
pub fn article_page<'a, G: Html>(
    cx: Scope<'a>,
    ArticlePageStateRx { article }: ArticlePageStateRx<'a>,
) -> View<G> {
    let content = article.get().content.clone();
    let parsed = parse::<()>(content.as_str()).unwrap();

    view! { cx,
        PageWrapper {
            NavBar(is_admin = false) {
                div() {}
            }
            // div() {(entry.title)}
            MDSycX(body=parsed.body)
        }
    }
}
error[E0597]: `content` does not live long enough
  --> src/templates/article.rs:20:30
   |
15 |   pub fn article_page<'a, G: Html>(
   |                       -- lifetime `'a` defined here
...
20 |       let parsed = parse::<()>(content.as_str()).unwrap();
   |                                ^^^^^^^^^^^^^^^^ borrowed value does not live long enough
21 |
22 | /     view! { cx,
23 | |         PageWrapper {
24 | |             NavBar(is_admin = false) {
25 | |                 div() {}
...  |
29 | |         }
30 | |     }
   | |_____- argument requires that `content` is borrowed for `'a`
31 |   }
   |   - `content` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.
warning: `dn` (lib) generated 5 warnings
error: could not compile `dn` due to previous error; 5 warnings emitted
lukechu10 commented 2 years ago

Try create_ref(cx, content) instead. The lifetime needs to last as long as the reactive scope.

danielnehrig commented 2 years ago

well problem was my lack of knowledge about sycamore sorry about that and thanks for helping me out i've got it working !