mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(tauri-utils): sort csp/plugin/header config maps during codegen so generate_context! is deterministic (#14986)
* fix(tauri-utils): sort csp/plugin/header config maps during codegen so generate_context! is deterministic * add comments explaining rationale, and todo for removing the hack in v3
This commit is contained in:
7
.changes/fix-nondeterministic-context-codegen.md
Normal file
7
.changes/fix-nondeterministic-context-codegen.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'tauri-utils': 'patch:bug'
|
||||
---
|
||||
|
||||
Sort csp/plugin/header configs when generating HashMap constructors so that `generate_context!` is deterministic.
|
||||
|
||||
See: https://github.com/tauri-apps/tauri/issues/14978 for more information
|
||||
@@ -3842,9 +3842,14 @@ mod build {
|
||||
quote!(#prefix::Policy(#policy.into()))
|
||||
}
|
||||
Self::DirectiveMap(list) => {
|
||||
// Pass a sorted vec so the HashMap constructor is deterministic
|
||||
// see: https://github.com/tauri-apps/tauri/issues/14978
|
||||
// TODO: Remove this in v3, use a BTreeMap instead of a HashMap
|
||||
let mut sorted: Vec<_> = list.iter().collect();
|
||||
sorted.sort_by_key(|(k, _)| *k);
|
||||
let map = map_lit(
|
||||
quote! { ::std::collections::HashMap },
|
||||
list,
|
||||
sorted,
|
||||
str_lit,
|
||||
identity,
|
||||
);
|
||||
@@ -3900,7 +3905,17 @@ mod build {
|
||||
quote!(#prefix::List(#list))
|
||||
}
|
||||
Self::Map(m) => {
|
||||
let map = map_lit(quote! { ::std::collections::HashMap }, m, str_lit, str_lit);
|
||||
// Pass a sorted vec so the HashMap constructor is deterministic
|
||||
// see: https://github.com/tauri-apps/tauri/issues/14978
|
||||
// TODO: Remove this in v3, use a BTreeMap instead of a HashMap
|
||||
let mut sorted: Vec<_> = m.iter().collect();
|
||||
sorted.sort_by_key(|(k, _)| *k);
|
||||
let map = map_lit(
|
||||
quote! { ::std::collections::HashMap },
|
||||
sorted,
|
||||
str_lit,
|
||||
str_lit,
|
||||
);
|
||||
quote!(#prefix::Map(#map))
|
||||
}
|
||||
})
|
||||
@@ -4047,9 +4062,14 @@ mod build {
|
||||
|
||||
impl ToTokens for PluginConfig {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
// Pass a sorted vec so the HashMap constructor is deterministic
|
||||
// see: https://github.com/tauri-apps/tauri/issues/14978
|
||||
// TODO: Remove this in v3, use a BTreeMap instead of a HashMap
|
||||
let mut sorted: Vec<_> = self.0.iter().collect();
|
||||
sorted.sort_by_key(|(k, _)| *k);
|
||||
let config = map_lit(
|
||||
quote! { ::std::collections::HashMap },
|
||||
&self.0,
|
||||
sorted,
|
||||
str_lit,
|
||||
json_value_lit,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user