Skip to content

Conversation

@shane-melton
Copy link
Member

@shane-melton shane-melton commented Jul 30, 2025

🎟️ Tracking

PM-24243

📔 Objective

Add load_flags method to the wasm PlatformClient to match parity with the uniffi PlatformClient so that the TS clients can set the SDK flags dynamically.

Related Clients PR: bitwarden/clients#15855

Added a FlagsInput struct that mimics the internal Flags struct but with tsify bindings.

Another potential option is to make the internal Flags struct public with wasm bindings to avoid duplicating the struct.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@shane-melton shane-melton requested a review from a team as a code owner July 30, 2025 23:29
@shane-melton shane-melton requested a review from dani-garcia July 30, 2025 23:29
@github-actions
Copy link
Contributor

github-actions bot commented Jul 30, 2025

Logo
Checkmarx One – Scan Summary & Details2e8d01b6-6dc8-41b5-85bc-00e0d8f40d38

Great job! No new security vulnerabilities introduced in this pull request

@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.93%. Comparing base (58a9bf9) to head (1484c3c).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
crates/bitwarden-wasm-internal/src/platform/mod.rs 0.00% 4 Missing ⚠️
crates/bitwarden-core/src/client/internal.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #369      +/-   ##
==========================================
+ Coverage   73.34%   73.93%   +0.59%     
==========================================
  Files         252      252              
  Lines       21283    21581     +298     
==========================================
+ Hits        15609    15955     +346     
+ Misses       5674     5626      -48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines 18 to 19
let js_value = serde_wasm_bindgen::to_value(&flags)
.expect("FlagsInput should always serialize successfully");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to avoid expect, as it would produce a panic. I don't think it would happen in this case but better safe than sorry.

Suggested change
let js_value = serde_wasm_bindgen::to_value(&flags)
.expect("FlagsInput should always serialize successfully");
let js_value = serde_wasm_bindgen::to_value(&flags).unwrap_or_default();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know! But this should no longer be needed after 9a7ca68


#[derive(serde::Serialize, serde::Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct FlagsInput {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than duplicate the Flags struct, we should tag the Flags struct in bitwarden_core with:

#[cfg_attr(
    feature = "wasm",
    derive(tsify::Tsify),
    tsify(into_wasm_abi, from_wasm_abi)
)]

Otherwise we'll have to ensure we keep them both in sync, which is error prone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Thanks @dani-garcia! Updated in 9a7ca68

I also had to make the Flags struct in bitwarden_core public and remove the #[cfg(feature="internal")] attribute in 8f2680b. If there's another or better way to go about it please let me know!

Comment on lines 17 to 18
#[allow(missing_docs)]
pub mod flags;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[allow(missing_docs)]
pub mod flags;
mod flags;

You don't need to make this module pub, as you're already doing pub use flags::Flags a few lines after it.

Also both lines should be able to be tagged with the internal flag, the wasm crate is enabling it.

#[cfg(feature = "internal")]
mod flags;

#[cfg(feature = "internal")]
pub use flags::Flags;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks! Fixed in 1484c3c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We intentionally didn't make flags public for mobile in order to avoid removal of flags from being a breaking change.

@shane-melton shane-melton requested a review from dani-garcia July 31, 2025 22:25
@sonarqubecloud
Copy link

@shane-melton shane-melton merged commit 4813492 into main Aug 5, 2025
50 checks passed
@shane-melton shane-melton deleted the vault/pm-24243/wasm-feature-flag-loading branch August 5, 2025 22:19
Comment on lines +119 to +123
#[allow(missing_docs)]
#[cfg(feature = "internal")]
pub fn set_flags(&self, flags: &Flags) {
*self.flags.write().expect("RwLock is not poisoned") = flags.clone();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have load_flags above, and #[allow(missing_docs)] is not allowed on new functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants