yew: Can't follow "Build a sample app": Hello World doesn't render

This is about:

  • Other

Problem While trying to follow https://yew.rs/docs/getting-started/build-a-sample-app, <h1>{ "Hello World" }</h1> does not show in Firefox so I can’t progress. Text included in the index.html renders.

index.html

<!DOCTYPE html>
<html lang="en">
    <head><title>testtitle</title></head>
    <body>this is from the html</body>
</html>

src/main.rs

use yew::prelude::*;

#[function_component(App)]
fn app() -> Html {
    html! {
        <h1>{ "Hello World" }</h1>
    }
}

fn main() {
    yew::start_app::<App>();
}

Cargo.toml

[package]
name = "yew-app"
version = "0.1.0"
edition = "2021"

[dependencies]
yew = "0.19"

Nothing is reported in Console. Inner HTML

<head><title>testtitle</title>
<link rel="preload" href="/yew-app-7bc228bf5a52d897_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/yew-app-7bc228bf5a52d897.js"></head>
    <body>this is from the html
<script type="module">import init from '/yew-app-7bc228bf5a52d897.js';init('/yew-app-7bc228bf5a52d897_bg.wasm');</script><script>(function () {
    var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
    var url = protocol + '//' + window.location.host + '/_trunk/ws';
    var poll_interval = 5000;
    var reload_upon_connect = () => {
        window.setTimeout(
            () => {
                // when we successfully reconnect, we'll force a
                // reload (since we presumably lost connection to
                // trunk due to it being killed, so it will have
                // rebuilt on restart)
                var ws = new WebSocket(url);
                ws.onopen = () => window.location.reload();
                ws.onclose = reload_upon_connect;
            },
            poll_interval);
    };

    var ws = new WebSocket(url);
    ws.onmessage = (ev) => {
        const msg = JSON.parse(ev.data);
        if (msg.reload) {
            window.location.reload();
        }
    };
    ws.onclose = reload_upon_connect;
})()
</script></body>

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 18 (8 by maintainers)

Most upvoted comments

I faced the same issue when I tried sample app instructions. This was fixed after executing the command

rustup target add wasm32-unknown-unknown

Not sure why I have to this.

Because running rustup target list showed me wasm32-unknown-unknown (installed) earlier too