Code compiles to wasm, but fails with "invalid character" errors


#1

Hey folks,

I’m having an odd Rust/wasm bug, and I don’t know enough about the compiler internals to fix it myself. I also don’t know where else I might file useful bugs.

I’m attempting to use Yew to build an HTML UI around my library. Unfortunately, I’m running into some issues where Yew’s html! macro produces errors like the following in my browser console:

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

I’ve filed this issue with Yew. I’ve also created this repository with a small code sample reproducing the issue.

What’s odd to me is that a macro compiles, but generates code that is incompatible on multiple web backends–wasm, asmjs, etc. and on both emscripten and wasm-unknown-unknown. It seems like this should be caught on a higher-level, and should either fail to compile if the issue is in Yew, or generate correct code if Yew isn’t at fault. Using wasm-unknown-unknown doesn’t work here.

Unfortunately, this issue is blocking me on a project I’d like to advance. If it’s just a matter of being patient until the Yew folks check it out, I’m OK with that. But the fact that the code fails post-compile seems suspicious to me, so I wonder if the problem lies elsewhere?

Thanks for any help.