From da93cf7dc4a026d037ea9d70198b465a96d4d64a Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 2 Nov 2022 08:59:37 +0100 Subject: [PATCH] fix(indexeddb): Fix `wasm_bindgen::JsValue::(from|to)_serde` warnings. `wasm_bindgen::JsValue::(from|to)_serde` now emit warnings because of a circular dependency. To solve this problem, this patch now uses `gloo-utils`, see https://rustwasm.github.io/wasm-bindgen/reference/arbitrary-data-with-serde.html#an-alternative-approach---using-json. Ideally, we would like to use `serde_wasm_bindgen` but the behaviour isn't the same. `gloo-utils` serializes and deserialized through JSON, whilst `serde_wasm_bindgen` manipulates the `JsValue` directly which can be better or worst dependending of the case. This patch conserves the JSON approach as it was the previous and tested one. --- crates/matrix-sdk-indexeddb/Cargo.toml | 5 +++-- crates/matrix-sdk-indexeddb/src/crypto_store.rs | 1 + crates/matrix-sdk-indexeddb/src/state_store.rs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/Cargo.toml b/crates/matrix-sdk-indexeddb/Cargo.toml index 4b796b6b4..09af3fac1 100644 --- a/crates/matrix-sdk-indexeddb/Cargo.toml +++ b/crates/matrix-sdk-indexeddb/Cargo.toml @@ -35,7 +35,8 @@ serde = "1.0.136" serde_json = "1.0.79" thiserror = "1.0.30" tracing = { workspace = true } -wasm-bindgen = { version = "0.2.80", features = ["serde-serialize"] } +wasm-bindgen = "0.2.83" +gloo-utils = { version = "0.1", features = ["serde"] } web-sys = { version = "0.3.57", features = ["IdbKeyRange"] } [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -48,4 +49,4 @@ matrix-sdk-common = { path = "../matrix-sdk-common", features = ["js"] } matrix-sdk-crypto = { path = "../matrix-sdk-crypto", features = ["js", "testing"] } matrix-sdk-test = { path = "../../testing/matrix-sdk-test" } uuid = "1.0.0" -wasm-bindgen-test = "0.3.30" +wasm-bindgen-test = "0.3.33" diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store.rs b/crates/matrix-sdk-indexeddb/src/crypto_store.rs index b0d469359..fbd0caf58 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store.rs @@ -19,6 +19,7 @@ use std::{ use async_trait::async_trait; use dashmap::DashSet; +use gloo_utils::format::JsValueSerdeExt; use matrix_sdk_base::locks::Mutex; use matrix_sdk_crypto::{ olm::{ diff --git a/crates/matrix-sdk-indexeddb/src/state_store.rs b/crates/matrix-sdk-indexeddb/src/state_store.rs index 62a8890d0..e2b610c1e 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store.rs @@ -23,6 +23,7 @@ use std::{ use anyhow::anyhow; use async_trait::async_trait; use derive_builder::Builder; +use gloo_utils::format::JsValueSerdeExt; use js_sys::Date as JsDate; use matrix_sdk_base::{ deserialized_responses::MemberEvent,