-
Notifications
You must be signed in to change notification settings - Fork 305
Description
hashed_js_name is based on the digest of the built wasm src. But since wasm-bindgens generation of the frontend.js is impure (1) we'll get a diff in the frontend-$digest.js src resulting in a different SRI integrity attribute for the same file name.
This breaks the cache-busting feature as the same frontend-$digest.js file name will be generated but with a different integritys set.
I think this could be solved by calculating the digest of the js-file and using that for the wasm and js file names. This makes the impurity trickle from wasm-bindgen to the trunks output as well but at least it fixes the cache busting feature. I don't know if this is a valid approach at all.
I've included a proof of concept minimal diff (2) implementation/fix.
I think this could potentially be the source of error / fix to #838
(1) diff between trunk build --release runs with the same rust src (resulting in the same wasm src, but different frontend.js output)
@@ -260,23 +260,23 @@ function makeMutClosure(arg0, arg1, dtor, f) {
CLOSURE_DTORS.register(real, state, state);
return real;
}
-function __wbg_adapter_6(arg0, arg1) {
- wasm.wasm_bindgen__convert__closures_____invoke__hd29f6a15cdda6cfb(arg0, arg1);
+function __wbg_adapter_8(arg0, arg1, arg2) {
+ wasm.closure2123_externref_shim(arg0, arg1, arg2);
}
-function __wbg_adapter_9(arg0, arg1) {
- wasm.wasm_bindgen__convert__closures_____invoke__ha9deb78b47e2044f(arg0, arg1);
+function __wbg_adapter_15(arg0, arg1, arg2) {
+ wasm.closure2042_externref_shim(arg0, arg1, arg2);
}
-function __wbg_adapter_14(arg0, arg1, arg2) {
- wasm.closure2042_externref_shim(arg0, arg1, arg2);
+function __wbg_adapter_18(arg0, arg1) {
+ wasm.wasm_bindgen__convert__closures_____invoke__ha9deb78b47e2044f(arg0, arg1);
}
-function __wbg_adapter_17(arg0, arg1, arg2) {
- wasm.closure2123_externref_shim(arg0, arg1, arg2);
+function __wbg_adapter_21(arg0, arg1) {
+ wasm.wasm_bindgen__convert__closures_____invoke__hd29f6a15cdda6cfb(arg0, arg1);
}
-function __wbg_adapter_20(arg0, arg1, arg2) {
+function __wbg_adapter_24(arg0, arg1, arg2) {
wasm.closure2172_externref_shim(arg0, arg1, arg2);
}
@@ -1231,17 +1231,17 @@ function __wbg_get_imports() {
};
imports.wbg.__wbindgen_cast_60e6c5eba56da3a5 = function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { dtor_idx: 2041, function: Function { arguments: [Ref(NamedExternref("Event"))], shim_idx: 2042, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
- const ret = makeClosure(arg0, arg1, 2041, __wbg_adapter_14);
+ const ret = makeClosure(arg0, arg1, 2041, __wbg_adapter_15);
return ret;
};
imports.wbg.__wbindgen_cast_6211035ff6a96c39 = function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { dtor_idx: 2122, function: Function { arguments: [Externref], shim_idx: 2123, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
- const ret = makeMutClosure(arg0, arg1, 2122, __wbg_adapter_17);
+ const ret = makeMutClosure(arg0, arg1, 2122, __wbg_adapter_8);
return ret;
};
imports.wbg.__wbindgen_cast_7350077ae8cb232c = function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { dtor_idx: 1835, function: Function { arguments: [], shim_idx: 1836, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
- const ret = makeMutClosure(arg0, arg1, 1835, __wbg_adapter_6);
+ const ret = makeMutClosure(arg0, arg1, 1835, __wbg_adapter_21);
return ret;
};
imports.wbg.__wbindgen_cast_7e9c58eeb11b0a6f = function(arg0, arg1) {
@@ -1252,7 +1252,7 @@ function __wbg_get_imports() {
};
imports.wbg.__wbindgen_cast_bcd2ca636b6d377d = function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { dtor_idx: 2171, function: Function { arguments: [Ref(NamedExternref("Event"))], shim_idx: 2172, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
- const ret = makeMutClosure(arg0, arg1, 2171, __wbg_adapter_20);
+ const ret = makeMutClosure(arg0, arg1, 2171, __wbg_adapter_24);
return ret;
};
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
@@ -1267,7 +1267,7 @@ function __wbg_get_imports() {
};
imports.wbg.__wbindgen_cast_eba64ab486c46f73 = function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { dtor_idx: 2105, function: Function { arguments: [], shim_idx: 2106, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.(2) (note that i haven't changed the hashed_wasm_base method name or looked into if this could have any other unwanted side effects)
diff --git a/src/pipelines/rust/mod.rs b/src/pipelines/rust/mod.rs
index 0919a5d..f2143fc 100644
--- a/src/pipelines/rust/mod.rs
+++ b/src/pipelines/rust/mod.rs
@@ -602,17 +602,21 @@ impl RustApp {
// Copy the generated WASM & JS loader to the dist dir.
tracing::debug!("copying generated wasm-bindgen artifacts");
- let hashed_name = self.hashed_wasm_base(wasm_path).await?;
- let hashed_wasm_name =
- apply_data_target_path(format!("{hashed_name}_bg.wasm"), &self.target_path);
let js_name = format!("{}.js", self.name);
+ let js_loader_path = bindgen_out.join(&js_name);
+
+ let hashed_name = self.hashed_wasm_base(js_loader_path.as_ref()).await?;
+
let hashed_js_name = apply_data_target_path(format!("{hashed_name}.js"), &self.target_path);
+
+ let hashed_wasm_name =
+ apply_data_target_path(format!("{hashed_name}_bg.wasm"), &self.target_path);
+
let ts_name = format!("{}.d.ts", self.name);
let hashed_ts_name =
apply_data_target_path(format!("{hashed_name}.d.ts"), &self.target_path);
- let js_loader_path = bindgen_out.join(&js_name);
let js_loader_path_dist = self.cfg.staging_dist.join(&hashed_js_name);
let wasm_name = format!("{}_bg.wasm", self.name);
let wasm_path = bindgen_out.join(&wasm_name);