Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding issue with emojis using the web platform #2589

Closed
HaHa421 opened this issue Jul 5, 2024 · 2 comments · Fixed by ealmloff/sledgehammer_bindgen#14
Closed

Decoding issue with emojis using the web platform #2589

HaHa421 opened this issue Jul 5, 2024 · 2 comments · Fixed by ealmloff/sledgehammer_bindgen#14
Labels
bug Something isn't working web relating to the web renderer for dioxus

Comments

@HaHa421
Copy link

HaHa421 commented Jul 5, 2024

Problem

I am using the latest version of Dioxus and I have encountered an issue when using emojis in the text. When an emoji is present in the text, I get the following error:

Uncaught (in promise) TypeError: Failed to execute 'decode' on 'TextDecoder': The provided ArrayBufferView value must not be shared.
    at RawInterpreter.run (inline0.js:130:37)
    at imports.wbg.__wbg_run_2ca7d9c27d6a5eb6 (app.js:612:25)
    at app.wasm.dioxus_interpreter_js::unified_bindings::Interpreter::flush::h009ba4a86f46ba0f (app_bg.wasm:0x4f1ec6)

This only occurs when the text contains emojis. If I remove the emojis from the text, everything works normally.

Steps To Reproduce

this occurs when I use ul { "😃" } but I suppose it will happen for any element with any emoji

Steps to reproduce the behavior:

  • same as above

Expected behavior

emojis are displayed without error

Environment:

  • Dioxus version: v0.5.1
  • Rust version: 1.81.0, nightly
  • OS info: Windows Edge
  • App platform: web
@HaHa421
Copy link
Author

HaHa421 commented Jul 7, 2024

I ended up patching sledgehammer_bindgen_macro/src/types/string.rs
with

                    let sharedView = new DataView(this.m.buffer, this.lsp, this.sl);
                    let arrayBuffer = new ArrayBuffer(sharedView.byteLength);
                    new Uint8Array(arrayBuffer).set(new Uint8Array(sharedView.buffer, sharedView.byteOffset, sharedView.byteLength));
                    this.s = this.c.decode(arrayBuffer);
                  
                    /*
                    this.s = this.c.decode(new DataView(this.m.buffer, this.lsp, this.sl));
                    */

it also lets Dynamic Attributes work smoothly with rsx!
the main caveat is that the buffer gets copied every time this code is ran , I suppose the buffer could be checked against:

if (this.m.buffer instanceof SharedArrayBuffer) ...

I suppose an issue should be opened on the sledgehammer_bindgen crate

@HaHa421 HaHa421 changed the title Decoding issue with emojis using the web backend Decoding issue with emojis using the web platform Jul 7, 2024
@ealmloff
Copy link
Member

ealmloff commented Jul 8, 2024

To reproduce this issue, you need to:

  1. Transfer large chunks of strings or non-ascii strings to hit that path of text decoding:
use dioxus::prelude::*;

fn main() {
    launch(|| rsx! { ul { {"12134".repeat(1000)} } })
}
  1. Enable a bunch of rust nightly flags to make wasm multithreaded described here: https://rustwasm.github.io/wasm-bindgen/examples/raytrace.html

@ealmloff ealmloff added bug Something isn't working web relating to the web renderer for dioxus labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working web relating to the web renderer for dioxus
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants