Skip to content

fix: drop the unused WebView2 controller import - #1399

Merged
tw93 merged 1 commit into
tw93:mainfrom
jakero:fix/remove-unused-webview2-import
Oct 4, 2026
Merged

tw93 merged 1 commit into
tw93:mainfrom
jakero:fix/remove-unused-webview2-import

Conversation

@jakero

@jakero jakero commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Summary

A Windows build reports an unused_imports warning in src-tauri/src/app/navigation.rs. The import was never needed, so this removes it. No functional change.

warning: unused import: `webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller`
  --> src\app\navigation.rs:66:9
   |
66 |     use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default
 #[cfg(windows)]
 fn history_step_platform(webview: &tauri::webview::PlatformWebview, back: bool) {
-    use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller;
-
     let controller = webview.controller();

Why the warning appeared

Two things overlap.

1. The import was unused from the start

git log -S ICoreWebView2Controller -- src-tauri/src/app/navigation.rs returns exactly two commits: 476a0a6 (2026-08-02), which added the line along with the file, and this PR, which removes it. Nothing in between touched the line, so this is not a refactoring regression. The warning existed when the line was written.

The likely reasoning was that calling CoreWebView2() requires the type to be in scope. That is not the case here. See the verification below.

2. CI structurally cannot catch this warning

  • The Windows implementation of history_step_platform is #[cfg(windows)]. The Rust Code Quality job in quality-and-test.yml runs on ubuntu-latest, so it never compiles this block and the warning never reaches a CI log.
  • That job's clippy step runs cargo hack ... clippy without -D warnings, so even when compiled, a lint warning does not fail the build.
  • The warning is therefore visible only in local Windows builds.

Why the import is not needed

The type is returned by value. In wry 0.54.2, PlatformWebview::controller() hands back an ICoreWebView2Controller by value (wry-0.54.2/src/lib.rs:2236 for the trait signature, :2270 for the impl):

fn controller(&self) -> ICoreWebView2Controller {
    self.webview.controller.clone()
}

So let controller = webview.controller(); already binds a value of that concrete type. Rust only needs an import when the type has to be named in source. This function calls CoreWebView2() as a method on a value and never writes the type as a path expression (ICoreWebView2Controller::…), so the name does not need to be in scope. CoreWebView2 is an inherent method generated by #[interface], which means no trait import is required either.

Reproduced in both directions

State Result
Import present warning: unused_imports at 66:9, identical to the log above
Import removed Compiling pake v3.17.2, zero warnings

Compiles and links. With the import gone, cargo build --lib produces the Windows native artifacts: app_lib.lib (staticlib), app_lib.dll (cdylib), and libapp_lib.rlib. The #[cfg(windows)] path survives both codegen and linking, which confirms the COM symbols and the inherent method resolve correctly here.

Repository-wide check. After the removal, the only remaining occurrence of ICoreWebView2Controller under src-tauri/src is a single comment at navigation.rs:68; no code references it. No code references webview2_com by name either.

Not in scope here

The direct webview2-com = "0.38" dependency in Cargo.toml is left alone. The GoBack/GoForward path still relies on that crate's COM implementation, so whether the direct dependency is still required is a separate decision. This PR only claims the import is unnecessary, not that the crate is.

Verification

cargo fmt --check        -> exit 0
cargo check --lib        -> Compiling pake v3.17.2, zero warnings
cargo build --lib        -> exit 0 (18.29s)
                           app_lib.lib / app_lib.dll / libapp_lib.rlib produced
cargo clippy --lib       -> exit 0
git show --stat HEAD     -> 1 file changed, 2 deletions(-)
git status --short       -> clean

No diff in the build-state files (src-tauri/pake.json, src-tauri/tauri.conf.json, src-tauri/tauri.macos.conf.json, src-tauri/icons/, src-tauri/png/).

Risk

Low. This deletes one import line inside a single #[cfg(windows)] function, and the rest of the function body is byte-identical, including the unsafe block and the let Ok(core) = … else form. The CoreWebView2(), GoBack(), and GoForward() call sites are untouched and the crate links. The macOS and Linux paths do not compile this function and are unaffected.

history_step_platform calls webview.controller(), which already yields the controller type, so the explicit ICoreWebView2Controller import was dead. Removing it clears the Windows-only unused_imports warning without touching the navigation path.
@jakero
jakero marked this pull request as ready for review September 26, 2026 14:00
@tw93

tw93 commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

@jakero Thanks for the cleanup. It is merged and included in pake-cli 3.17.3, with no change to how the Windows WebView is configured.

@tw93
tw93 merged commit 4540cda into tw93:main Oct 4, 2026
8 checks passed
@jakero
jakero deleted the fix/remove-unused-webview2-import branch October 5, 2026 07:02
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.

2 participants