Skip to content

Commit b7cdb3b

Browse files
chore: feature gate html manipulation code (#13410)
* Feature gate html manipulation code * Change file
1 parent 96ecfca commit b7cdb3b

File tree

8 files changed

+30
-12
lines changed

8 files changed

+30
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": 'patch:changes'
3+
"tauri-utils": 'patch:breaking'
4+
---
5+
6+
Feature gated the HTML manipulation code in `tauri-utils` behined a flag to reduce compile time

crates/tauri-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ tauri-utils = { version = "2.4.0", path = "../tauri-utils", features = [
6363
"schema",
6464
"config-json5",
6565
"config-toml",
66+
"html-manipulation",
6667
] }
6768
tauri-utils-v1 = { version = "1", package = "tauri-utils", features = [
6869
"isolation",

crates/tauri-utils/Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ brotli = { version = "8", optional = true, default-features = false, features =
2222
"std",
2323
] }
2424
url = { version = "2", features = ["serde"] }
25-
html5ever = "0.26"
26-
kuchiki = { package = "kuchikiki", version = "0.8" }
25+
html5ever = { version = "0.26", optional = true }
26+
kuchiki = { package = "kuchikiki", version = "0.8", optional = true }
2727
proc-macro2 = { version = "1", optional = true }
2828
quote = { version = "1", optional = true }
2929
# Our code requires at least 0.8.18 so don't change this to 0.8
@@ -59,11 +59,19 @@ getrandom = { version = "0.2", features = ["std"] }
5959
serial_test = "3"
6060

6161
[features]
62-
build = ["proc-macro2", "quote", "cargo_metadata", "schema", "swift-rs"]
62+
build = [
63+
"proc-macro2",
64+
"quote",
65+
"cargo_metadata",
66+
"schema",
67+
"swift-rs",
68+
"html-manipulation",
69+
]
6370
compression = ["brotli"]
6471
schema = ["schemars"]
6572
isolation = ["aes-gcm", "getrandom", "serialize-to-javascript"]
6673
process-relaunch-dangerous-allow-symlink-macos = []
6774
config-json5 = ["json5"]
6875
config-toml = []
6976
resources = ["walkdir"]
77+
html-manipulation = ["dep:html5ever", "dep:kuchiki"]

crates/tauri-utils/src/assets.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ use std::{
1212
path::{Component, Path},
1313
};
1414

15+
/// The token used for script nonces.
16+
pub const SCRIPT_NONCE_TOKEN: &str = "__TAURI_SCRIPT_NONCE__";
17+
/// The token used for style nonces.
18+
pub const STYLE_NONCE_TOKEN: &str = "__TAURI_STYLE_NONCE__";
19+
1520
/// Assets iterator.
1621
pub type AssetsIter<'a> = dyn Iterator<Item = (Cow<'a, str>, Cow<'a, [u8]>)> + 'a;
1722

crates/tauri-utils/src/html.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ use serde::Serialize;
1919
#[cfg(feature = "isolation")]
2020
use serialize_to_javascript::DefaultTemplate;
2121

22-
use crate::config::{DisabledCspModificationKind, PatternKind};
2322
#[cfg(feature = "isolation")]
2423
use crate::pattern::isolation::IsolationJavascriptCodegen;
25-
26-
/// The token used for script nonces.
27-
pub const SCRIPT_NONCE_TOKEN: &str = "__TAURI_SCRIPT_NONCE__";
28-
/// The token used for style nonces.
29-
pub const STYLE_NONCE_TOKEN: &str = "__TAURI_STYLE_NONCE__";
24+
use crate::{
25+
assets::{SCRIPT_NONCE_TOKEN, STYLE_NONCE_TOKEN},
26+
config::{DisabledCspModificationKind, PatternKind},
27+
};
3028

3129
// taken from <https://github.com/kuchiki-rs/kuchiki/blob/57ee6920d835315a498e748ba4b07a851ae5e498/src/serializer.rs#L12>
3230
fn serialize_node_ref_internal<S: Serializer>(

crates/tauri-utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
2323
pub mod acl;
2424
pub mod assets;
2525
pub mod config;
26+
#[cfg(feature = "html-manipulation")]
2627
pub mod html;
2728
pub mod io;
2829
pub mod mime_type;

crates/tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ macos-private-api = [
210210
"tauri-runtime/macos-private-api",
211211
"tauri-runtime-wry?/macos-private-api",
212212
]
213-
webview-data-url = ["data-url"]
213+
webview-data-url = ["data-url", "tauri-utils/html-manipulation"]
214214
protocol-asset = ["http-range"]
215215
config-json5 = ["tauri-macros/config-json5"]
216216
config-toml = ["tauri-macros/config-toml"]

crates/tauri/src/manager/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use url::Url;
1414

1515
use tauri_macros::default_runtime;
1616
use tauri_utils::{
17-
assets::{AssetKey, CspHash},
17+
assets::{AssetKey, CspHash, SCRIPT_NONCE_TOKEN, STYLE_NONCE_TOKEN},
1818
config::{Csp, CspDirectiveSources},
19-
html::{SCRIPT_NONCE_TOKEN, STYLE_NONCE_TOKEN},
2019
};
2120

2221
use crate::resources::ResourceTable;

0 commit comments

Comments
 (0)