@@ -72,7 +72,7 @@ pub struct Templates {
7272 url_builder : UrlBuilder ,
7373 branding : SiteBranding ,
7474 features : SiteFeatures ,
75- vite_manifest_path : Utf8PathBuf ,
75+ vite_manifest_path : Option < Utf8PathBuf > ,
7676 translations_path : Utf8PathBuf ,
7777 path : Utf8PathBuf ,
7878 /// Whether template rendering is in strict mode (for testing,
@@ -143,6 +143,11 @@ fn is_hidden(entry: &DirEntry) -> bool {
143143impl Templates {
144144 /// Load the templates from the given config
145145 ///
146+ /// # Parameters
147+ ///
148+ /// - `vite_manifest_path`: None if we are rendering resources for
149+ /// reproducibility, in which case a dummy Vite manifest will be used.
150+ ///
146151 /// # Errors
147152 ///
148153 /// Returns an error if the templates could not be loaded from disk.
@@ -154,7 +159,7 @@ impl Templates {
154159 pub async fn load (
155160 path : Utf8PathBuf ,
156161 url_builder : UrlBuilder ,
157- vite_manifest_path : Utf8PathBuf ,
162+ vite_manifest_path : Option < Utf8PathBuf > ,
158163 translations_path : Utf8PathBuf ,
159164 branding : SiteBranding ,
160165 features : SiteFeatures ,
@@ -163,7 +168,7 @@ impl Templates {
163168 let ( translator, environment) = Self :: load_ (
164169 & path,
165170 url_builder. clone ( ) ,
166- & vite_manifest_path,
171+ vite_manifest_path. as_deref ( ) ,
167172 & translations_path,
168173 branding. clone ( ) ,
169174 features,
@@ -186,7 +191,7 @@ impl Templates {
186191 async fn load_ (
187192 path : & Utf8Path ,
188193 url_builder : UrlBuilder ,
189- vite_manifest_path : & Utf8Path ,
194+ vite_manifest_path : Option < & Utf8Path > ,
190195 translations_path : & Utf8Path ,
191196 branding : SiteBranding ,
192197 features : SiteFeatures ,
@@ -196,13 +201,18 @@ impl Templates {
196201 let span = tracing:: Span :: current ( ) ;
197202
198203 // Read the assets manifest from disk
199- let vite_manifest = tokio:: fs:: read ( vite_manifest_path)
200- . await
201- . map_err ( TemplateLoadingError :: ViteManifestIO ) ?;
204+ let vite_manifest = if let Some ( vite_manifest_path) = vite_manifest_path {
205+ let raw_vite_manifest = tokio:: fs:: read ( vite_manifest_path)
206+ . await
207+ . map_err ( TemplateLoadingError :: ViteManifestIO ) ?;
208+
209+ serde_json:: from_slice :: < ViteManifest > ( & raw_vite_manifest)
210+ . map_err ( TemplateLoadingError :: ViteManifest ) ?
211+ } else {
212+ ViteManifest :: sample ( )
213+ } ;
202214
203215 // Parse it
204- let vite_manifest: ViteManifest =
205- serde_json:: from_slice ( & vite_manifest) . map_err ( TemplateLoadingError :: ViteManifest ) ?;
206216
207217 let translations_path = translations_path. to_owned ( ) ;
208218 let translator =
@@ -291,7 +301,7 @@ impl Templates {
291301 let ( translator, environment) = Self :: load_ (
292302 & self . path ,
293303 self . url_builder . clone ( ) ,
294- & self . vite_manifest_path ,
304+ self . vite_manifest_path . as_deref ( ) ,
295305 & self . translations_path ,
296306 self . branding . clone ( ) ,
297307 self . features ,
@@ -506,23 +516,28 @@ mod tests {
506516 Utf8Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../../frontend/dist/manifest.json" ) ;
507517 let translations_path =
508518 Utf8Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../../translations" ) ;
509- let templates = Templates :: load (
510- path,
511- url_builder,
512- vite_manifest_path,
513- translations_path,
514- branding,
515- features,
516- // Use strict mode in tests
517- true ,
518- )
519- . await
520- . unwrap ( ) ;
521519
522- // Check the renders are deterministic, when given the same rng
523- let render1 = templates. check_render ( now, & rng) . unwrap ( ) ;
524- let render2 = templates. check_render ( now, & rng) . unwrap ( ) ;
520+ for use_real_vite_manifest in [ true , false ] {
521+ let templates = Templates :: load (
522+ path. clone ( ) ,
523+ url_builder. clone ( ) ,
524+ // Check both renders against the real vite manifest and the 'dummy' vite manifest
525+ // used for reproducible renders.
526+ use_real_vite_manifest. then_some ( vite_manifest_path. clone ( ) ) ,
527+ translations_path. clone ( ) ,
528+ branding. clone ( ) ,
529+ features,
530+ // Use strict mode in tests
531+ true ,
532+ )
533+ . await
534+ . unwrap ( ) ;
535+
536+ // Check the renders are deterministic, when given the same rng
537+ let render1 = templates. check_render ( now, & rng) . unwrap ( ) ;
538+ let render2 = templates. check_render ( now, & rng) . unwrap ( ) ;
525539
526- assert_eq ! ( render1, render2) ;
540+ assert_eq ! ( render1, render2) ;
541+ }
527542 }
528543}
0 commit comments