linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.45k stars 569 forks source link

Web example crashes when using clipboard in wasm #2321

Open kahnclusions opened 1 year ago

kahnclusions commented 1 year ago

It looks like Druid tries to call Application::global() when doing stuff with the clipboard but this panics, maybe because the global app is stored in a thread_local! variable which doesn't work in wasm.

Steps to reproduce

  1. Clone the repo and then run:
    ❯ wasm-pack build --target web --dev
    ❯ http
  2. Open browser and navigate to http://localhost:8000/
  3. Try to cut/copy/paste any text in the textbox
  4. See the following error in the JS console:
    
    hello_web.js:333 panicked at 'There is no globally active Application', /.../druid/druid-shell/src/application.rs:109:35

Stack:

Error at http://localhost:8000/pkg/hello_web.js:339:21 at logError (http://localhost:8000/pkg/hello_web.js:233:18) at imports.wbg.__wbg_new_abda76e883ba8a5f (http://localhost:8000/pkg/hello_web.js:338:66) at console_error_panic_hook::Error::new::h196751a1eab8f86e (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[8917]:0x31a10f) at console_error_panic_hook::hook_impl::h0db4adfa38059141 (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[1669]:0x201334) at console_error_panic_hook::hook::hd8a36f6179709228 (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[9547]:0x322b08) at core::ops::function::Fn::call::hf4cc558cb113cf3a (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[8654]:0x315f70) at std::panicking::rust_panic_with_hook::he04cb00575f2a1e3 (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[3489]:0x280df4) at std::panicking::begin_panic_handler::{{closure}}::hb733f0aa505760cf (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[4587]:0x2b35fc) at std::sys_common::backtrace::__rust_end_short_backtrace::h6beefa0bcab220bc (http://localhost:8000/pkg/hello_web_bg.wasm:wasm-function[10070]:0x3295f0)