yew: Can't use spaces directly in a class string
If in my render function, I have:
fn view(&self) -> Html<Context, Self> {
html! {
<div class="container-fluid",>
<div class="row",>
<div class="col",>
</div>
</div>
<main class="row",>
<div class="col",>
</div>
</main>
</div>
}
}
my code runs fine, without errors.
If I change to:
fn view(&self) -> Html<Context, Self> {
html! {
<div class="container-fluid",>
<div class="row",>
<div class="col",>
<nav class="navbar navbar-expand-lg navbar-light bg-light",>
</nav>
</div>
</div>
<main class="row",>
<div class="col",>
</div>
</main>
</div>
}
}
I get the following error:
exception thrown: InvalidCharacterError: String contains an invalid character,ASM_CONSTS<@http://localhost:8000/js/app.js:1707:80
_emscripten_asm_const_iii@http://localhost:8000/js/app.js:1729:10
__ZN6stdweb6webapi10token_list9TokenList3add17hbcd64a3dc4ae18fcE@http://localhost:8000/js/app.js:772025:1
dynCall_viii@http://localhost:8000/js/app.js:4750617:1
Module.dynCall_viii@http://localhost:8000/js/app.js:8323:66
invoke_viii@http://localhost:8000/js/app.js:8038:5
__ZN95__LT_yew__virtual_dom__vtag__VTag_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hbed485f8d5184751E@http://localhost:8000/js/app.js:327193:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN97__LT_yew__virtual_dom__vnode__VNode_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hfca50f400ff0a51fE@http://localhost:8000/js/app.js:388499:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN95__LT_yew__virtual_dom__vtag__VTag_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hbed485f8d5184751E@http://localhost:8000/js/app.js:334714:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN97__LT_yew__virtual_dom__vnode__VNode_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hfca50f400ff0a51fE@http://localhost:8000/js/app.js:388499:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN95__LT_yew__virtual_dom__vtag__VTag_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hbed485f8d5184751E@http://localhost:8000/js/app.js:334714:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN97__LT_yew__virtual_dom__vnode__VNode_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hfca50f400ff0a51fE@http://localhost:8000/js/app.js:388499:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN95__LT_yew__virtual_dom__vtag__VTag_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hbed485f8d5184751E@http://localhost:8000/js/app.js:334714:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN97__LT_yew__virtual_dom__vnode__VNode_LT_CTX_C__u20_COMP_GT__u20_as_u20_yew__virtual_dom__VDiff_GT_5apply17hfca50f400ff0a51fE@http://localhost:8000/js/app.js:388499:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN48__LT_yew__html__Scope_LT_CTX_C__u20_COMP_GT__GT_14mount_in_place17h89d4b08b69a16c7fE@http://localhost:8000/js/app.js:541259:1
dynCall_viiii@http://localhost:8000/js/app.js:4750692:1
Module.dynCall_viiii@http://localhost:8000/js/app.js:8326:68
invoke_viiii@http://localhost:8000/js/app.js:8065:5
__ZN48__LT_yew__html__Scope_LT_CTX_C__u20_COMP_GT__GT_5mount17hb6ed45d1713922caE@http://localhost:8000/js/app.js:540050:1
dynCall_vii@http://localhost:8000/js/app.js:4750494:1
Module.dynCall_vii@http://localhost:8000/js/app.js:8318:64
invoke_vii@http://localhost:8000/js/app.js:7993:5
__ZN48__LT_yew__html__Scope_LT_CTX_C__u20_COMP_GT__GT_13mount_to_body17heac8c16e9144cb0fE@http://localhost:8000/js/app.js:539586:1
__ZN6hermes3web4main17h387d3e4fbc1bd385E@http://localhost:8000/js/app.js:404925:1
__ZN6hermes4main17hf85a49bbb4aa5bf3E@http://localhost:8000/js/app.js:317312:1
__ZN3std2rt10lang_start28__u7b__u7b_closure_u7d__u7d_17h1c74e3c4f7fb0654E@http://localhost:8000/js/app.js:297327:1
__ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h7a30486027a5b027E@http://localhost:8000/js/app.js:984250:1
__ZN3std9panicking3try7do_call17h0b1cf60168c8dd57E@http://localhost:8000/js/app.js:963626:1
dynCall_vi@http://localhost:8000/js/app.js:4750386:1
Module.dynCall_vi@http://localhost:8000/js/app.js:8313:62
invoke_vi@http://localhost:8000/js/app.js:7948:5
___rust_maybe_catch_panic@http://localhost:8000/js/app.js:1010073:1
__ZN3std2rt19lang_start_internal17h2834043e12814a8eE@http://localhost:8000/js/app.js:963175:1
__ZN3std2rt10lang_start17hf551b0ba7b832818E@http://localhost:8000/js/app.js:297268:1
_main@http://localhost:8000/js/app.js:317306:1
Module._main@http://localhost:8000/js/app.js:8220:52
callMain@http://localhost:8000/js/app.js:8456:15
doRun@http://localhost:8000/js/app.js:8516:42
run@http://localhost:8000/js/app.js:8530:5
runCaller@http://localhost:8000/js/app.js:8435:29
removeRunDependency@http://localhost:8000/js/app.js:1381:7
receiveInstance@http://localhost:8000/js/app.js:1549:7
receiveInstantiatedSource@http://localhost:8000/js/app.js:1568:7
promise callback*doNativeWasm@http://localhost:8000/js/app.js:1583:7
integrateWasmJS/Module.asm@http://localhost:8000/js/app.js:1672:15
@http://localhost:8000/js/app.js:8202:10
app.js:196:7
wasm streaming compile failed: InvalidCharacterError: String contains an invalid character
app.js:196:7
falling back to ArrayBuffer instantiation
app.js:196:7
Note that this change necessitates adding:
#![recursion_limit="128"]
to my crate. I’m wondering if that might be related? It doesn’t seem to happen with less deeply-nested templates.
Workaround: use <tag class=("class-1", "class-2"),> syntax. See below for the details.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 18 (6 by maintainers)
I’ve found the solution, at least for me
Placing multiple class names into a class string is a syntax error, one has to write
<ul class=("nav", "nav-tabs"),></ul>See macro code
I actually think this syntax:
should be much preferred to
We should simply suggest the first syntax if we encounter the second IMO (the second should remain an error but with a better message).
I’m a little confused as to how it is even possible that both syntaxes pass the type checker?
I’ve found that in https://dom.spec.whatwg.org/#interface-domtokenlist:
When you try to use
classparameter of macro it callsadddirectly: https://docs.rs/stdweb/*/src/stdweb/webapi/token_list.rs.html#26 and stumbles on this error.We can fix this footgun in two ways:
I will refocus the PR to fix this spacing problem. Thank you for the investigation tips 👍